I have a scientific code that implements a numerical method in Fortran, which is compiled with ifort using "-O2 -mieee-fp" flags, and the results with this compilation are the reference results.
After compiling the code without using "-mieee-fp", intermediate variables present small differences, and as the numerical method iterates and checks for convergence, the final results differ by either hundreds or thousands when compared to the reference results. I'd like to know what is the reason for these differences.
I also used another compiler (pgf90) for comparison, which produces the same results as ifort without using "-mieee-fp", even if explicitly using this type of flag ("-Kieee").
The sample code below illustrates the differences.
System: Intel Core i7 7820x, Linux CentOS 7.5.1804
Compilers: Intel Fortran 188.8.131.521, PGI Fortran 19.10-0
ifort -o prog1.x prog.f90 -O2 -mieee-fp; prog1.x
ifort -o prog2.x prog.f90 -O2; prog2.x / pgf90 -o prog2.x prog.f90 -O2 [with/without] -Kieee; prog2.x
program precision real x1, x2, x3, val x1 = 0.00999999977648258209228515625 x2 = 539.693969726562499999999999999999999999 x3 = 150.0 val = x1*x2*x3*3600.0 write(*,'(F30.20)') val end program precision
The differences that you report are illusions. In single precision, i.e., default real size, machine epsilon is 1.192093E-07. The implication is that you should not compare more than the seven most significant digits in deciding whether two numbers are equal or different. The two numbers that you reported differ only in the least significant bit; that is, they have the internal representations Z'4A31E0AD' and Z'4A31E0AE'.
Secondly, when you output more digits, you can see misleading (and, indeed, non-existing) differences because of the arithmetic involved in converting from the internal binary format to a decimal string representation.
If you are not familiar with the ways in which floating point arithmetic is inexact and violates familiar rules of algebra (such as A + (B + C) = (A + B) + C), please read some articles on the topic, such as https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html .