I’m trying to port a program from Red Hat Linux to IBM AIX, but the precision on the IBM system seems different to the Red Hat system. Does anyone know why this is happing? Here is an example:
program main
implicit none
real(8) a
a=0.2D0
print *,a
end program
On Red Hat I get output:
0.200000000000000
On AIX I get output:
0.200000000000000011
The version of the system I’m using:
IBM XL Fortran for AIX, V13.1 (5724-X15)
Version: 13.01.0000.0005
and
Linux 2.6.18-8.el5 x86_64
ifort Version 10.0
This is probably just a difference in the default number of digits printed.
0.2cannot be accurately represented as a binary floating point number, so you are always going to have some garbage in the least significant digits. The default number of digits printed for a float withifortis simply set to be low enough that you don’t see it in this case. The actual calculation (most likely) has the same precision. Try this with both compilers:This will show you that
ifortalso has the ones at the end. On my computer, it prints0.20000000000000001110.