Comparison between float point numbers

57 Views Asked by At

How can I demostrate that given two numbers A and B, if A <= B, then fl(A) <= fl(B). fl(A) is the float point representation of A. Which is equal to A(1+x), and |x| <= the machine epsilon (eps). The same goes for fl(b).

I've tried a lot of things so far: if I consider that both representations will have the same maximum error (1+epsilon) it's easy:

fl(A) <= fl(B)

A(1+eps) <= B(1+eps)

A<=B, which is true

But, if I consider the worst case scenario, in which the error for A is positive eps, and the error for B is negative eps.

A(1+eps) <= B(1-eps)

Then it's more complicated. I've been playing around with this for a while, and I can't get to any conclusions. I'd be very glad if someone could point me to the right direction.

Thanks in advance.

1

There are 1 best solutions below

1
On BEST ANSWER

There are only finitely many float numbers. I assume that $\operatorname{fl}(A)$ is one of the up to two float numbers closest to $A$. For $A,B\in\mathbb R$, we have $$ \left|\operatorname{fl}(A)-A\right|\le \left|\operatorname{fl}(B)-A\right|\qquad \left|\operatorname{fl}(B)-B\right|\le \left|\operatorname{fl}(A)-B\right|$$ Now if $\operatorname{fl}(A)>\operatorname{fl}(B)$ this implies $$ A\ge\frac{\operatorname{fl}(A)+\operatorname{fl}(B)}{2}\qquad B\le\frac{\operatorname{fl}(A)+\operatorname{fl}(B)}{2}$$ and hence $A\ge B$.