首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::feraiseexcept

Defined in header <cfenv>

?

?

int feraiseexcept( int excepts );

?

(since C++11)

中列出的所有浮点异常的引发尝试。excepts%28a按位或浮点异常宏29%。如果其中一个例外是FE_OVERFLOWFE_UNDERFLOW,此功能可能会增加FE_INEXACT.提出例外情况的先后次序未予指明,但FE_OVERFLOWFE_UNDERFLOW总是在FE_INEXACT...

参数

excepts

-

bitmask listing the exception flags to raise

返回值

?0?如果引发所有列出的异常,则为非零值。

二次

代码语言:javascript
复制
#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";
    }
}

二次

产出:

二次

代码语言:javascript
复制
Raising divbyzero and underflow simultaneously succeeds and results in
division by zero
underflow

二次

另见

feclearexcept (C++11)

clears the specified floating-point status flags (function)

fetestexcept (C++11)

determines which of the specified floating-point status flags are set (function)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com