Re: how long is double

From: Andrew Koenig (ark_at_acm.org)
Date: 01/04/04


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! ]



Relevant Pages

  • Re: CPtrArray Performance
    ... CPtrArray has approximately the same performance as an ordinary array. ... are you measuring debug or optimized code? ... can completely swamp the actual function execution. ... In debug mode, you worry about getting it right. ...
    (microsoft.public.vc.mfc)
  • Re: frame creation bug in release mode
    ... > I have a MDI MFC app which works well in debug mode. ... > after "Create", the app crashes. ...
    (microsoft.public.vc.mfc)
  • Re: /MT and /MD
    ... then the codepath may differ in Debug vs. Release builds. ... In Debug mode, it may not be zero." ...
    (microsoft.public.vc.language)
  • Re: Debug library crashes when linked with Release build
    ... In debug mode the classes ... compiled the classes memory footprint is smaller thanm in debug mode ... compiler or library implementation. ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Execution time debug vs. release
    ... Note that VS is doing more and more runtime checks in debug mode, ... You could check this out by compiling just one of your files in VS7 and VS8 with the ... speed with Task Manager showing 0% CPU time. ...
    (microsoft.public.vc.mfc)