C / C ++ NaN常数(literal)? [英] C/C++ NaN constant (literal)?

查看:165
本文介绍了C / C ++ NaN常数(literal)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能会将 NaN 指派给 double float 在C / C ++?像在JavaScript你做: a = NaN

Is this possible to assign a NaN to a double or float in C/C++? Like in JavaScript you do: a = NaN. So later you can check if the variable is a number or no.

推荐答案

在C中, NAN < math.h> 中声明。

$ c> std :: numeric_limits< double> :: quiet_NaN()声明在< limits>

In C++, std::numeric_limits<double>::quiet_NaN() is declared in <limits>.

但是,为了检查一个值是否为NaN,你不能将它与另一个NaN值进行比较。而是使用C中的 isnan();或者C中的< math.h> :isnan()来自C ++中的< cmath>

But for checking whether a value is NaN, you can't compare it with another NaN value. Instead use isnan() from <math.h> in C, or std::isnan() from <cmath> in C++.

这篇关于C / C ++ NaN常数(literal)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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