help-octave
[Top][All Lists]

checking for tiny inequalities (was: Re: puzzling Octave behaviour)

 From: Joan Picanyol i Puig Subject: checking for tiny inequalities (was: Re: puzzling Octave behaviour) Date: Mon, 24 Jul 2006 12:54:11 +0200 User-agent: Mutt/1.5.11

```* Francesco Potorti` <address@hidden> [20060724 10:37]:
> >The real problem is that testing doubles for equality doesn't
> >work very well. It doesn't have anything to do with Octave, it's
> >just a property of the floating point representation that
> >computers use. You need to test to see if the numbers are close,
> >within some tolerance, like (a - b) < 1e-10, instead of a == b.
>
> You example is wrong, because it should use abs().
>
> Moreover, it assumes that you know the range of values of a and b.  For
> example, it gives wrong results if a and b are in the order of 1e-10.  A
> better test would be something like
>
>  abs(a-b) < 10*abs(a)*eps

I need some clarification on the significance and use of eps. According
to octave,

`eps' is the largest relative spacing between any two adjacent numbers in
the machine's floating point system

Which I understand as "any number smaller than eps is undistinguishable
from 0". However, AFAIK, 64-bit double precision floating point permits
representing something as small as 10^-323 or so, and although I've done
comparisons to some multiple of eps as a threshold to check for 0s,
I'm unsure on how would that work if I really needed to work with values
around 10^-20.

BTW: I found the following a great paper while trying to understand all
of this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html

tks
--
pica

```