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
- URP Realtime reflection probes do not update when RenderProbe() is being called once per second
- Addressable terrain shader variants are stripped from the Player
- [iOS] Debug.Log() appears as <private> in Console app
- UI stays in the background when it is disabled in simulator
- A wrong log file is attached when project is launched with a "-logFile" command line argument
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().