help-octave
[Top][All Lists]

## RE: Comparing of values

 From: Hall, Benjamin Subject: RE: Comparing of values Date: Fri, 22 Oct 2004 09:59:32 -0400

```Searching for exact matches to floating point numbers can be troublesome
just due to the nature of floating point numbers in computers
(unfortunately, I can't really give a better answer than that!).  For
instance

>> 3*0.05 - 0.15

ans =

2.7756e-017

One work-around is the following:

beta = 0.05:0.05:0.95;

beta( beta == 3*0.05 )

or

beta( abs( beta - 0.15 ) < 0.00000001 )

Hope that helps

-----Original Message-----
From: Jakub Selesovsky [mailto:address@hidden
Sent: Friday, October 22, 2004 9:40 AM
Subject: Comparing of values

Hello,

I have a problem with searching of values in vector. What is wrong in
following sequence of commands? I mean why Octave (2.1.50, Linux, compiled
from source) return some values when searching beta==0.05, and return zero

vector when searching beta==0.15. Both of these values are included in
vector beta. Thank you for each answer.

Jakub Selesovsky

octave:10> beta = rot90(0.05:0.05:0.95,-1)
beta =

0.050000
0.100000
0.150000
0.200000
0.250000
0.300000
0.350000
0.400000
0.450000
0.500000
0.550000
0.600000
0.650000
0.700000
0.750000
0.800000
0.850000
0.900000
0.950000

octave:11> beta = [beta; beta; beta; beta; beta]
octave:12> beta(beta==0.15)
ans = [](0x1)
octave:13> beta(beta==0.05)
ans =

0.050000
0.050000
0.050000
0.050000
0.050000

octave:14>

--
Jakub Selesovsky
--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```

reply via email to