help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: puzzling Octave behaviour


From: Francesco Potorti`
Subject: Re: puzzling Octave behaviour
Date: Mon, 24 Jul 2006 10:34:58 +0200

>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

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
Web: http://fly.isti.cnr.it/           Key:   fly.isti.cnr.it/public.key


reply via email to

[Prev in Thread] Current Thread [Next in Thread]