Search code examples
linuxfortranprecisionaixintel-fortran

Fortran improper output on AIX and Linux


I have a scenario where i declare a variable real*8 and read a value

0.1234123412341234

which is stored in a file.

When i try to read it on Linux to a variable and display the value, it prints

0.12341234123412

whereas when i run the same code for AIX it prints the value

0.12341234123412370

Why does both the platform print different values for the same code? Is there any possibility to overcome this without using format specifier?

P.S

AIX compiler is xlf

Linux compiler is ifort


Solution

  • I assume that you are using list-directed IO, write (X, *). While this type of IO is convenient, the output is not fully specified by the standard. If you want your output to be extremely similar across compilers and platforms, you should use a format. (You might still have small variations in results due to the use of finite-precision arithmetic.)