Double.IsNaN(double d)的作用是什么? [英] What is the purpose of Double.IsNaN(double d)?

查看:63
本文介绍了Double.IsNaN(double d)的作用是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在.Net中,类型 Double 具有静态方法 IsNan(),该方法接受一个参数,即 double ,并返回一个布尔.

In .Net the type Double has a static method IsNan() which accepts one parameter, a double and returns a bool.

当然,这意味着该方法将始终返回true,因为它只能接受一个double?有人可以解释此方法的重点,以及何时可能返回false吗?纯粹是好奇的,想受教育.

Surely, this means that the method will always return true as it can only accept a double? Can someone explain the point of this method and when it might return false? Purely curious and wanting to be educated.

编辑:我很抱歉回答一个很差的问题.没关系,我应该阅读该文档.而且,是的,我的意思是该方法将始终返回false".

My apologies for a very poorly asked question. You are all right, I should have read the documentation. And, yes I did mean "the method will always return false".

推荐答案

double float 具有"Not A Number"值,用于表示误差量.NaN具有不幸的性质,它总是将false与包括自身在内的所有事物进行比较.因此,您调用一种特殊的方法来告诉您给定的double是否为NaN.(由于NaN是具有唯一性的 值,因此您也可以通过将其与自身进行比较来判断其是否为NaN!但是 x!= x 在代码中看起来很奇怪;简单地调用 IsNaN(x)更为习惯.)

double and float have "Not A Number" values that they use to represent error quantities. A NaN has the unfortunate property that it always compares false to everything, including itself. Thus you call a special method to tell you if a given double is a NaN. (Since NaNs are the only values that have the property that they do not equal themselves, you can also tell if a value is a NaN by comparing it to itself! But x != x looks weird in the code; it is much more idiomatic to simply call IsNaN(x).)

关于文档的某些内容不清楚吗,以至于提示您在这里提出问题?如果您可以解释不清楚的地方,我可以将该反馈传递给文档管理器.

Is there something about the documentation that was so unclear that it prompted you to ask a question here? If you can explain what you found unclear I can pass that feedback on to the documentation manager.

这篇关于Double.IsNaN(double d)的作用是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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