Floating Point Problem ffast-math Complex divide

FX Coudert fxcoudert@gmail.com
Thu Oct 20 22:22:00 GMT 2005


>  The following floating point complex divide doesn't work with -ffast-math.
> [...]
>  This works correctly with Intel and Pathscale compilers.

Some optimization options can cause incorrect behaviour ("incorrect" in 
the sense of "not respecting the IEEE rules"). This is known and 
documented, as for example (in the gcc manual):

`-ffast-math'
      Sets `-fno-math-errno', `-funsafe-math-optimizations',
      `-fno-trapping-math', `-ffinite-math-only', `-fno-rounding-math',
      `-fno-signaling-nans' and `fcx-limited-range'.

      This option causes the preprocessor macro `__FAST_MATH__' to be
      defined.

      This option should never be turned on by any `-O' option since it
      can result in incorrect output for programs which depend on an
      exact implementation of IEEE or ISO rules/specifications for math
      functions.

Please note that the same kind of options enabling agressive 
optimization (and sometimes leading to incorrect FP behaviour) exist in 
other compilers too:

$ ifort a.f90 -O2 -complex-limited-range && ./a.out
   1.389121338912134E+276 -0.166000000000000      -1.195000000000000E-277
  (Infinity,NaN) (-0.166000000000000,0.000000000000000E+000)
  (-1.195000000000000E-277,0.000000000000000E+000)


Thanks for your interest in gfortran,
FX



More information about the Fortran mailing list