FPGETROUND(3)

NAME
fpgetround, fpsetround, fpgetmask, fpsetmask, fpgetsticky, fpresetsticky - IEEE floating point interface

SYNOPSIS
#include <floatingpoint.h>
typedef enum {
FP_RN,
/* round to nearest */
FP_RM,
/* round to minus infinity */
FP_RP,
/* round to plus infinity */
FP_RZ,
/* truncate */
} fp_rnd;

fp_rnd
fpgetround();
fp_rnd
fpsetround(fp_rnd direction);
#define fp_except int
#define FP_X_INV 0x01 /* invalid */
#define FP_X_OFL 0x08 /* overflow */
#define FP_X_UFL 0x10 /* underflow */
#define FP_X_DZ 0x04 /* divide-by-zero */
#define FP_X_IMP 0x20 /* loss of precision */
#define FP_X_DNML 0x02 /* denormal */
fp_except
fpgetmask();
fp_except
fpsetmask(fp_except mask);
fp_except
fpgetsticky();
fp_except
fpresetsticky(fp_except sticky);

DESCRIPTION
When a floating point exception is detected, the exception sticky flag is set and the exception mask is tested. If the mask is set, then a trap occurs. These routines allow both setting the floating point exception masks, and resetting the exception sticky flags after an exception is detected. In addition, they allow setting the floating point rounding mode.

The fpgetround() function returns the current floating point rounding mode.

The fpsetround() function sets the floating point rounding mode and returns the previous mode.

The fpgetmask() function returns the current floating point exception masks.

The fpsetmask() function sets the floating point exception masks and returns the previous masks.

The fpgetsticky() function returns the current floating point sticky flags.

The fpresetsticky() function clears the floating point sticky flags and returns the previous flags.

Sample code which prevents a trap on divide-by-zero:

    fpsetmask(~FP_X_DZ);
    a = 1.0;
    b = 0;
    c = a / b;
    fpresetsticky(FP_X_DZ);
    fpsetmask(FP_X_DZ);

SEE ALSO
isnan(3)

CAVEAT
After a floating point exception and before a mask is set, the sticky flags must be reset. If another exception occurs before the sticky flags are reset, then a wrong exception type may be signaled.

HISTORY
These routines are based on SysV/386 routines of the same name.