Ok, so a while back, I think KittyCat had posted, a method of saving floats (can't find it now) that basically involved some division, seperating it into two peices, and then saving each peice individually... it was kind of complicated but only like 5 lines or so of code... If anybody has any idea what I'm talking about, reposting this code would be greatly appreciated...
The reason for it, instead of just saving 4 bytes from memory was for cross platform compatability... (not all compilers adhere to the same standards or some such...)
Anyway, the reason I want it is because I'm writing a game in VB.NET (using allegro's file packing routines for saving data) that will save maps/tilesets to files on disk, and I need to save a single (a float is called a single in VB.) to a file. -- I've written some string/bitmap saving functions that seem to work pretty good, but saving with single.ToString()/loading with Single.Parse(x) is probably pretty bad for accuracy...
got the post: http://www.allegro.cc/forums/thread/525662
Kitty Cat said:
To save a float/double:
pack_iputl(file, floor(fval));if(fval-floor(fval)) pack_iputl(file, 1/(fval-floor(fval)));else pack_iputl(file, 0);
And to read:
long whole = pack_igetl(file);long recip = pack_igetl(file);float fval = whole + (recip ? (1.0/(float)recip) : 0.0);
Should work. To save an int, use pack_igetl/pack_iputl. For char, pack_getc/pack_putc.