fpgetround(3C) (C Programming Language Utilities) fpgetround(3C)
NAME
fpgetround, fpsetround, fpgetmask, fpsetmask, fpgetsticky,
fpsetsticky - IEEE floating point environment control
SYNOPSIS
#include <ieeefp.h>
fprnd fpgetround (void);
fprnd fpsetround (fprnd rnddir);
fpexcept fpgetmask (void);
fpexcept fpsetmask (fpexcept mask);
fpexcept fpgetsticky (void);
fpexcept fpsetsticky (fpexcept sticky);
DESCRIPTION
There are eight floating point exceptions: branch/set on unordered,
signalling not a number, operand error, overflow, underflow, divide-
by-zero, inexact operation, and inexact decimal input. When an
exception occurs, the trap takes place if the corresponding mask bit
is set(1), and the fact is noted by setting an associated accrued
exception bit (sticky bit). There are five sticky bits: invalid
operation, overflow, underflow, divide-by-zero, and inexact result.
The following algorithm is used in setting the sticky bits:
FPAIOP |= FPEBSUN | FPESNAN | FPEOPERR
FPAOVFL |= FPEOVFL
FPAUNFL |= FPEUNFL & FPEINEX2
FPADZ |= FPEDZ
FPAINEX |= FPEINEX1 | FPEINEX2 | FPEOVFL
The fpexcept mask can take the following (not exclusive) values:
/* exception enable */
FPEBSUN /* branch/set on unordered */
FPESNAN /* signalling not a number */
FPEOPERR /* operand error */
FPEOVFL /* overflow */
FPEUNFL /* underflow */
FPEDZ /* divide-by-zero */
FPEINEX2 /* inexact operation */
FPEINEX1 /* inexact decimal input */
/* accrued exceptions */
FPAIOP /* invalid operation */
7/91 Page 1
fpgetround(3C) (C Programming Language Utilities) fpgetround(3C)
FPAOVFL /* overflow */
FPAUNFL /* underflow */
FPADZ /* divide-by-zero */
FPAINEX /* inexact result */
The fprnd mask can take the following (exclusive) values to control
the rounding mode:
FPRN /* round to nearest representative number */
FPRZ /* round to zero (truncate) */
FPRM /* round to minus infinity */
FPRP /* round to plus infinity */
The following 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.
fpgetround returns the current rounding mode.
fpsetround sets the rounding mode and returns the previous rounding
mode.
fpgetmask returns the current exception masks.
fpsetmask sets the exception masks and returns the previous setting.
fpgetsticky returns the current exception sticky flags.
fpsetsticky sets (clears) the exception sticky flags and returns the
previous setting.
The default environment is rounding mode set to nearest(FPRN) and
all traps disabled.
Individual bits may be examined using the constants defined in
<ieeefp.h>.
SEE ALSO
isnan(3C).
NOTES
fpsetsticky modifies all sticky flags. fpsetmask changes all mask
bits. fpsetmask clears the sticky bit associated with each exception
being enabled according to the following table:
sticky bit cleared mask bit(s) set
FPAIOP FPEBSUN & FPESNAN & FPEOPERR
FPAOVFL FPEOVFL
FPAUNFL FPEUNFL | FPEINEX2
FPADZ FPEDZ
FPAINEX FPEINEX1 | FPEINEX2 | FPEOVFL
Page 2 7/91
fpgetround(3C) (C Programming Language Utilities) fpgetround(3C)
C requires truncation (round to zero) for floating point to integral
conversions. The current rounding mode has no effect on these
conversions.
One must clear the sticky bit to recover from the trap and to
proceed. If the sticky bit is not cleared before the next trap
occurs, a wrong exception type may be signaled.
7/91 Page 3