Error trapping for multiprocessor systems: A primer
last update: 04/29/2003

Types of execution errors

This section provides brief introductions to typical execution errors involving NaNs and INFs.

NaN stands for Not a Number, and INF stands for Infinity error. All bit patterns that are not usable as numbers -- either those that are possible to load into a real object or those created by a floating-point operation -- are classified as NaNs or INFs.

The IEEE Standard for Binary Floating-Point Arithmetic (IEEE Std. 754-1985) describes NaNs and INFs in Section 6. The exact bit patterns for these entities on IBM SP-cluster systems are defined in Chapter 7 of IBM's XL Fortran for AIX User's Guide, and they are reproduced in the tables below. Note that other computing systems may define different bit patterns.

When a NaN or an INF occurs in a computation, the computer generates a Floating-Point Exception (FPE) that may not halt the computation. (This is why you need to use floating-point traps.) The IEEE Standard for Binary Floating-Point Arithmetic describes FPEs in Section 7. Because your program can run to completion even when FPEs occur, you should include error-trapping code in your programs. Sample code appears as an example at the end of this section.

The sample code at the end of this section prints hexadecimal values for arithmetic errors generated by the code. These hexadecimal values, called "bit patterns," are the NaNs and INFs specified in tables below. You typically don't need to examine these bit patterns, but you do need to trap all NaNs ind INFs generated by your codes.

Not a Number (NaN), a representation of a number outside the allowable IEEE range

In general, a Floating-Point Exception (FPE) occurs when a program performs an operation that produces a result outside the allowable range described by the IEEE Standard for Binary Floating-Point Arithmetic. Computers cannot perform useful calculations on numbers outside this range. A detailed discussion of NaNs and INFs appears in Chapter 7 of IBM's XL Fortran for AIX User's Guide. This section briefly summarizes that information.

Quiet NaN (NAN)

A quiet NaN (NAN) is a non-floating-point result generated by a floating-point operation in a code. A quiet NaN will be trapped if floating-point exception trapping is enabled.

Signaling NaN (NANS)

A signaling NaN (NANS) is a NaN that is deliberately put in a non-floating-point pattern defined with a data statement or by employing the compiler option -qautoinit. This form of NaN is useful to make sure your program aborts if you don't define the contents of a variable and subsequently use it in the code without initializing it.

Infinity error (INF) representing a number outside the allowable IEEE range

Infinites are both less than and greater than the range of finite numbers. Arithmetic on infinity does not signal an exception, but if your calculations produce an infinity, then an INF is generated. These invalid operations create INFs:

Single-precision and double-precision NaNs and INFs

The table below shows the IBM-defined ranges for single-precision and double-precision bit patterns that constitute a positive and negative:

Note: Since NaN is "not a number," there really isn't a "+" or "-" sign associated with it. However, the first range indicated for the NAN, the NANS, and the INF has the sign bit set to off (positive), while the second has the sign bit set to on (negative). This applies to both single-precision and double-precision NaNs and INFs.

Ranges for single-precision floating-point NaNs and INFs

Positive NANS Any bit pattern between X'7F80 0001' and X'7FBF FFFF'
Negative NANS Any bit pattern between X'FF80 0001' and X'FFBF FFFF'
Positive NAN Any bit pattern between X'7FC0 0000' and X'7FFF FFFF'
Negative NAN Any bit pattern between X'FFC0 0000' and X'FFFF FFFF'
Positive infinity X'7F80 0000'
Negative infinity X'FF80 0000'
   
Ranges for double-precision 64-bit floating-point NaNs and INFs

Positive NANS Any bit pattern between X'7FF0 0000 0000 0001' and X'7FF7 FFFF FFFF FFFF'
Negative NANS Any bit pattern between X'FFF0 0000 0000 0001' and X'FFF7 FFFF FFFF FFFF'
Positive NAN Any bit pattern between X'7FF8 0000 0000 0000' and X'7FFF FFFF FFFF FFFF'
Negative NAN Any bit pattern between X'FFF8 0000 0000 0000' and X'FFFF FFFF FFFF FFFF'
Positive infinity X'7FF0 0000 0000 0000'
Negative infinity X'FFF0 0000 0000 0000'

Sample code for detecting NaNs and INFs

This example code shows how to test for NaNs and INFs:

#! /bin/csh
#
#  This example of a serial code detects NANs, NANSs, and INFs.
#  Note: the function isnan() must be compiled unoptimised.
#  Note: I have also included a "trap" version xlf90_r statement
#  that is commented out.
#
# LoadLeveler batch commands that are used if this script is
# submitted to the share batch queue:

#@output=out
#@error=err
#@class=share
#@queue

cat << 'EOF1' >! test.F
       program main
       logical isnan
       real x,y,w
       real p_inf, n_inf, p_nanq, n_nanq, p_nans, n_nans
       real large

       x=50.
       y=500.
       w=5000.

       p_inf  = x**w
       n_inf  = -(x/0.0)
       p_nanq = p_inf - p_inf
       n_nanq = -sqrt(-w)

       print 100, p_inf, p_inf, isnan(p_inf)
       print 100, n_inf, n_inf, isnan(n_inf)
       print 100, p_nanq,p_nanq,isnan(p_nanq)
       print 100, n_nanq,n_nanq,isnan(n_nanq)

       stop
 100   format("  ",F17.2,Z17,"  isnan=",L1)
       end

! The following logical function should not be compiled with
! -qipa (intraprocessor analysis) or an optimization level of
! -O3 or higher. Such aggressive levels of optimization will
! eliminate this test.
!
       @PROCESS STRICT
       logical function isnan(arg1)
       real,intent(IN) :: arg1
       isnan=( arg1  .ne. arg1 )
       return
       end

'EOF1'
xlf90_r -g -q64 -qrealsize=8 -O2 -otest test.F
./test
rm   *.o  test *.F

Next page | Table of contents - TotalView primer

If you have questions about this document, please contact SCD Customer Support. You can also reach us by telephone 24 hours a day, seven days a week at 303-497-1278. Additional contact methods: consult1@ucar.edu and during business hours in NCAR Mesa Lab Suite 39.

© Copyright 2003. University Corporation for Atmospheric Research (UCAR). All Rights Reserved.

Address of this page: http://www.scd.ucar.edu/docs/trap.error/errortypes.html