Home Dashboard Directory Help
Search

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


Status: 

Closed
 as Fixed Help for as Fixed


2
0
Sign in
to vote
Type: Bug
ID: 668921
Opened: 5/17/2011 9:48:09 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

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.












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

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
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 MS-Moderator09 [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 MS-Moderator09 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(http://support.microsoft.com)
Sign in to post a workaround.