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
- The Up, Down and other Buttons in a Style Sheet's Inspector unselect items when they are clicked while they are disabled
- Virtual Player remains active and still launches when removed from Additional Editor Instances from a custom Play Mode Scenario
- UI Toolkit Editor Window Creator becomes not interactable and greyed out when a long name is entered
- [Web][iOS] Web Player keeps restarting on launch when Native C/C++ Multithreading is enabled
- "Add Scene to Scenes in Build" pop-up reappears after Scene has already been added and another Multiplayer Editor Instance is loaded
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().