XL Fortran for AIX 8.1

User's Guide


IEEE Floating-Point Overview

Here is a brief summary of the IEEE Standard for Floating-Point Arithmetic and the details of how it applies to XL Fortran on specific hardware platforms.For information on the draft Fortran 2000 IEEE Module and arithmetic support, see the XL Fortran for AIX Language Reference.

Compiling for Strict IEEE Conformance

By default, XL Fortran follows most, but not all of the rules in the IEEE standard. To compile for strict compliance with the standard:

IEEE Single- and Double-Precision Values

XL Fortran encodes single-precision and double-precision values in IEEE format. For the range and representation, see "Real" in the XL Fortran for AIX Language Reference.

IEEE Extended-Precision Values

The IEEE standard suggests, but does not mandate, a format for extended-precision values. XL Fortran does not use this format. Extended-Precision Values describes the format that XL Fortran uses.

Infinities and NaNs

For single-precision real values:

For double-precision real values:

These values do not correspond to any Fortran real constants. You can generate all of these by encoding the bit pattern directly. However, this programming technique is often discouraged, as it is not allowed by the Fortran standard and it could cause portability problems on machines using different bit patterns for the different values. All except NaNS values can occur as the result of arithmetic operations:


$ cat fp_values.f
real plus_inf, minus_inf, plus_nanq, minus_nanq, nans
real large
 
data plus_inf /z'7f800000'/
data minus_inf /z'ff800000'/
data plus_nanq /z'7fc00000'/
data minus_nanq /z'ffc00000'/
data nans /z'7f800001'/
 
print *, 'Special values:', plus_inf, minus_inf, plus_nanq, minus_nanq, nans
 
! They can also occur as the result of operations.
large = 10.0 ** 200
print *, 'Number too big for a REAL:', large * large
print *, 'Number divided by zero:', (-large) / 0.0
print *, 'Nonsensical results:', plus_inf - plus_inf, sqrt(-large)
 
! To find if something is a NaN, compare it to itself.
print *, 'Does a NaNQ equal itself:', plus_nanq .eq. plus_nanq
print *, 'Does a NaNS equal itself:', nans .eq. nans
! Only for a NaN is this comparison false.
 
end
$ xlf95 -o fp_values fp_values.f
** _main   === End of Compilation 1 ===
1501-510  Compilation successful for file fp_values.f.
$ fp_values
 Special values: INF -INF NaNQ -NaNQ NaNS
 Number too big for a REAL: INF
 Number divided by zero: -INF
 Nonsensical results: NaNQ NaNQ
 Does a NaNQ equal itself: F
 Does a NaNS equal itself: F

Exception-Handling Model

The IEEE standard defines several exception conditions that can occur:

OVERFLOW
The exponent of a value is too large to be represented.

UNDERFLOW
A nonzero value is so small that it cannot be represented as anything other than zero.

ZERODIVIDE
A finite nonzero value is divided by zero.

INVALID
Operations are performed on values for which the results are not defined, such as infinity-infinity, 0.0/0.0, or the square root of a negative number.

INEXACT
A computed value cannot be represented exactly, so a rounding error is introduced. (This exception is very common.)

XL Fortran always detects these exceptions when they occur, but the default is not to take any special action. Calculation continues, usually with a NaN or infinity value as the result. If you want to be automatically informed when an exception occurs, you can turn on exception trapping through compiler options or calls to intrinsic subprograms. However, different results, intended to be manipulated by exception handlers, are produced:

Table 18. Results of IEEE Exceptions, with and without Trapping Enabled

  Overflow Underflow Zerodivide Invalid Inexact
Exceptions not enabled (default) Inf Denormalized number Inf NaNQ Rounded result
Exceptions enabled Unnormalized number with biased exponent Unnormalized number with biased exponent No result No result Rounded result
Note:
Because different results are possible, it is very important to make sure that any exceptions that are generated are handled correctly. See Detecting and Trapping Floating-Point Exceptions for instructions on doing so.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]