HP-UX Floating-Point Guide

Chapter 5 139
Manipulating the Floating-Point Status Register
Run-Time Mode Control: The fenv(5) Suite
Manipulating the Floating-Point
Environment: fegetenv, fesetenv, feupdateenv,
feholdexcept
The fenv(5) suite includes a group of functions that allow you to manage
the floating-point environment as a whole. The declarations for these
functions are as follows.
void fegetenv(fenv_t *envp);
void fesetenv(const fenv_t *envp);
void feupdateenv(const fenv_t *envp);
int feholdexcept(fenv_t *envp);
All these functions take as argument a value representing the
floating-point environment.
The fegetenv function stores the current floating-point environment in
the object pointed to by envp.
The fesetenv function establishes the floating-point environment
represented by the object pointed to by envp. The argument envp must
point to an object set by a call to fegetenv or feholdexcept, or equal
the macro FE_DFL_ENV.
The feupdateenv function saves the current exceptions in its automatic
storage, installs the floating-point environment represented through
envp, and then raises the saved exceptions. The argument envp must
point to an object set by a call to fegetenv or feholdexcept, or equal
the macro FE_DFL_ENV.
The feholdexcept function saves the current floating-point
environment in the object pointed to by envp, clears the exception flags,
and disables all traps.
The functions can be used together to save and restore the floating-point
environment at different parts of your program and in different ways, so
that you can control whether selected exceptions are hidden from calling
routines. For example, you can call feholdexcept to store the
floating-point environment temporarily and start afresh with no flags or
traps set. Later on, you can use either fesetenv or feupdateenv to
restore the saved environment, or save and update it. A call to fesetenv
does not raise any saved exceptions, however, whereas a call to
feupdateenv does raise the exceptions.