topic Re: Reason for difference in results in IntelĀ® Fortran Compiler
https://community.intel.com/t5/Intel-Fortran-Compiler/Reason-for-difference-in-results/m-p/1212643#M151977
<P>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'<SPAN>4A31E0AE'.</SPAN></P>
<P>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.</P>
<P>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 <A href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" target="_blank" rel="noopener">https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html</A> .</P>Sat, 26 Sep 2020 03:47:31 GMTmecej42020-09-26T03:47:31ZReason for difference in results
https://community.intel.com/t5/Intel-Fortran-Compiler/Reason-for-difference-in-results/m-p/1212635#M151976
<P>Hello,</P>
<P>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.</P>
<P>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.</P>
<P>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").</P>
<P>The sample code below illustrates the differences.</P>
<P>System: Intel Core i7 7820x, Linux CentOS 7.5.1804<BR />Compilers: Intel Fortran 19.0.5.281, <SPAN>PGI Fortran 19.10-0</SPAN></P>
<P>Thanks</P>
<P>Results:<BR />ifort -o prog1.x prog.f90 -O2 -mieee-fp; prog1.x<BR />val: 2914347.25<BR />ifort -o prog2.x prog.f90 -O2; prog2.x / <SPAN>pgf90 -o prog2.x prog.f90 -O2 [with/without] -Kieee; prog2.x</SPAN><BR />val: 2914347.50</P>
<LI-CODE lang="fortran">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</LI-CODE>
<P> </P>Sat, 26 Sep 2020 01:55:34 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Reason-for-difference-in-results/m-p/1212635#M151976Freitas__Henrique2020-09-26T01:55:34ZRe: Reason for difference in results
https://community.intel.com/t5/Intel-Fortran-Compiler/Reason-for-difference-in-results/m-p/1212643#M151977
<P>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'<SPAN>4A31E0AE'.</SPAN></P>
<P>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.</P>
<P>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 <A href="https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html" target="_blank" rel="noopener">https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html</A> .</P>Sat, 26 Sep 2020 03:47:31 GMThttps://community.intel.com/t5/Intel-Fortran-Compiler/Reason-for-difference-in-results/m-p/1212643#M151977mecej42020-09-26T03:47:31Z