Difference between revisions of "cpp/numeric/fenv/feraiseexcept"
From cppreference.com
m (Text replace - "{{example cpp" to "{{example") |
m (Text replace - "{{cpp|" to "{{c|") |
||
Line 16: | Line 16: | ||
===Return value=== | ===Return value=== | ||
− | {{ | + | {{c|0}} if all listed exceptions were raised, non-zero value otherwise. |
===Example=== | ===Example=== |
Revision as of 20:19, 19 April 2012
Template:cpp/numeric/fenv/sidebar Template:ddcl list begin <tr class="t-dsc-header">
<td>Defined in header
</td>
<cfenv>
<td></td> <td></td> </tr> <tr class="t-dcl ">
<td >int feraiseexcept(int excepts);
</td>
<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end
Attempts to raise all floating point exceptions listed in excepts
(a bitwise OR of the floating point exception macros). If one of the exceptions is FE_OVERFLOW or FE_UNDERFLOW, this function may additionally raise FE_INEXACT. The order in which the exceptions are raised is unspecified, except that FE_OVERFLOW and FE_UNDERFLOW are always raised before FE_INEXACT.
Contents |
Parameters
excepts | - | bitmask listing the exception flags to raise |
Return value
0 if all listed exceptions were raised, non-zero value otherwise.
Example
Run this code
#include <iostream> #include <cfenv> #pragma STDC FENV_ACCESS ON int main() { std::feclearexcept(FE_ALL_EXCEPT); int r = std::feraiseexcept(FE_UNDERFLOW | FE_DIVBYZERO); std::cout << "Raising divbyzero and underflow simultaneously " << (r?"fails":"succeeds") << " and results in\n"; int e = std::fetestexcept(FE_ALL_EXCEPT); if(e & FE_DIVBYZERO) std::cout << "division by zero\n"; if(e & FE_INEXACT) std::cout << "inexact\n"; if(e & FE_INVALID) std::cout << "invalid\n"; if(e & FE_UNDERFLOW) std::cout << "underflow\n"; if(e & FE_OVERFLOW) std::cout << "overflow\n"; }
Output:
Raising divbyzero and underflow simultaneously succeeds and results in division by zero underflow