如何产生NaN的浮在C? [英] How to produce a NaN float in c?
问题描述
float f = (float)'a';
if(f < 0){
}
else if(f == 0){
}
else if(f > 0){
}
else{
printf("NaN\n");
}
˚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
:
#include <stdio.h>
int main()
{
float x = 0.0 / 0.0;
printf("%f\n", x);
return 0;
}
在计算什么 NaN的
看起来像电脑,两个无效的数字保留为信号和安静南(类似于保留两个无效号码用于正和负无穷大)。该维基百科条目拥有约NaN被再怎么psented作为IEE浮点数$ P $的更多细节。
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.
这篇关于如何产生NaN的浮在C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!