I need to represent single precision numbers as text in a way that won't lose any information (so I can get the same number back, possibly disregarding NaNs etc.), but without too many spurious digits - so single precision 0.1 comes out as "0.1" not "0.100000001490116".
I'm not trying to save bytes, these extra digits are just confusing.
Is there a simple way to do that? I can see at least 8 significant decimal digits will be needed to represent 23+1 bits (12345678.0 and 12345679.0 are different in single precision), and that it would be enough with binary exponent (12345b-11
sort of notation) but is this guaranteed to be enough decimal exponent notation (1.2345e+6
) or one that uses 0-padding (0.0000123456
- usually more readable, and these zeroes don't bother me much)?
Any printf
formats, or exact instructions much appreciated.