Datasheet

Floating-point Support
5-16 Copyright © 1999-2001 ARM Limited. All rights reserved. ARM DUI 0067D
The
fegetround
function returns the current rounding mode, as one of the macros
defined above. The
fesetround
function sets the current rounding mode to the value
provided.
fesetround
returns zero for success, or nonzero if its argument is not a valid
rounding mode.
Saving the whole environment
C9X provides functions to save and restore the entire floating-point environment:
void fegetenv(fenv_t *envp);
void fesetenv(const fenv_t *envp);
The
fegetenv
function stores the current state of the floating-point environment into the
fenv_t
variable provided. The
fesetenv
function restores the environment from the
variable provided.
Like
fesetexceptflag
,
fesetenv
does not call trap handlers when it sets the sticky flags
for trapped exceptions.
Temporarily disabling exceptions
C9X provides two functions that enable you to 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);
void feupdateenv(const fenv_t *envp);
The
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
feupdateenv
. This
restores any exception traps and calls them if necessary.
For example, suppose you have a function
frob()
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. So
you could do this:
fenv_t env;
feholdexcept(&env);
frob();
feclearexcept(FE_UNDERFLOW);
feupdateenv(&env);