std::numeric_limits<float>::max_digits10 value of 8 is wrong and should be 9.
max_digits10 is the number of decimal digits that is required to ensure that a 1 least significant bit change in the floating point value produces a change in the decimal digits string representation.
// See for details: http://www2.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1822.pdf
The long accepted formula for this was given by Kahan
2 + std::numeric_limits<float>::digits * 3010/10000
and for float this gives a value of 9.
VC 10 returns only 8, and this is not sufficient for a significant number of float values.
One example (and only one is necessary for the choice of 8 to be wrong, but about 1/3 show this problem)
1.10000006e-032f or as a binary pattern in hex a647609 is displayed using max_digits 10 as
1.1000001e-032
but the next binary value, a64760a is also displayed as the *same* value 1.1000001e-032.
Using the accepted value of 9 for max_digits10,
a647609 is displayed as 1.10000006e-032
a64760a is displayed as 1.10000014e-032
which is as expected.
This has some serious effects on programs that rely on max_digits value being sufficient to reflect a one digit change. It will cause dificult to diagnose apparently random faults (only for about 1/3 of values) in Boost lexical_cast and Boost.serialisation and archive and Boost.Test, and many other user programs.
Thanks for reporting this bug. We've fixed it, and the fix will be available in VC11.
If you have any further questions, feel free to E-mail me at stl@microsoft.com .
Stephan T. Lavavej
Visual C++ Libraries Developer