Storing Integers as Doubles
For simplicity sake, I want to store both floats and integers in the same structure element. I was wondering if I could just store everything as double. In other words, convert integers to doubles
before a save and convert the double to an integer after retrieval?
There won't be any precision lost?
Thanks.
before a save and convert the double to an integer after retrieval?
There won't be any precision lost?
Thanks.
Code:
union
{
long bob;
double ned;
}
doubles have 52 bits of mantissa precision, so they can losslessly represent any integer between -4503599627370496 and 4503599627370496. 4503599627370497 is unrepresentable.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
How do unsigned integers differ from signed integers? | ferum | 3 | 4,742 |
Apr 11, 2006 01:52 PM Last Post: ferum |