Here is a brief summary of the ANSI/IEEE Standard for Binary Floating-Point Arithmetic, ANSI/IEEE Std 754-1985 and the details of how it applies to XL Fortran on specific hardware platforms. For information on the Fortran 2003 IEEE Module and arithmetic support, see the XL Fortran Language Reference.
By default, XL Fortran follows most, but not all of the rules in the IEEE standard. To compile for strict compliance with the standard:
XL Fortran encodes single-precision and double-precision values in IEEE format. For the range and representation, see Real in the XL Fortran Language Reference.
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.
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, or by using the ieee_value function provided in the ieee_arithmetic module. Using the ieee_value function is the preferred programming technique, as it is allowed by the Fortran 2003 standard and the results are portable. Encoding the bit pattern directly could cause portability problems on machines using different bit patterns for the different values. All except signaling NaN 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 quiet NaN equal itself:', plus_nanq .eq. plus_nanq print *, 'Does a signaling NaN 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 NAN -NAN NAN Number too big for a REAL: INF Number divided by zero: -INF Nonsensical results: NAN NAN Does a quiet NaN equal itself: F Does a signaling NaN equal itself: F
The IEEE standard defines several exception conditions that can occur:
XL Fortran always detects these exceptions when they occur, but by default does not 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:
Overflow | Underflow | Zerodivide | Invalid | Inexact | |
---|---|---|---|---|---|
Exceptions not enabled (default) | INF | Denormalized number | INF | NaN | Rounded result |
Exceptions enabled | Unnormalized number with biased exponent | Unnormalized number with biased exponent | No result | No result | Rounded result |