function
<cfenv>
feupdateenv
int feupdateenv (const fenv_t* envp);
Update floating-point environment
Attempts to establish the state of the floating-point environment as represented by the object pointed by envp. It then attempts to raise the exceptions that were set in the floating-point environment before the call.
Programs calling this function shall ensure that pragma FENV_ACCESS is enabled for the call.
Parameters
- envp
- Either a pointer to a fenv_t value (filled by a previous call to fegetenv or feholdexcept), or one of the floating-point environment macro values:
| value | description |
| FE_DFL_ENV | Default floating-point environment (the same as at program startup). |
Certain library implementations may support additional floating-point environment state values (with their corresponding macros also beginning with FE_).
Return Value
Zero, if successful.
A non-zero value otherwise.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| /* feholdexcept/feupdateenv example */ #include <stdio.h> /* printf, puts */ #include <fenv.h> /* feholdexcept, feclearexcept, fetestexcept, feupdateenv, FE_* */ #include <math.h> /* log */ #pragma STDC FENV_ACCESS on double log_zerook (double x) { fenv_t fe; feholdexcept(&fe); x=log(x); feclearexcept (FE_OVERFLOW|FE_DIVBYZERO); feupdateenv(&fe); return x; } int main () { feclearexcept (FE_ALL_EXCEPT); printf ("log(0.0): %f\n", log_zerook(0.0)); if (!fetestexcept(FE_ALL_EXCEPT)) puts ("no exceptions raised"); return 0; }
|
Possible output:
log(0.0): -inf no exceptions raised |
Data races
Each thread maintains a separate floating-point environment with its own state. Spawning a new thread copies the current state. [This applies to C11 and C++11 implementations]
Exceptions
No-throw guarantee: this function never throws exceptions.
Note that C floating-point exceptions are not C++ exceptions, and thus are not caught by try/catch blocks.
See also
- feupdateenv
- Update floating-point environment (function)
- fegetenv
- Get floating-point environment (function)
- fesetenv
- Set floating-point environment (function)