Storing Integers as Doubles

Member
Posts: 321
Joined: 2004.10
Post: #1
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.
Quote this message in a reply
Moderator
Posts: 916
Joined: 2002.10
Post: #2
Code:
union
{
  long bob;
  double ned;
}
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #3
doubles have 52 bits of mantissa precision, so they can losslessly represent any integer between -4503599627370496 and 4503599627370496. 4503599627370497 is unrepresentable.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  How do unsigned integers differ from signed integers? ferum 3 3,443 Apr 11, 2006 01:52 PM
Last Post: ferum