octave-maintainers
[Top][All Lists]
Advanced

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

Re: Comparison with NaN


From: Michael Goffioul
Subject: Re: Comparison with NaN
Date: Thu, 14 May 2009 19:26:22 +0100

On Thu, May 14, 2009 at 11:58 AM, Jaroslav Hajek <address@hidden> wrote:
>>> It is indeed a problem, because the sort is supposed to be stable.
>>> Unfortunately, I can't reproduce it.
>>> can you run the infringing "sort" statement and verify that v(2) == v(6)?
>>
>> I'm not I'm following...
>> As the test result shows, the second "assert" fails, meaning that
>> the first one succeeded, so v = [1, 1i, 1i, -1, Inf, NaN]. Of course
>> v(2) != v(6). However, in the original unsorted array, elements 2 and 6
>> are the same.
>
> Yes, sorry. I said it wrong, but you understood correctly.
>
>>> what does
>>> [v,i] = sort([NaN, 2, 3, Inf, 1, 2])
>>> return?

octave:2> x = [NaN, 1i, -1, Inf, 1, 1i]
x =

   NaN +   0i     0 +   1i    -1 +   0i   Inf +   0i     1 +   0i     0 +   1i

octave:3> [v,i] = sort(x)
v =

     1 +   0i     0 +   1i     0 +   1i    -1 +   0i   Inf +   0i   NaN +   0i

i =

   5   6   2   3   4   1

octave:4> x(2) == x(6)
ans =  1
octave:5> [v,i] = sort([NaN, 2, 3, Inf, 1, 2])
v =

     1     2     2     3   Inf   NaN

i =

   5   2   6   3   4   1


reply via email to

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