Re: comparing numbers using WHERE doesn't work [message #25241] |
Sat, 02 June 2001 15:19 |
Ken Mankoff
Messages: 158 Registered: February 2000
|
Senior Member |
|
|
On Sat, 2 Jun 2001, Miklos Z. Kiss wrote:
> Hi folks:
> I have noticed a strange occurence when I try to compare a number with
> all the elements of an array. I'll show my situation in an example.
> Consider the following array:
> [snip]
> index0 = WHERE(a EQ x)
> index0 = index[0] ; convert from 1-D array to single integer.
> index1 = WHERE(a EQ y)
> index1 = index[0]
I'm not sure why this is happening to you. It works correctly on my
machine. But you can simplify your WHERE query and subsequent
array-to-integer like this:
index0 = ( WHERE(a EQ x) )[0]
-k.
--
Ken Mankoff
LASP://303.492.3264
http://lasp.colorado.edu/~mankoff/
|
|
|
Re: comparing numbers using WHERE doesn't work [message #25242 is a reply to message #25241] |
Sat, 02 June 2001 14:10  |
Paul Woodford
Messages: 43 Registered: June 2000
|
Member |
|
|
In article <9fbduu$ojm$1@uni00nw.unity.ncsu.edu>,
"Miklos Z. Kiss" <mzkiss@unity.ncsu.edu> wrote:
> I have noticed a strange occurence when I try to compare a number with
> all the elements of an array. I'll show my situation in an example.
> Consider the following array:
> a = [2.0000, 2.1000, 2.2000, 2.3000, 2.4000, 2.5000, 2.6000].
> Let, x = 2.2000, y = 2.4000
> So, I want to find which elements of a match up with x and y.
> Naturally, I do the following:
>
> index0 = WHERE(a EQ x)
I don't know if this is the problem, but using EQ to compare floating
point numbers is generally not a good idea. A better way to compare
would be WHERE(abs(a-x) LT 2*epsilon), where epsilon is the floating
point precision returned by machar().
Paul
|
|
|