Compiler features for trapping floating-point exceptions

To turn on XL Fortran exception trapping, compile the program with the -qflttrap option and some combination of suboptions that includes enable. This option uses trap operations to detect floating-point exceptions and generates SIGFPE signals when exceptions occur, provided that a signal handler for SIGFPE is installed.

-qflttrap also has suboptions that correspond to the names of the exception conditions. In particular, use the -qflttrap=qpxstore suboption to detect NaN or infinity values in QPX vectors. The compiler generates stores with indicating instructions for QPX vectors in registers. For example, if you are concerned with handling overflow, underflow, and QPX floating point exceptions, you can specify the following command:
  bgxlf -qflttrap=overflow:underflow:qpxstore:enable compute_pi.f
You only need enable when you are compiling the main program. However, it is very important and does not cause any problems if you specify it for other files, so always include it when you use -qflttrap.

An advantage of this approach is that performance impact is relatively low. However, this approach only traps exceptions that occur in code that you compiled with -qflttrap, which does not include system library routines.

Notes:
  1. If your program depends on floating-point exceptions occurring for particular operations, also specify -qfloat suboptions that include nofold. Otherwise, the compiler might replace an exception-producing calculation with a constant NaN or infinity value, or it might eliminate an overflow in a single-precision operation.
  2. The suboptions of the -qflttrap option replace an earlier technique that required you to modify your code with calls to the fpsets and fpgets procedures. You no longer require these calls for exception handling if you use the appropriate -qflttrap settings.
    Attention: If your code contains fpsets calls that enable checking for floating-point exceptions and you do not use the -qflttrap option when compiling the whole program, the program will produce unexpected results if exceptions occur, as explained in Table 1.