gpt4 book ai didi

gcc - GCC 的 __builtin_isnan 是否做了 isnan 以外的事情?

转载 作者:行者123 更新时间:2023-12-04 07:27:01 28 4
gpt4 key购买 nike

GCC built-ins description , 它说:

GCC provides built-in versions of the ISO C99 floating-point comparison macros that avoid raising exceptions for unordered operands. They have the same names as the standard macros ( isgreater, isgreaterequal, isless, islessequal, islessgreater, and isunordered) , with _builtin prefixed. We intend for a library implementor to be able to simply #define each standard macro to its built-in equivalent. In the same fashion, GCC provides fpclassify, isfinite, isinf_sign, isnormal and signbit built-ins used with _builtin prefixed. The isinf and isnan built-in functions appear both with and without the _builtin prefix.


所以,我不太能解析这个。浮点比较什么时候应该引发异常? C标准是否要求他们这样做?授权他们不?什么都不强制?并且 - 做 __builtin_isnan()行为不同于 isnan() ?

最佳答案

此处异常(exception),GCC 文档引用 IEEE 754 floating point exceptions .如果你做类似的事情

a < b
并且操作数之一是 NaN,将引发 FP 异常(无效)。这意味着 FPU 中的某个位将保持设置状态,直到它被程序员明确清除。改为使用 isgreater/ isless/等等。程序员可以避免触发FP异常。

关于gcc - GCC 的 __builtin_isnan 是否做了 isnan 以外的事情?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68163793/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com