什么时候float变量不等于其自身 [英] When is a float variable not equal to itself
本文介绍了什么时候float变量不等于其自身的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在编程测试中有人问我这个问题.问题是,我以浮点数作为参数传递,并询问以下代码何时为假.
I was asked this questino on a programming test. The question was, I was passed in a float as a parameter, and asked when would the following code be false.
bool result = (floatValue == floatValue);
我想不出一个正当的理由或什么时候会是假的而仍然不会的情况.最后,我回答说永远不会出现错误的情况.想知道是否有人可以给我一些例子,什么时候这是错误的
I couldn't think of a valid reason or a situation of when this would be false and still can't. In the end, I answered that there will never be a case when this would be false. Was wondering if anyone can give me some example(s) of when this would be false
推荐答案
floatValue == NaN
floatValue == NaN
如果floatValue是非数字的计算结果,例如0/0.
If floatValue is the result of a computation that is Not a Number, like 0/0.
这篇关于什么时候float变量不等于其自身的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文