如何产生NaN的浮在C? [英] How to produce a NaN float in c?

查看:232
本文介绍了如何产生NaN的浮在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆