NAME
feclearexcept, feraiseexcept, fetestexcept, fegetexceptflag,
fesetexceptflag - access floating point exception flags
SYNOPSIS
cc [ flag ... ] file ... -R/opt/SUNWspro/lib
-L/opt/SUNWspro/lib -lm9x [ library ... ]
#include <fenv.h>
void feclearexcept(int excepts);
void feraiseexcept(int excepts);
int fetestexcept(int excepts);
void fegetexceptflag(fexcept_t *flagp, int excepts);
void fesetexceptflag(const fexcept_t *flagp, int excepts);
DESCRIPTION
These functions provide access to the floating point excep-
tion flags. For each function, the excepts argument speci-
fies one or more exceptions indicated by a bitwise "or" of
any of the following values (defined in <fenv.h>):
FE_INEXACT
FE_UNDERFLOW
FE_OVERFLOW
FE_DIVBYZERO
FE_INVALID
For convenience, the macro FE_ALL_EXCEPT is defined to be
the bitwise "or" of all of the above values.
feclearexcept(excepts) clears the flags for the specified
exceptions.
feraiseexcept(excepts) raises the specified exceptions: for
each exception indicated, if FEX_NONSTOP handling mode is in
effect, the exception's flag is set, and otherwise the
appropriate action is taken as described in
fex_set_handling(3M).
fetestexcept(excepts) returns a bitwise "or" of the values
listed above corresponding to the subset of the specified
exceptions whose flags are set.
fegetexceptflag(flagp, excepts) saves the current values of
the flags for the exceptions indicated by excepts in the
object pointed to by flagp. The type fexcept_t is defined
in <fenv.h>.
fesetexceptflag(flagp, excepts) restores the values of the
flags for the exceptions indicated by excepts from the
object pointed to by flagp. This object must have been set
by a previous call to fegetexceptflag(); otherwise the
effect on the indicated flags is undefined. (The fesetex-
ceptflag function does not raise exceptions, but only sets
the state of the flags.)
EXAMPLE
The following code fragment calls the function f() if the
invalid operation flag is set and g() if the overflow flag
is set:
#include <fenv.h>
/*...*/
{
int set_excepts;
feclearexcept(FE_INVALID | FE_OVERFLOW);
/* computation that may raise exceptions */
set_excepts = fetestexcept(FE_INVALID | FE_OVERFLOW);
if (set_excepts & FE_INVALID) f();
if (set_excepts & FE_OVERFLOW) g();
/*...*/
}
ATTRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
_______________________________________
| ATTRIBUTE TYPE | ATTRIBUTE VALUE|
|____________________|_________________|
| Availability | SPROm9xs |
| Interface Stability| Standard |
| MT-Level | MT-Safe |
|____________________|_________________|
SEE ALSO
fegetenv(3M), fex_set_handling(3M), fex_set_log(3M), attri-
butes(5)
Numerical Computation Guide
NOTES
When the FEX_CUSTOM handling mode is in effect for an excep-
tion, raising that exception via feraiseexcept will cause
the handling function to be invoked. The handling function
may then modify the exception flags to be set as described
in fex_set_handling(3M). Any result value the handler sup-
plies will be ignored.
As shown in the synopsis, the recommended way to link with
libm9x using cc is to specify
-Rinstall-path/lib -Linstall-path/lib -lm9x
on the command line, where install-path refers to the loca-
tion in which the compilers are installed (/opt/SUNWspro by
default). See the Numerical Computation Guide for addi-
tional information about linking with libm9x.