SetWorldRotation , SetLocalRotation Floating Point discrepancies

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 ,Are floats broken or is this some precision issue? - Programming & Scripting - Unreal Engine Forums

you might want to know how float values work
Floating-point arithmetic - Wikipedia also: What Every Computer Scientist Should Know About Floating-Point Arithmetic What Every Computer Scientist Should Know About Floating-Point Arithmetic

I have read a part from your third link and the issue seems to be related to base and precision values.

Never encountered it before, still, given the link explanation, that must be it.
I have found and read that first link while searching for a solution, though instead i landed on using "Nearly equal(float)"function, it works rather well.

I am going to put my answer as the solution, since is the one that made the algorithm work, still, i have put an annotation that clearly refers to your answer, cause it is helpful in elucidating the issue, appreciated.

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)

Construction Script

90 Degrees Case

202299-90degreesdiscrepancy.png

180 Degrees Case

202300-180degreesdiscrepancy.png

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)

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.