octave-maintainers
[Top][All Lists]
Advanced

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

Re: Why a separate isequal?


From: Richard Crozier
Subject: Re: Why a separate isequal?
Date: Mon, 10 Mar 2014 08:56:01 +0000
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:16.0) Gecko/20121010 Thunderbird/16.0.1

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.



reply via email to

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