Bug 45175 - In gfortran, the calculation of small differences seems to depend on optimization flags
Summary: In gfortran, the calculation of small differences seems to depend on optimiza...
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-04 02:03 UTC by Dave Newton
Modified: 2010-08-04 02:42 UTC (History)
69 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Main program (302 bytes, application/octet-stream)
2010-08-04 02:05 UTC, Dave Newton
Details
Support routines (121.10 KB, application/octet-stream)
2010-08-04 02:05 UTC, Dave Newton
Details
Implicit typecasting include file (118 bytes, application/octet-stream)
2010-08-04 02:06 UTC, Dave Newton
Details
Compilation batch file (151 bytes, application/octet-stream)
2010-08-04 02:22 UTC, Dave Newton
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Newton 2010-08-04 02:03:25 UTC
Just a little background:

I wrote a program that does high accuracy factorials.  It saves a given factorial for later use as a double precision real between 1 and 2 and an integer power of 2.  It does this by calculating the factorial to a practically unlimited number of bits, rounding it to 53 bits only as the final step, thereby avoiding the cumulative round off errors that occur.

I wanted to compare the accuracy of this method to a straight-forward way of calculating factorials.  So I also scaled factorials calculated in a straight-forward way the same way as above, that is as a double precision real between 1 and 2 and an integer power of 2.

In the comparison, the integer power of 2 can be ignored, as it is practically always the same.  As to the real portion, the difference between the two reals should always be an integer multiple of 2**(-52).  The crux of the bug is that when I compiled using the flag -O, this was true.  Using -O2, it was not.  Stated another way, the calculation of small differences seems to depend on optimization flags.
Comment 1 Dave Newton 2010-08-04 02:05:14 UTC
Created attachment 21388 [details]
Main program
Comment 2 Dave Newton 2010-08-04 02:05:50 UTC
Created attachment 21389 [details]
Support routines
Comment 3 Dave Newton 2010-08-04 02:06:39 UTC
Created attachment 21390 [details]
Implicit typecasting include file
Comment 4 Dave Newton 2010-08-04 02:22:27 UTC
Created attachment 21391 [details]
Compilation batch file
Comment 5 Dominique d'Humieres 2010-08-04 02:38:13 UTC
You do not say on which platform you did the tests (gfortran -v). From

C:\FI\Implicit4.inc

I assume that you are using some *86* processor under Windows. 

This is not a gfortran bug, but a duplicate of an infamous pr I cannot find the number. You should try -ffloat-store or -mfpmath=sse and have a look at the gcc manual

http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Optimize-Options

under -ffloat-store and -fexcess-precision=style.
Comment 6 Jerry DeLisle 2010-08-04 02:42:02 UTC
This is a duplicate of PR 323

See  http://gcc.gnu.org/bugzilla/show_bug.cgi?id=323

Just use -ffloat-store.



*** This bug has been marked as a duplicate of 323 ***