SetWorldRotation , SetLocalRotation Floating Point discrepancies
Hello there, i am currently going nuts, somehow parts of my code wouldn't work,and i couldn't get to the bottom of it.
But then i have noticed that, when i set a specific Yaw amount to a rotator linked to either SetWorldRotation or SetLocalRotation the resulting Object Transform Rotation is wrong, for instance 90 ° is -179.999985 °, and even worse, the value isn't consistent, sometimes is -179.9999854 °.
Therefore when, i execute Compare Floats to enact specific behaviour, nothing ever happens, cause numbers are never equal, (except for 0 degrees, that works)
90 Degrees Case
180 Degrees Case
Now, i need to solve this, i could've got along if the stilted values were consistent, but they are not.
I couldn't find anything specific about this issue, and how to solve it.
It sounds so silly, yet this nullifies almost the entire behaviour coded afterwards
The Rotator return value is 180.0 so the issue must be in SetWorld Rotation and SetLocalRotation
And finally, yes, the issue persist also in SetWorldLocationAndRotation
I hereby applaud your solution in advance,kind sir or miss
CLAP CLAP CLAP, that was really helpful, grateful, I am (Says I from the future)
asked Jul 13 '17 at 09:00 PM in Blueprint Scripting
If anybody else has an issue such as that, the workaround is to ditch "Compare Float" and use a Branch in conjunction with "Nearly Equal (float)", that will suffice for comparisons.
It is related to the floating point precision error, read BobTheRoss third link for more info on the subject
Direct quote from that third link
Floating-point representations have a base (which is always assumed to be even) and a precision p. If = 10 and p = 3, then the number 0.1 is represented as 1.00 × 10-1. If = 2 and p = 24, then the decimal number 0.1 cannot be represented exactly, but is approximately 1.10011001100110011001101 × 2-4.
I think that is a problem of the way floating-point arythmetics works. I think 90 can only be described aproximatly by a float value. The Unreal interface shows you a 90 as value if you type it in the details panel, but if you print the actor roation you will get the value that really was set. Even more confusing is that unreal will print you a 90.0 if you print a float variable on that you typed in 90. Maybe Unreal is calculating with 64 bit floats internally so it hits the 90 more closely... I can't tell.
I also had problems on itrative adding of float values, this shows a workaround https://answers.unrealengine.com/questions/76911/are-floats-broken-or-is-this-some-precision-issue.html
you might want to know how float values work https://en.wikipedia.org/wiki/Floating-point_arithmetic also: What Every Computer Scientist Should Know About Floating-Point Arithmetic http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
answered Jul 14 '17 at 02:17 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here