-ftrapping-math (-qflttrap)

Purpose

Determines what types of floating-point exceptions to detect at run time.

The program receives a SIGFPE signal when the corresponding exception occurs.

Syntax

Read syntax diagramSkip visual syntax diagram
        .-notrapping-math-.   
>>- -f--+-trapping-math---+------------------------------------><

Read syntax diagramSkip visual syntax diagram
        .-noflttrap------------------------------.   
>>- -q--+-flttrap--+---------------------------+-+-------------><
                   |    .-:------------------. |     
                   |    |   .-zero-------.   | |     
                   |    |   +-zerodivide-+   | |     
                   |    |   +-und--------+   | |     
                   |    |   +-underflow--+   | |     
                   |    |   +-ov---------+   | |     
                   |    |   +-overflow---+   | |     
                   |    |   +-inv--------+   | |     
                   |    |   +-invalid----+   | |     
                   |    |   +-inex-------+   | |     
                   |    V   +-inexact----+   | |     
                   '-=------+-enable-----+---+-'     
                            +-en---------+           
                            '-nanq-------'           

Defaults

-fnotrapping-math or -qnoflttrap

Specifying -qflttrap option with no suboptions is equivalent to -qflttrap=overflow:underflow:zerodivide:invalid:inexact

Parameters

Note: You can specify the following suboptions with -qflttrap only.
enable, en
Inserts a trap when the specified exceptions (overflow, underflow, zerodivide, invalid, or inexact) occur. You must specify this suboption if you want to turn on exception trapping without modifying your source code. If any of the specified exceptions occur, a SIGTRAP or SIGFPE signal is sent to the process with the precise location of the exception.
inexact, inex
Enables the detection of floating-point inexact operations. If a floating-point inexact operation occurs, an inexact operation exception status flag is set in the Floating-Point Status and Control Register (FPSCR).
invalid, inv
Enables the detection of floating-point invalid operations. If a floating-point invalid operation occurs, an invalid operation exception status flag is set in the FPSCR.
nanq
Generates code to detect Not a Number Quiet (NaNQ) and Not a Number Signalling (NaNS) exceptions before and after each floating-point operation, including assignment, and after each call to a function returning a floating-point result to trap if the value is a NaN. Trapping code is generated regardless of whether the enable suboption is specified.
overflow, ov
Enables the detection of floating-point overflow. If a floating-point overflow occurs, an overflow exception status flag is set in the FPSCR.
underflow, und
Enables the detection of floating-point underflow. If a floating-point underflow occurs, an underflow exception status flag is set in the FPSCR.
zerodivide, zero
Enables the detection of floating-point division by zero. If a floating-point zero-divide occurs, a zero-divide exception status flag is set in the FPSCR.

Usage

Exceptions will be detected by the hardware, but trapping is not enabled.

It is recommended that you use the enable suboption whenever compiling the main program with -ftrapping-math (-qflttrap). This ensures that the compiler will generate the code to automatically enable floating-point exception trapping, without requiring that you include calls to the appropriate floating-point exception library functions in your code.

If you specify -qflttrap more than once, both with and without suboptions, the -qflttrap without suboptions is ignored.

The -ftrapping-math (-qflttrap) option is recognized during linking with IPA. Specifying the option at the link step overrides the compile-time setting.

If your program contains signalling NaNs, you should use the -qfloat=nans option along with -ftrapping-math (-qflttrap) to trap any exceptions.

The compiler exhibits behavior as illustrated in the following examples when the -ftrapping-math (-qflttrap) option is specified together with an optimization option:
  • with -O2:
    • 1/0 generates a div0 exception and has a result of infinity
    • 0/0 generates an invalid operation
  • with -O3 or greater:
    • 1/0 generates a div0 exception and has a result of infinity
    • 0/0 returns zero multiplied by the result of the previous division.
Note: Due to the transformations performed and the exception handling support of some vector instructions, use of -qsimd=auto may change the location where an exception is caught or even cause the compiler to miss catching an exception.

Predefined macros

None.

Example

#include <stdio.h>

int main()
{
  float x, y, z;
  x = 5.0;
  y = 0.0;
  z = x / y;
  printf("%f", z);
}      
When you compile this program with the following command, the program stops when the division is performed.
xlc -ftrapping-math divide_by_zero.c

The zerodivide suboption identifies the type of exception to guard against. The enable suboption causes a SIGFPE signal to be generated when the exception occurs.

Related information



Voice your opinion on getting help information Ask IBM compiler experts a technical question in the IBM XL compilers forum Reach out to us