Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is a float variable not equal to itself

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

like image 911
dwnenr Avatar asked Oct 02 '15 03:10

dwnenr


1 Answers

floatValue == NaN

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

like image 192
1201ProgramAlarm Avatar answered Oct 10 '22 15:10

1201ProgramAlarm