5

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

dwnenr
  • 443
  • 1
  • 4
  • 15

1 Answers1

12

floatValue == NaN

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

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
  • OH. I was totally forgetting NaN. Does this also apply if floatValue is INF? Or is this just for when floatValue is NaN? – dwnenr Oct 02 '15 at 03:55
  • Only for NaNs. Infinities compare normally (-infinity < any real number < +infinity; +infinity == +infinity; etc.). – 1201ProgramAlarm Oct 02 '15 at 04:35