I'd like to check if a double
is smaller, equal to, or bigger than another double
. Even though I read a lot about floats
and doubles
not being precisely comparable because of how the computer calculates at a binary level, using the simple binary operators works like a charm so far. I tested it with dozens of different numbers and it hasn't failed me even once so far.
So is there really a problem comparing them like that in my case? And if there is - why can't I locate it and how to fix it?
EDIT: I'm aware that 0.1 + 0.2 != 0.3
if I decide to compare them. The thing is - I want to simply compare two fixed doubles
. I won't have to compare 0.1 + 0.2
and 0.3
. I'd have to compare 0.3
and 0.3
at best. Or 0.4
and 0.3
. Something like that. Do I really need to use BigDecimal, or epsilon, or whatever for that?