Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/numeric/fenv/feraiseexcept"

From cppreference.com
< cpp‎ | numeric‎ | fenv
m (Text replace - "/sidebar" to "/navbar")
(fmt)
Line 4: Line 4:
 
{{ddcl list header | cfenv}}
 
{{ddcl list header | cfenv}}
 
{{ddcl list item | notes={{mark since c++11}} |
 
{{ddcl list item | notes={{mark since c++11}} |
int feraiseexcept(int excepts);
+
int feraiseexcept( int excepts );
 
}}
 
}}
 
{{ddcl list end}}
 
{{ddcl list end}}
  
Attempts to raise all floating point exceptions listed in {{tt|excepts}} (a bitwise OR of the [[cpp/numeric/fenv/FE_exceptions|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.
+
Attempts to raise all floating point exceptions listed in {{tt|excepts}} (a bitwise OR of the [[cpp/numeric/fenv/FE_exceptions|floating point exception macros]]). If one of the exceptions is {{c|FE_OVERFLOW}} or {{c|FE_UNDERFLOW}}, this function may additionally raise {{c|FE_INEXACT}}. The order in which the exceptions are raised is unspecified, except that {{c|FE_OVERFLOW}} and {{c|FE_UNDERFLOW}} are always raised before {{c|FE_INEXACT}}.
  
 
===Parameters===
 
===Parameters===
Line 34: Line 34:
 
               << (r?"fails":"succeeds") << " and results in\n";
 
               << (r?"fails":"succeeds") << " and results in\n";
 
     int e = std::fetestexcept(FE_ALL_EXCEPT);
 
     int e = std::fetestexcept(FE_ALL_EXCEPT);
     if(e & FE_DIVBYZERO)
+
     if (e & FE_DIVBYZERO) {
 
         std::cout << "division by zero\n";
 
         std::cout << "division by zero\n";
     if(e & FE_INEXACT)
+
    }
 +
     if (e & FE_INEXACT) {
 
         std::cout << "inexact\n";
 
         std::cout << "inexact\n";
     if(e & FE_INVALID)
+
    }
 +
     if (e & FE_INVALID) {
 
         std::cout << "invalid\n";
 
         std::cout << "invalid\n";
     if(e & FE_UNDERFLOW)
+
    }
 +
     if (e & FE_UNDERFLOW) {
 
         std::cout << "underflow\n";
 
         std::cout << "underflow\n";
     if(e & FE_OVERFLOW)
+
    }
 +
     if (e & FE_OVERFLOW) {
 
         std::cout << "overflow\n";
 
         std::cout << "overflow\n";
 
+
    }
 
}
 
}
 
  | output=
 
  | output=

Revision as of 03:22, 17 June 2012

 
 
 
Floating-point environment
Functions
feraiseexcept
(C++11)
(C++11)(C++11)
(C++11)(C++11)
Macro constants
(C++11)
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <cfenv>
</td>

<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

#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

See also

Template:cpp/numeric/fenv/dcl list feclearexceptTemplate:cpp/numeric/fenv/dcl list fetestexcept