Search Issue Tracker
Won't Fix
Votes
1
Found in
2017.4.0f1
2018.3.0a1
2018.3.7f1
Issue ID
1134777
Regression
No
[2018.3][IL2CPP] Float to int conversion in returns incorrect value
Steps to reproduce:
1. Download attached project
2. Build a Standalone player with IL2CPP backend
Expected results: Angle variable is 45
Actual results: Angle variable is 44
Reproduced with: 2018.3.8f1, 2017.4.21f1
Not reproducible with: 2019.2.0a8, 2019.1.0b5
Example code:
Vector3 Direction = new Vector3(-3.0f, 0.0f, 3.0f);
float angleFloat = Vector3.SignedAngle(Direction, Vector3.forward, Vector3.up);
int angle = (int)angleFloat;
Workaround: for the float to int conversion use Convert.ToInt32()
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- DownloadHandlerScript.CompleteContent is called twice when building for WebGL
- Scene view has Y coordinates of the Screen Position node flipped when some of the URP features are disabled
- Volumetric fog shader variants are missing from build when "Strict Shader Variant Matching" is disabled
- Unnecessary modifications clutter the Scene when using a RectTransform driven by a LayoutGroup in a Prefab
- Files in the target folder are deleted without a proper warning when building an iOS project
Resolution Note:
This is a precision error where IL2CPP calculates the SignedAngle to be 44.9999962 while Mono calculates it to be 45. Casting a float to int will truncate the value.
It is suggested that floats should always be rounded before casting, e.g. Mathf.Round(float), or use a dedicated function such as Convert.ToInt32().