When is a float variable not equal to itself

空扰寡人 提交于 2021-02-07 14:36:29

问题


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


回答1:


floatValue == NaN

If floatValue is the result of a computation that is Not a Number, like 0/0.



来源:https://stackoverflow.com/questions/32900284/when-is-a-float-variable-not-equal-to-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!