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
- UI Builder can't set a background image to a sprite from a multi-sprite spritesheet in the Resources folder
- Light2D freeform does not render the internal part when rendered in certain shapes
- Using AddCopyPass causes an incorrect merging of passes.
- Negative Enum value is not pasted correctly when copying from another array
- Silent Crash when generating Lightmap UVs for a model with a large object scale
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().