-qflttrap
Category
Pragma equivalent
#pragma options [no]flttrap
Purpose
Determines what types of floating-point exceptions to detect at run time.
The program receives a SIGTRAP signal when the corresponding exception occurs.
Syntax
.-noflttrap------------------------------. >>- -q--+-flttrap--+---------------------------+-+------------->< | .-:------------------. | | | .-zero-------. | | | | +-zerodivide-+ | | | | +-und--------+ | | | | +-underflow--+ | | | | +-ov---------+ | | | | +-overflow---+ | | | | +-inv--------+ | | | | +-invalid----+ | | | | +-inex-------+ | | | V +-inexact----+ | | '-=------+-enable-----+---+-' +-en---------+ +-imprecise--+ +-imp--------+ '-nanq-------'
Defaults
-qnoflttrap
Specifying -qflttrap option with no suboptions is equivalent to -qflttrap=overflow:underflow:zerodivide:invalid:inexact
Parameters
- 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. If imprecise is in effect, traps will not report exactly where the exception occurred.
- imprecise, imp
- Enables imprecise detection of the specified exceptions. The compiler generates instructions after a block of code and just before the main program returns, to check if any of the specified exceptions (overflow, underflow, zerodivide, invalid, or inexact) have occurred. If an exception has occurred, an exception status flag is set in the Floating-Point Status and Control Register, but the exact location of the exception is not determined. Because instructions are not generated after each floating-point operation and function call to check for exceptions, this suboption can result in a slight performance improvement.
- inexact, inex
- Enables the detection of floating-point inexact operations. If imprecise is not also specified, the compiler generates instructions after each floating-point operation and function call to check if an inexact operation exception has occurred. 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 imprecise is not also specified, the compiler generates instructions after each floating-point operation and function call to check if an invalid operation exception has occurred. 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 imprecise is not also specified, the compiler generates instructions after each floating-point operation and function call to check if an overflow exception has occurred. 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 imprecise is not also specified, the compiler generates instructions after each floating-point operation and function call to check if an underflow exception has occurred. 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 imprecise is not also specified, the compiler generates instructions after each floating-point operation and function call to check if a zero-divide exception has occurred. 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 -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 -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 -qflttrap to trap any exceptions.
- 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.
export SQRT_EXCEPTION=3.1
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);
}
xlc -qflttrap=zerodivide:enable divide_by_zero.c
The zerodivide suboption identifies the type of exception to guard against. The enable suboption causes a SIGTRAP signal to be generated when the exception occurs.