FLOAT to DWORD -- Accuracy?
inline DWORD FtoDW( FLOAT f ) { return *((DWORD*)&f); }
DWORD dwNumber = FtoDW(1.5);
What sort of accuracy is kept?
How does the comp go from DWORD to float like this? I can write the function but I do not understand how any accuracy or anything behind the decimal can be kept. 1.5 converted to a DWORD should be 1 or 2....
Re: FLOAT to DWORD -- Accuracy?
I'm not sure if that function will give you any sort of reasonable answer. Floating point numbers are stored in the IEEE Floating Point standard format:
one bit: sign
eight bits: exponent
23 bits: fractional part:
and to calculate the actual value, you perform 1.fraction raised to the exponent minus 127.
In other words, the bit pattern in a float is not a value that you can cast to a DWORD. You should instead be doing normal casting
DWORD dw = (DWORD)(some_float /* + .5 to do conventional rounding */);
Re: FLOAT to DWORD -- Accuracy?
You are definetly correct with your explanations.
However the function I posted works, and it works well enough for declaring scale values in float but the rendering pipeline wants DWORD. I am able to notice differences between 1.0 and 1.2 and 1.5 for example when converting to DWORD using that function for the pipeline