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

Floating-point environment

浮点环境是实现所支持的浮点状态标志和控制模式的集合。它是线程本地的,每个线程从父线程继承其浮点环境的初始状态。浮点操作修改浮点状态标志以指示异常结果或辅助信息.。浮点控制模式的状态影响着一些浮点操作的结果.

浮点环境的访问和修改只有在以下情况下才有意义:#pragma STDC FENV_ACCESS被支持,并设置为ON否则,实现可以自由地假设浮点控制模式始终是默认模式,并且浮点状态标志从未被测试或修改。在实践中,很少有当前的编译器(如HP ACC、Oracle Studio或IBMXL)支持#pragma但是大多数编译器都允许有意义地访问浮点环境.

类型

在标头中定义<cfenv>

*。

芬夫[医]t表示整个浮点环境的类型。

福斯特[医]t表示所有浮点状态标志的类型。

功能

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)

feraiseexcept (C++11)

raises the specified floating-point exceptions (function)

fegetexceptflagfesetexceptflag (C++11)(C++11)

copies the state of the specified floating-point status flags from or to the floating-point environment (function)

fegetroundfesetround (C++11)(C++11)

gets or sets rounding direction (function)

fegetenvfesetenv (C++11)

saves or restores the current floating point environment (function)

feholdexcept (C++11)

saves the environment, clears all status flags and ignores all future errors (function)

feupdateenv (C++11)

restores the floating-point environment and raises the previously raise exceptions (function)

FE_ALL_EXCEPTFE_DIVBYZEROFE_INEXACTFE_INVALIDFE_OVERFLOWFE_UNDERFLOW (C++11)

floating-point exceptions (macro constant)

FE_DOWNWARDFE_TONEARESTFE_TOWARDZEROFE_UPWARD (C++11)

floating-point rounding direction (macro constant)

FE_DFL_ENV (C++11)

default floating-point environment (macro constant)

注记

浮点异常与C++异常无关.。当浮点操作引发浮点异常时,浮点环境的状态会发生变化,可以用std::fetestexcept,但是在大多数实现中,C++程序的执行仍然不间断。

当出现浮点异常时,可以使用编译器扩展自动生成C++异常:

  • GNU libc函数feenableexcept()启用浮点异常的捕获,这将生成信号。SIGFPE.如果编译器选项-fnon-call-exceptions使用时,该信号的处理程序可能会引发用户定义的C++异常。

另见

c浮点环境的文档

*。

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

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

扫码关注腾讯云开发者

领取腾讯云代金券