6.5.10 feholdexcept Function
Stores the floating-point environment into an object then installs a non-stop exception mode.
Include
<fenv.h>
Prototype
int feholdexcept(fenv_t * envp);
Argument
envp
- a pointer to the object in which the environment should be stored
Return Value
This function returns zero if and only if the non-stop exception mode was successfully installed.
Remarks
This function saves the current floating-point environment in the object pointed to by
envp
, clears the floating-point status flags, and then installs a
non-stop exception mode, if available. Once installed, the non-stop mode will allow
execution to continue on a floating-point exception and can be used to hide spurious
floating-point exceptions.
Example
See the notes at the beginning of this chapter or section for
information on using printf()
or scanf()
(and other functions reading and writing the stdin
or
stdout
streams) in the example code.
#include <fenv.h>
#include <stdio.h>
#include <assert.h>
int main(void)
{
int nonStopFail;
fenv_t envp;
volatile double x, y=1E30;
nonStopFail = feholdexcept(&envp); // save the current environment
assert(nonStopFail == 0);
fesetround(FE_UPWARD);
x = 1 / y;
printf("the small result rounded up is %g\n", x);
fesetround(FE_DOWNWARD);
x = 1 / y;
printf("the small result rounded down is %g\n", x);
feupdateenv(&envp); // restore the environment
}
Example Output
The small result rounded up is 1.00001e-30
The small result rounded down is 9.99999e-31