Single precision strikes again!
It’s a rite of passage for every Fortran programmer to get bitten by this issue.
TL;DR
- Add
_wp
to every floating point value, no matter how much you don’t want to. The syntax is3.0_wp
,10.1e3_wp
, etc. - Don’t use
3_wp
expecting it to be a floating point value (if it doesn’t have the.
then it is an integer). - Don’t use
3.0
without the_wp
ever under any circumstances. - Don’t declare variables as
real
orreal(8)
orreal*8
under any circumstances, alwaysreal(wp)
. - Define
wp
, for example usinguse iso_fortran_env, only: wp => real64
to get double precision. Put it in a module if you want to use it in multiple files.