How reliable is comparing Doubles? Should I create a safe compare function with some small wiggle room?
like
fun Double.equals(b: Double): Boolean = abs(this - b) < 1e-20
?
s
spand
05/02/2019, 7:23 AM
I would expect it to be a bitwise equality. Any error tolerance seems would be quite domain specific imo
k
karelpeeters
05/02/2019, 7:38 AM
It's reliable, but of course the operations aren't, eg they're not commutative/associative/... and so when you're unit testing there are usually functions like that that take a precision parameter