iDevGames Forums
Storing Integers as Doubles - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Programming Languages & Scripting (/forum-8.html)
+--- Thread: Storing Integers as Doubles (/thread-9113.html)



Storing Integers as Doubles - WhatMeWorry - Jun 29, 2011 09:56 AM

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.


RE: Storing Integers as Doubles - skyhawk - Jun 29, 2011 09:57 AM

Code:
union
{
  long bob;
  double ned;
}



RE: Storing Integers as Doubles - ThemsAllTook - Jun 29, 2011 10:33 AM

doubles have 52 bits of mantissa precision, so they can losslessly represent any integer between -4503599627370496 and 4503599627370496. 4503599627370497 is unrepresentable.