There are five floating-point exceptions:
- divide-by-zero,
- overflow,
- underflow,
- imprecise (inexact) result, and
- invalid operation.
When a floating-point exception occurs, the corresponding sticky bit is set (1), and if the mask bit is enabled (1), the trap takes place. These routines let the user change the behavior on occurrence
of any of these exceptions, as well as change the rounding mode for floating-point operations.
The mask argument is formed by the logical OR operation of the following floating-point exception masks:
|
FP_X_INV /* invalid operation exception */
FP_X_OFL /* overflow exception */
FP_X_UFL /* underflow exception */
FP_X_DZ /* divide-by-zero exception */
FP_X_IMP /* imprecise (loss of precision) */
|
The following floating-point rounding modes are passed to fpsetround and returned by fpgetround().
|
FP_RN /* round to nearest representative number */
FP_RP /* round to plus infinity */
FP_RM /* round to minus infinity */
FP_RZ /* round to zero (truncate) */
|
The default environment is rounding mode set to nearest (FP_RN) and all traps disabled.
The fpsetsticky() function modifies all sticky flags. The fpsetmask() function changes all mask bits. The fpsetmask() function clears the sticky
bit corresponding to any exception being enabled.
|