printf/sprintf do not print enough significant digits for exact binary fractions - by DoctorBinary

Status : 

  Won't Fix<br /><br />
		Due to several factors the product team decided to focus its efforts on other items.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


0
0
Sign in
to vote
ID 329278 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 2/19/2008 5:53:06 PM
Access Restriction Public

Description

Fractions expressible as a/2^n have exact binary representations (with n, for example, being <= 53 for the double type).  I would expect printf and sprintf to print out all n digits of such fractions as they are all significant.  As the attached program shows, (2^24+1)/2^25 = 0.5000000298023223876953125, but printf gives 0.5000000298023223900000000.
Sign in to post a comment.
Posted by Microsoft on 7/6/2009 at 11:32 AM
Thx super for the extra info! As we said, we will look into this for the release after VS2010.

Ale Contenti
VC++ Dev Lead
Posted by DoctorBinary on 1/30/2009 at 2:12 PM
When you fix this, consider that the new limit should be no less than 1074. This will allow you to print any dyadic fraction to full precision, even all 1074 digits of 2^-1074. GCC C allows this.

I wrote an article about how VS C++ and 7 other languages handle this issue at http://www.exploringbinary.com/print-precision-of-dyadic-fractions-varies-by-language/
Posted by Microsoft on 12/30/2008 at 4:09 PM
The Visual C++ team has triaged the issue you reported. The issue has been resolved during triage with the following message:

Thanks for reporting this problem. We're aware of it, and we don't have time to fix this issue for the next release of VS (VS 2010).
The problem is that we need to refresh the read/write floating point algorithms. We'll do that in the release after VS 2010.

For further information, you may want to consult one of these resources:
1. Visual C++ triage guidelines:
        http://blogs.msdn.com/vcblog/articles/621116.aspx
2. MSDN forums:
        http://forums.microsoft.com/msdn/default.aspx

Thank you for taking time to send us feedback,
The Visual C++ Team
Posted by Microsoft on 2/19/2008 at 6:54 PM
Thanks for your feedback. We are escalating this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you,
Visual Studio Product Team