Recently I got into a discussion about floating point comparison. My point of view was always to not compare two floating point numbers using ==
directly.
It was pointed out that this is not true and there are cases where using ==
is perfectly fine.
I can think of typical cases, where I check against IEEE 754 literals, as +-INF
or +-0
, but apart from that, I cannot think of a case where this wouldn’t lead to problems.
So my question is: What are the cases when a floating point comparison using ==
is valid?