From: Rick.Regan on 27 Jun 2010 00:11 You said "If you stop in the debugger and examine the value of the double, you will find it to be -937566.23646998685 ... on output VC++ is rounding whereas G++ is truncating." The debugger is not printing all the digits. Try printing the double in hex with the %a format specifier ("%.13a" gets all the digits in VC++). Now take that value, translate it to binary, and then convert it to decimal. It is exactly -937566.236469986848533153533935546875. G++ is not truncating; it is rounding the exact value to 16 digits (which only looks like truncating since the remaining digits are less than 1/2 ULP). VC++ is rounding up, which is incorrect. George Neuner wrote: I do not have a cite ready, but problems similar to yours have beendiscussed 26-Jun-10 I do not have a cite ready, but problems similar to yours have been discussed before in this group. The last one I remember was about exponential notation: someone was reading in values like "0.0003" and "3.e-4" and finding they do not compare equal. This is a known issue with the VC++ library - it goes back at least to VS2002 and maybe further. Does the file have to be human readable? If not, store the exact bit pattern in binary or in hexadecimal (16 chars). I do not deny there is a discrepancy, but the question still is which compiler is wrong. I see that VC++ is giving back the input value, but it is by coincidence. If you stop in the debugger and examine the value of the double, you will find it to be -937566.23646998685 ... on output VC++ is rounding whereas G++ is truncating. If you change the input string to "-937566.2364699868", the value of the double is still -937566.23646998685 ... but in this case, G++ matches the input while VC++ does not. For my money VC++ is the one doing it wrong. George Previous Posts In This Thread: Submitted via EggHeadCafe - Software Developer Portal of Choice Composite UI Pattern And Enterprise Settings http://www.eggheadcafe.com/tutorials/aspnet/14dd2b7f-9da4-4a45-bc93-ce5fdba5c5ee/composite-ui-pattern-and-enterprise-settings.aspx -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
|
Pages: 1 Prev: deleted functions and conversions Next: Lifetime of a temporary bound to a reference |