• C++ Reference: Standard C++ Library reference: C Library: cfenv: feraiseexcept


    C++官方参考链接:https://cplusplus.com/reference/cfenv/feraiseexcept/

    函数 

    feraiseexcept
    int feraiseexcept (int excepts);

    引发浮点异常
    尝试引发excepts指定的浮点异常。 
    如果指定了多个异常,则不指定引发异常的顺序。
    调用此函数的程序应确保为调用启用pragma FENV_ACCESS

    形参
    excepts
    位掩码值:实现支持的任意数量的浮点异常值的组合(带有按位或:|):

    macro value(宏值)description(描述)
    FE_DIVBYZEROPole error: division by zero, or some other asymptotically infinite result (from finite arguments).(极点错误:除以零,或其他渐进无限大的结果(来自有限的实参)。)
    FE_INEXACTInexact: the result is not exact.(不精确:结果不精确。)
    FE_INVALIDDomain error: At least one of the arguments is a value for which the function is not defined.(定义域错误:至少有一个实参是函数没有定义的值。)
    FE_OVERFLOWOverflow range error: The result is too large in magnitude to be represented as a value of the return type.(上溢范围错误:结果的绝对大小太大,不能用返回类型的值表示。)
    FE_UNDERFLOWUnderflow range error: The result is too small in magnitude to be represented as a value of the return type.(下溢范围错误:结果的绝对大小太小,不能用返回类型的值表示。)
    FE_ALL_EXCEPTAll exceptions (selects all of the exceptions supported by the implementation).(所有异常(选择实现支持的所有异常)。)

    某些库实现可能支持额外的浮点异常值(其对应的宏也以FE_开头)。
    C99
    库可以在中只定义它们支持的以上宏值(其他的可能没有定义)。
    C++11
    至少上述所有宏值都在中定义(即使实现不支持)。

    返回值
    如果excepts中的所有异常都被成功引发,则为0(或者excepts为0)。否则为非0值。

    用例
    /* feraiseexcept example */
    #include      /* printf */
    #include       /* feraiseexcept, fetestexcept, FE_ALL_EXCEPT, FE_INVALID */
    #pragma STDC FENV_ACCESS on

    double fn (double x) {  /* some function for which zero is a domain error */
      if (x==0.0) feraiseexcept(FE_INVALID);
      return x;
    }

    int main ()
    {
      feclearexcept (FE_ALL_EXCEPT);
      fn (0.0);
      if (fetestexcept(FE_INVALID)) printf ("FE_INVALID raised\n");
      return 0;
    }
    可能的输出:

    数据竞争
    每个线程都维护一个具有自己状态的独立浮点环境。生成一个新线程会复制当前状态。【这适用于C11和C++11实现】

    异常
    无抛出保证:此函数从不抛出异常。
    注意,C浮点异常不是C++异常,因此不会被try/catch块捕获。 

  • 相关阅读:
    Java进阶-----反射
    5G相关信息
    C语言中宏定义的盲区有哪些?
    模拟量偏差报警功能块(SCL代码)
    linux CentOS7 安装git 配置秘钥公钥克隆代码
    面向对象的三大特性、方法重写、super关键字以及装箱拆箱(JAVA基础四)
    kali部署dvwa靶场
    MLOps的演进历程
    leaflet教程039: 只显示一屏地图,设定范围不让循环延展
    synchronized 关键字背后的锁升级流程
  • 原文地址:https://blog.csdn.net/weixin_40186813/article/details/126954499