I have two floating points, x, y
. They are "supposed to be" the same, but with floating-point, you never know, so x == y
may return False
.
So I am looking for an operation O()
which ensures that if x
and y
really are "supposed to be the same" (where that supposedness is indicated by a tolerance), then O(x) == O(y)
. I am NOT looking to just compare if abs(x - y) <= tol
, that is of course easily done, but it is not what I want, I want two representations O(x), O(y)
that I need to later use.
Is there such an operation?
I first thought about rounding as an obvious solution, but it doesn't actually work. For example, x = 1, y = 0.999999999999
are "clearly supposed to be the same", but with rounding x = 1, y = 0.999999
, and so that operation clearly does not satisfy O(x) == O(y)
.