CHALLENGE using root_fortran to find root of a complex function

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 is 3.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 or real(8) or real*8 under any circumstances, always real(wp).
  • Define wp, for example using use iso_fortran_env, only: wp => real64 to get double precision. Put it in a module if you want to use it in multiple files.
7 Likes