std::feraiseexcept(3)
πΈ NAME πΈ
okay so bestie, welcome to std::feraiseexcept(3) from the C++ Standard Libary manual β¨ (yes, the header spells it "Libary" β we're keeping that, no cap). This page is literally about std::feraiseexcept β the function whose whole job is raising floating-point exceptions, and she does it with main character energy π
.
β¨ Synopsis β¨
Defined in header <cfenv>
int feraiseexcept( int excepts ); (since C++11)
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.
lowkey important: the order is unspecified, butFE_OVERFLOWandFE_UNDERFLOWare always raised beforeFE_INEXACT. That part is not up for debate, periodt.
π Parameters π
exceptsβ bitmask listing the exception flags to raise.
π Return value π
0 if all listed exceptions were raised, non-zero value otherwise.
So: if every listed exception got raised, you get 0 β slay. If not, you get a non-zero value β not slay, but useful π.
π§ Example π§
// Run this code
#include <cfenv>
#include <iostream>
// #pragma STDC FENV_ACCESS ON
int main()
{
std::feclearexcept(FE_ALL_EXCEPT);
const int r = std::feraiseexcept(FE_UNDERFLOW | FE_DIVBYZERO);
std::cout << "Raising divbyzero and underflow simultaneously "
<< (r ? "fails" : "succeeds") << " and results in\n";
const 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 π₯
feclearexceptβ clears the specified floating-point status flags(C++11)(function).fetestexceptβ determines which of the specified floating-point status flags are set(C++11)(function).- C documentation for
feraiseexcept.
catch you later bestie π this page came from http://cppreference.com, version/date 2024.06.10 β mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms