Should project settings affect accuracy?

  • Thread starter Thread starter David Binner
  • Start date Start date
D

David Binner

Hello.

I recently came across something that baffled me regarding
floating point calculations.

I use Microsoft Visual C++ version 6 on a Windows 2000
machine. All my variables are type double.

After compiling a program in Debug mode and then running
the program, it correctly calculated my variable, x, to be
(say) 3.09e-9. However, after compiling the program in
Release mode and running it, the program calculated x to
be (say) -2.19e-9. This discrepancy completely ruined the
results of the program because later in the program,
different calculations are made, depending upon whether x
is positive or negative. I noticed the Optimizations
setting was set to "Maximize Speed". I changed this
setting to "Default" and re-compiled my program. The
correct results were then produced.

My question is this: Should this have happened?

I had always assumed that Optimization settings would
affect the size of the code produced (perhaps by unrolling
small loops, etc.), but accuracy would never be
compromised. After all, what good are fast results if they
are incorrect?

Yet now I have come across a situation that seems to
indicate otherwise. Is this a quirk in the software, or
should have expected such behaviour?

Your insight is appreciated.
 
My question is this: Should this have happened?

Have a look at using the /Op (Improve Float Consistency) and see if
that makes the results consistent between your builds.

Dave
 
David said:
Hello.

I recently came across something that baffled me regarding
floating point calculations.

I use Microsoft Visual C++ version 6 on a Windows 2000
machine. All my variables are type double.

After compiling a program in Debug mode and then running
the program, it correctly calculated my variable, x, to be
(say) 3.09e-9. However, after compiling the program in
Release mode and running it, the program calculated x to
be (say) -2.19e-9. This discrepancy completely ruined the
results of the program because later in the program,
different calculations are made, depending upon whether x
is positive or negative. I noticed the Optimizations
setting was set to "Maximize Speed". I changed this
setting to "Default" and re-compiled my program. The
correct results were then produced.

My question is this: Should this have happened?

In addition to David's response, be very careful that you're obeying your
floating point rules correctly. Comparing very small numbers to zero,
especially if those numbers were the result of addition or subtraction, is a
very tricky business indeed, due to rounding considerations.

http://docs.sun.com/source/806-3568/ncg_goldberg.html.

might be of some help.

-cd
 
Back
Top