Let's say I want to define pi. I have a file pi.f
which does the following:
PROGRAM PI_program
DOUBLE PRECISION PI
PI = 3.1415926535897932
print *, pi
END
I then compile:
fortran -free-form pi.f
and run the output:
./a.out
This returns,
3.1415927410125732
i.e. close, but not the same as the initially defined number.
This is an issue if I then want to do trigonometric calculations e.g. take the cos(pi/2) - the difference in the answers is of the order 10^9, due to the asymptote.
Is there a way in Fortran to define pi such that the precision is not lost?