Allows operations on the floating-point exception flags.
Standard C Library (libc.a)
#include <float.h>
#include <fpxcp.h>
void fp_clr_flag( Mask)
fpflag_t Mask;
void fp_set_flag(Mask)
fpflag_t Mask;
fpflag_t fp_read_flag( )
fpflag_t fp_swap_flag(Mask)
fpflag_t Mask;
These subroutines aid in determining both when an exception has occurred and the exception type. These subroutines can be called explicitly around blocks of code that may cause a floating-point exception.
According to the IEEE Standard for Binary Floating-Point Arithmetic, the following types of floating-point operations must be signaled when detected in a floating-point operation:
An invalid operation occurs when the result cannot be represented (for example, a sqrt operation on a number less than 0).
The IEEE Standard for Binary Floating-Point Arithmetic states: "For each type of exception, the implementation shall provide a status flag that shall be set on any occurrence of the corresponding exception when no corresponding trap occurs. It shall be reset only at the user's request. The user shall be able to test and to alter the status flags individually, and should further be able to save and restore all five at one time."
Floating-point operations can set flags in the floating-point exception status but cannot clear them. Users can clear a flag in the floating-point exception status using an explicit software action such as the fp_swap_flag (0) subroutine.
The fpxcp.h file defines the following names for the flags indicating floating-point exception status:
Item | Description |
---|---|
FP_INVALID | Invalid operation summary |
FP_OVERFLOW | Overflow |
FP_UNDERFLOW | Underflow |
FP_DIV_BY_ZERO | Division by 0 |
FP_INEXACT | Inexact result |
In addition to these flags, the operating system supports additional information about the cause of an invalid operation exception. The following flags also indicate floating-point exception status and defined in the fpxcp.h file. The flag number for each exception type varies, but the mnemonics are the same for all ports. The following invalid operation detail flags are not required for conformance to the IEEE floating-point exceptions standard:
Item | Description |
---|---|
FP_INV_SNAN | Signaling NaN |
FP_INV_ISI | INF - INF |
FP_INV_IDI | INF / INF |
FP_INV_ZDZ | 0 / 0 |
FP_INV_IMZ | INF x 0 |
FP_INV_CMP | Unordered compare |
FP_INV_SQRT | Square root of a negative number |
FP_INV_CVI | Conversion to integer error |
FP_INV_VXSOFT | Software request |
Item | Description |
---|---|
Mask | A 32-bit pattern that identifies floating-point exception flags. |
The fp_clr_flag subroutine resets the exception status flags defined by the Mask parameter to 0 (false). The remaining flags in the exception status are unchanged.
The fp_set_flag subroutine sets the exception status flags defined by the Mask parameter to 1 (true). The remaining flags in the exception status are unchanged.
The fp_read_flag subroutine returns the current floating-point exception status. The flags in the returned exception status can be tested using the flag definitions above. You can test individual flags or sets of flags.
The fp_swap_flag subroutine writes the Mask parameter into the floating-point status and returns the floating-point exception status from before the write.
Users set or reset multiple exception flags using fp_set_flag and fp_clr_flag by ANDing or ORing definitions for individual flags. For example, the following resets both the overflow and inexact flags:
fp_clr_flag (FP_OVERFLOW | FP_INEXACT)