Suppose I have two floating point numbers, x
and y
, with their values being very close.
There's a discrete number of floating point numbers representable on a computer, so we can enumerate them in increasing order: f_1, f_2, f_3, ...
. I wish to find the distance of x
and y
in this list (i.e. are they 1, 2, 3, ... or n
discrete steps apart?)
Is it possible to do this by only using arithmetic operations (+-*/
), and not looking at the binary representation? I'm primarily interested in how this works on x86.
Is the following approximation correct, assuming that y > x
and that x
and y
are only a few steps (say, < 100) apart? (Probably not ...)
(y-x) / x / eps
Here eps
denotes the machine epsilon. (The machine epsilon is the difference between 1.0 and the next smallest floating point number.)