How can C/Fortran floating point exceptions be trapped on Solaris in order to modify the default results. (Doc ID 1295477.1)

Last updated on OCTOBER 25, 2016

Applies to:

Oracle Solaris Studio - Version Forte Developer 6 Update 2 to 12.2 [Release 6.0 to 12]
Oracle Solaris on x86 (32-bit)
Oracle Solaris on SPARC (64-bit)
Oracle Solaris on x86-64 (64-bit)
Oracle Solaris on SPARC (32-bit)

Goal

 

How can Fortran floating point exceptions be trapped on Solaris platforms so that:

0.0 / 0.0 = 0.0
Inf / Inf = Inf
Inf * 0.0 = 0.0

Without trapping all three result in -NaN (Not A Number). Note:  "Inf" is infinity.

In Fortran, the default execution of the following sample (test_exceptions.f) will result in :

      Program test_exceptions

      Write(*,*) 'Floating Point'
      A=1.
      B=0.
 1111 FORMAT(F5.1,' / ',F5.1,' = ',F5.1)
      C=B/B
      WRITE(6,1111)B,B,C
      C=A/B
      D=C/C
      WRITE(6,1111)C,C,D
      D=C*B
      WRITE(6,1111)C,B,D
      End

 

% f77 test_exceptions.f
NOTICE: Invoking /space/sunstudio12.1/bin/f90 -f77 -ftrap=%none test_exceptions.f
test_exceptions.f:
 MAIN test_exceptions:

% ./a.out
 Floating Point
  0.0 /   0.0 = NaN
Inf   / Inf   = NaN
Inf   /   0.0 = NaN

Solution

Sign In with your My Oracle Support account

Don't have a My Oracle Support account? Click to get started

My Oracle Support provides customers with access to over a
Million Knowledge Articles and hundreds of Community platforms