我使用 ANSI C89(不是 C++),我想生成 NaN
、-Infinity
和 +Infinity
。
有没有标准的方法(例如标准宏)? 或者是否有任何独立于平台和编译器的方法来生成这些数字?
float f = 0.0 / 0.0; // Is f ALWAYS in any platform is NaN?
最佳答案
在 C99 中有,但在以前的标准 AFAIK 中没有。
在 C99 中,您将拥有 NAN
和 INFINITY
宏。
来自“数学<math.h>
”(§7.12)部分
The macro INFINITY expands to a constant expression of type float representing positive or unsigned infinity, if available; ...
如果您受困于 ANSI C89,那您就倒霉了。参见 C-FAQ 14.9 .
关于c - 如何在 ANSI C 中生成 NaN、-Infinity 和 +Infinity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6235847/