Floating point exception from exp

Large negative arguments to exp() can give a floating point exception.
See comments in the example code.

      PROGRAM EXPTEST
C
C   Testing exponential with large negative arguments.
C   Compile with "pgfortran -g -fast -Ktrap=fp -o exptest exptest.F.
C   The parameter SCALING is to be set to a large positive number.
C   If it is set large enough (1.E8, for example), then the program
C   gets a floating point exception with pgfortran 15.10-0 64-bit target
C   on x86-64 Linux -tp sandybridge.
C   The exception comes from __fvd_exp_vex, called by __fvd_exp_vex_256.
C   Omitting "Ktrap=fp" is a workaround.
C   Adding "-Mnovect" to the compiler flags is another workaround.
C
      IMPLICIT NONE
      INTEGER, PARAMETER :: JD=24
      REAL(KIND=8), PARAMETER :: SCALING=1.E8
      REAL(KIND=8), DIMENSION(JD) :: EARG,Y
      INTEGER :: J
C
C
      DO J = 1,JD
         EARG(J) = -SCALING * REAL(J)/24.D0
      ENDDO
      DO J = 1,JD
         Y(J) = EXP(EARG(J))
      ENDDO
      WRITE(*,"('Min and max of exponential=',2ES20.8)")
     &     MINVAL(Y(1:JD)),MAXVAL(Y(1:JD))
      END

We replicated the issue and we have logged this as TPR 22323.

We note that if you add a STOP statement, the F2003 standard says you need to
report the state of the FP status bits.

One of status bits ieee_inexact we do not prevent from being set,
and we suggest you ignore it.

On Nehalem type CPUs, ieee_inexact is set, but on sandybridge CPUs
ieee_inexact, and ieee_invalid are set.

dave

More information.

On Sandybridge CPUs, compiling

-fast

yields

ieee_invalid <— not good.
and
ieee_inexact

but if you request better precision through maintaining operation order
and some more precise routines(ie -Kieee)

-fast -Kieee

execution yields that
ieee_underflow
ieee_inexact

which are fairly harmless conditions we don’t avoid.

dave