|Non-Confidential||PDF version||ARM DUI0475M|
|Home > Floating-point Support > Controlling the ARM floating-point environment > Functions for temporarily disabling exceptions|
feupdateenv functions let you temporarily disable exception trapping.
These functions let you avoid risking exception traps when executing code that might cause exceptions. This is useful when, for example, trapped exceptions are using the ARM® default behavior. The default is to cause SIGFPE and terminate the application.
int feholdexcept(fenv_t *envp);
const fenv_t *envp);
feholdexcept() function saves the
current floating-point environment in the
fenv_t variable provided,
sets all exceptions to be untrapped, and clears all the exception
sticky flags. You can then execute code that might cause unwanted
exceptions, and make sure the sticky flags for those exceptions
are cleared. Then you can call
This restores any exception traps and calls them if necessary. For
example, suppose you have a function,
that might cause the Underflow or Invalid Operation exceptions (assuming
both exceptions are trapped). You are not interested in Underflow,
but you want to know if an invalid operation is attempted. You can implement
the following code to do this:
fenv_t env; feholdexcept(&env); frob(); feclearexcept(FE_UNDERFLOW); feupdateenv(&env);
Then, if the
frob() function raises Underflow,
it is cleared again by
no trap occurs when
feupdateenv() is called.
frob() raises Invalid Operation,
the sticky flag is set when
called, so the trap handler is invoked.
This mechanism is provided by C99 because C99 specifies no
way to change exception trapping for individual exceptions. A better
method is to use
__ieee_status() to disable
the Underflow trap while leaving the Invalid Operation trap enabled.
This has the advantage that the Invalid Operation trap handler is
provided with all the information about the invalid operation (that
is, what operation was being performed, and on what data), and can
invent a result for the operation. Using the C99 method, the Invalid
Operation trap handler is called after the fact, receives no information
about the cause of the exception, and is called too late to provide
a substitute result.