Storing Integers as Doubles

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?

Quote this message in a reply
Posts: 916
Joined: 2002.10
Post: #2
  long bob;
  double ned;
Quote this message in a reply
Posts: 1,563
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 5,053 Apr 11, 2006 01:52 PM
Last Post: ferum