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.
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 for AIX 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. 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
The IEEE standard defines several exception conditions that can occur:
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
|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|