I am not convinced stuffing the hex values straight in will work as expected. I think the compiler translates that number as an integer value represented by the hex string, and then creates an appropriate float representation. So more specifically:
f64 foo = 0x11 will set foo to 3.0, not the IEEE spec for what in hex 0x11 might represent.
At least that what I think happened when I tried to do it.
Here I took the function out of the trunk and made it into a helper, so we could both be sure to be on the trunk. I could reproduce with this:
Code: Select all
f64 GetAngleIrrlichtSVN(vector2df const &v)
{
// v.X = 0x0, v.Y = 0xfffffffe
if (v.Y == 0) // corrected thanks to a suggestion by Jox
return v.X < 0 ? 180 : 0;
else if (v.X == 0)
return v.Y < 0 ? 90 : 270;
// don't use getLength here to avoid precision loss with s32 vectors
f64 tmp = v.Y / sqrt((f64)(v.X*v.X + v.Y*v.Y)); // = -1.0
if ( tmp > 1.0 ) // avoid floating-point trouble as sqrt(y*y) is occasionally larger y
tmp = 1.0;
tmp = atan( core::squareroot(1 - tmp*tmp) / tmp) * RADTODEG64;
// tmp = -nan a.k.a 0x8000000000000000
....
}
Looks like the core::squareroot(1 - tmp*tmp) in particular is causing the ruckus. Dugging in, that looks like one's local, friendly math.h sqrt(). sqrt(0) should succeed so I am confused.
I actually tried to isolate that code and it appears to work. From what I can see in my own debugger, the hex representation of the floating-point numbers is the same.
On a whim, I added a -1.0 clamp and it appeared to work!
Code: Select all
if (v.Y == 0) // corrected thanks to a suggestion by Jox
return v.X < 0 ? 180 : 0;
else if (v.X == 0)
return v.Y < 0 ? 90 : 270;
// don't use getLength here to avoid precision loss with s32 vectors
f64 tmp = v.Y / sqrt((f64)(v.X*v.X + v.Y*v.Y)); // = -1.0
if ( tmp > 1.0 ) // avoid floating-point trouble as sqrt(y*y) is occasionally larger y
tmp = 1.0;
if(tmp < -1.0)
tmp = -1.0;
tmp = atan( core::squareroot(1 - tmp*tmp) / tmp) * RADTODEG64;
...
So I suspect my ability to get the accurate view of the raw floating point numbers was also getting hampered too. Does that negative clamp make mathematical sense?