feclearexcept(3M)
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);
#include <fenv96.h>
void feclearexcept96(int excepts);
void feraiseexcept96(int excepts);
int fetestexcept96(int excepts);
void fegetexceptflag96(fexcept_t ∗flagp, int excepts);
void fesetexceptflag96(const fexcept_t ∗flagp, int excepts);
DESCRIPTION
These functions provide access to the floating point exception flags. For each function, the excepts argument specifies 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 fesetexceptflag 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 attributes:
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
| Availability | SPROm9xs |
| Interface Stability | Stable (see below) |
| MT-Level | MT-Safe |
The feclearexcept, feraiseexcept, fetestexcept, fegetexceptflag, and fesetexceptflag functions are defined by the C9X draft standard. Should the final standard change the definitions of these functions, new conforming implementations will be provided in a subsequent major release. Therefore, these functions should currently be considered Evolving.
To maintain compatibility with the present C9X definitions, programs may instead use the feclearexcept96, feraiseexcept96, fetestexcept96, fegetexceptflag96, and fesetexceptflag96 functions. Each of these functions currently performs the same operation as its counterpart without the 96 suffix. The suffixed functions, however, will retain their present definitions regardless of changes to the C9X draft. These functions are Stable.
Note that <fenv.h> currently redefines the names of the standard functions to their suffixed counterparts so that compiled programs will invoke the suffixed functions. Once the C9X draft is adopted as a standard, those redefinitions will be removed from <fenv.h>. Any program recompiled thereafter that uses the standard, unsuffixed names will then invoke the standard functions (with their final definitions), but previously compiled programs will be unaffected.
SEE ALSO
fegetenv(3M), fex_set_handling(3M), fex_set_log(3M), attributes(5)
Numerical Computation Guide
NOTES
When the FEX_CUSTOM handling mode is in effect for an exception, 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 supplies 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 location in which the compilers are installed (/opt/SUNWspro by default). See the Numerical Computation Guide or the READMEs/math_libraries file in the compiler installation area for additional information about linking with libm9x.
SunOS 5.0 — Last change: 06/25/97