std::numeric_limits<float>::max_digits10 value of 8 is wrong and should be 9 - by Paul A Bristow

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 668921 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 5/17/2011 9:48:09 AM
Access Restriction Public


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:

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


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.  

Sign in to post a comment.
Posted by Microsoft on 6/28/2011 at 5:02 PM

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 .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Paul A Bristow on 6/6/2011 at 4:50 AM
FWIW, gcc provides the accepted value of 9 for std::numeric_limits<float>::max_digits10;
Posted by EricLeong [Feedback Moderator] on 5/17/2011 at 7:50 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by EricLeong on 5/17/2011 at 6:36 PM
Thank you for your feedback, We are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(