Re: how long is double
From: Andrew Koenig (ark_at_acm.org)
Date: 01/04/04
- Next message: Jack Klein: "Re: how long is double"
- Previous message: Jacques Labuschagne: "Re: [OT?] C++ Standard - 14882:2003"
- In reply to: f: "how long is double"
- Next in thread: Jack Klein: "Re: how long is double"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 4 Jan 2004 06:13:27 -0500
"f" <ffunus@yahoo.com> wrote in message
news:8f4ce98a.0401031338.4208ac8@posting.google.com...
> I have this
>
> double sum, a, b, c;
> sum = a + b + c;
> printf("%.20f = %.20f, %.20f, %.20f", sum, a, b, c);
>
> I found that the debug version and release version of the same code
> give me different result. I am using VC++ 6.0.
>
> In debug version, the print out is:
> -12.25938471938358500000 = -11.43596388399630500000,
> -0.07591666113607631300, -0.74750417425120252000,
>
> In the release version, the print out is:
> -12.25938471938358300000 = -11.43596388399630500000,
> -0.07591666113607631300, -0.74750417425120252000,
>
> The above sum = a + b + c is just a part of my computation. I found
> that my whole computation crushed in the debug version because some
> number became zero and another number divide this number. But this did
> not happened in the release version.
>
> Why?
Apparently the discrepancy is between -12.25938471938358500000
and -12.25938471938358300000, a difference of 2 in the 17th significant
digit.
I'm guessing--and this is only a guess--that in production mode, the
compiler tells the machine to compute a+b+c by using its extended-precision
intermediate register (80 bits, if I remember correctly), and in debug mode
it actually truncates the intermediate result to 64 bits. That might well
give a discrepancy of about this degree. I'd have to look at the binary
representations of the numbers to be sure, and I'm too lazy right now :-) --
but if your computation is so brittle that such a small deviation crashes
it, you may want to rethink it.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
- Next message: Jack Klein: "Re: how long is double"
- Previous message: Jacques Labuschagne: "Re: [OT?] C++ Standard - 14882:2003"
- In reply to: f: "how long is double"
- Next in thread: Jack Klein: "Re: how long is double"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|