f 不会大于/等于/小于 0 如果它是 NaN.
f won't be greater/equal/less than 0 if it's a NaN.
但是首先如何产生这样的f呢?
But how to produce such a f in the first place?
我尝试了各种方法来生成 NaN,但都没有奏效..
I tried various ways to produce a NaN,but none work..
推荐答案使用浮点数,0.0/0.0 不是除以零"错误;结果是 NaN.
Using floating point numbers, 0.0 / 0.0 isn't a "divide by zero" error; it results in NaN.
这个 C 程序打印 -nan:
This C program prints -nan:
#include <stdio.h> int main() { float x = 0.0 / 0.0; printf("%f ", x); return 0; }就 NaN 对计算机的外观而言,两个无效"数字为信号"和安静"NaN 保留(类似于为正无穷和负无穷保留的两个无效数字).维基百科条目 有更多关于 NaN 如何表示为 IEE 浮点数的详细信息.
In terms what NaN looks like to the computer, two "invalid" numbers are reserved for "signaling" and "quiet" NaN (similar to the two invalid numbers reserved for positive and negative infinity). The Wikipedia entry has more details about how NaN is represented as an IEE floating point number.
更多推荐
如何在 c 中产生 NaN 浮点数?
发布评论