From: John Maddock (john_at_[hidden])
Date: 2006-03-16 14:20:46
Attached is a sketch of how reals can be serialised in hex notation, without
data loss when round-tripping from binary-to-text-to-binary.
1) The iostream code could be improved, particularly formatting errors on
reading, if any iostream experts would like to give it the once over they're
2) There is no check on reading that the target type is large enough to hold
all the bits that were previously written out (neither is there for decimal
io come to that).
3) I've only tested this code with VC8, so portability may vary.
4) I've made no attempt to beautify the output format, it's frankly rather
ugly to read at present.
5) It's not clear whether on output the digit before the decimal point
should always be a 1: at present it's a full hex digit, which means the
value "1" comes out as 0x8p-3 rather than 0x1p0
6) Zero still needs to handled as a special case, at present it prints as
0x0p-3 rather than 0x0p0: it makes no difference on input, but it would be
nice to print it prettily :-)
7) I've been unable to reproduce the original problem with native << and >>
operators with either random value tests, or with sequential nextafter
tests, unless I start with the specific value that caused all the fuss in
the first place :-( Any ideas for better tests much appreciated.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk