Why a separate isequal?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Why a separate isequal?

David Spies
I noticed that:

octave:1> isequal(1,2)
ans =  1

I'm guessing this is a bug.  Nonetheless, why is there even a separate isequal function?  Why can't it just be defined as

function [res] = isequal(a,b)
  res = (a == b)
endfunction

Are there types for which it's meant to differ from ==?  Is this supposed to be used for some sort of test?
Reply | Threaded
Open this post in threaded view
|

Re: Why a separate isequal?

Daniel Sebald
On 03/09/2014 10:03 PM, David Spies wrote:

> I noticed that:
>
> octave:1> isequal(1,2)
> ans =  1
>
> I'm guessing this is a bug.  Nonetheless, why is there even a separate
> isequal function?  Why can't it just be defined as
>
> function [res] = isequal(a,b)
>    res = (a == b)
> endfunction
>
> Are there types for which it's meant to differ from ==?  Is this
> supposed to be used for some sort of test?

According to the documentation, isequal accepts a general tuple:

>> isequal(5,5,5)
ans =  1
>> 5 == 5 == 5
ans = 0

Why it is failing on your system is a good question.  Seems like a basic
function that shouldn't have changed much.

What does

>> test isequal
PASSES 23 out of 23 tests

produce for you?

Dan
Reply | Threaded
Open this post in threaded view
|

Re: Why a separate isequal?

Richard Crozier
In reply to this post by David Spies
On 10/03/2014 03:03, David Spies wrote:

> I noticed that:
>
> octave:1> isequal(1,2)
> ans =  1
>
> I'm guessing this is a bug.  Nonetheless, why is there even a separate
> isequal function?  Why can't it just be defined as
>
> function [res] = isequal(a,b)
>    res = (a == b)
> endfunction
>
> Are there types for which it's meant to differ from ==?  Is this
> supposed to be used for some sort of test?


a == b would return the elementwise logical matrix of comparisons

isequal always returns a single boolean, only if every value in the
matrix is the same, so more like:

res = all((a == b)(:))

i.e.

 >> a = [1 2 ; 3 4], b = [1 1; 1 1], a == b
a =

    1   2
    3   4

b =

    1   1
    1   1

ans =

    1   0
    0   0

 >> isequal (a,b)
ans = 0


but as also pointed out by another, isequal also takes any number of
arguments.

Your example should definitely return true however, and does so on the
development version at least for me on Mint Linux 16:

 >> isequal (1,2)
ans = 0

Richard


--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.