help-octave
[Top][All Lists]
Advanced

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

Re: find command sometimes doesn't work in script


From: Jaroslav Hajek
Subject: Re: find command sometimes doesn't work in script
Date: Thu, 12 Nov 2009 11:29:03 +0100



On Thu, Nov 12, 2009 at 11:10 AM, Lidia Bressan <address@hidden> wrote:
Sure, here I write all the information I was missing in the last email.

I use GNU Octave, version 3.2.2. I'm not sure what you mean with octave
configuration.

Any result:

octave:105> any ((1:0.05:5) == 2.05)
ans = 0


There you go. As you can see, something is wrong. I suppose the simpler equality
 1 + 21 * 0.05 == 2.05
does not hold for you either (am I right)?
This is because numbers like 0.05 do not have an exact representation in the FP arithmetics. When you say 0.05, Octave actually picks the closest floating-point number, which is 3602879701896397 * 2^-56. Then, when it calculates 1 + 21 * 0.05 (and it does so even in the for loop), it uses this number, and the result is a tiny bit off.
 
Is there a way to go around a precision issue?

Use an integer range, or don't compare for strict equality but rather with a tolerance.
There is also an extension package for Octave providing fixed point numbers:
http://octave.sourceforge.net/fixed/index.html

hth

--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

reply via email to

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