Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

optimization differences

Susan_Frankenstein
788 Views
I have the following lines of code:
x = 351.41985
x = dint(x*1d5)*1d-5
If my compiler options are:
FFLAGS1 = -stand f03 -free -check all -r8 -O2 -shared-intel -heap-arrays -m64 -c
I get x = 351.41984
If my compiler options are:
FFLAGS1 = -stand f03 -free -check all -r8 -O0 -shared-intel -heap-arrays -m64 -c
I get x = 351.41985
Why?
0 Kudos
3 Replies
mecej4
Honored Contributor III
788 Views
In Fortran, expressions have a type associated with them, along with type promotion rules for mixed-type expressions. The expression in your program simply contains the constant 351.41985, which is of type 32-bit (4-byte) REAL, and its value is already at the limit of how many significand bits can fit into a 4-byte REAL, with its 23-bit significand (about 7 decimal digits).

From that point on, your statements are doing some manipulations, with promotion to double precision, and so forth, but nothing makes up for the fact that you started out with a single-precision constant. The differences in the last (eight) digit are not arguable because single-precision cannot represent 8 decimal digits.
0 Kudos
TimP
Honored Contributor III
788 Views
Although mecej4 is basically correct, your specification of -r8 should cause your constant to be seen as double precision. I can think of several possible influences, so a complete sample which can be compiled and run may be needed to find out the reason. It might depend on compiler version as well.
0 Kudos
mecej4
Honored Contributor III
788 Views
The declaration of variable x was not shown. Had it been declared as REAL*4, i.e., with explicitly stated size, the -r8 option would not affect the variable x.
0 Kudos
Reply