Please note that the recommended version of Scilab is 2023.1.0. This page might be outdated.
See the recommended documentation of this function
comparison
comparison, relational operators
Syntax
a==b a~=b or a<>b a<b a<=b a>b a>=b
Arguments
 a
any type of variable for
a==b
,a~=b
a<>b
equality comparisons and restricted to real floating point and integer array for order related comparisonsa<b
,a<=b
,a>b
,a>=b
. b
any type of variable for
a==b
,a~=b
a<>b
equality comparisons and restricted to real floating point and integer arrays for order related comparisonsa<b
,a<=b
,a>b
,a>=b
.
Description
Two classes of operators have to be distinguished:
 The equality and inequality comparisons:
a==b
,a~=b
(or equivalentlya<>b
). These operators apply to any type of operands. The order related comparisons:
a<b
,a<=b
,a>b
,a>=b
. These operators apply only to integer and real numbers.
The result of the comparison operators also depends on the operands types:
 With array variables
arrays of numbers, boolean arrays, string arrays, polynomial and rational arrays, handle arrays, lists... the following rules apply:
If
a
andb
are arrays with same types and sizes, the comparison is performed element by element and the result is an array of booleans of the same sizes.If
a
andb
have the same type anda
orb
is a scalar, then the scalar is compared with each element of the other array. The result is an array of booleans of the size of the non scalar operand.If
a
orb
is an array while the other one is empty, then the result is a scalar boolean.In all other cases, the result is
%F
If the operand data types are different but "compatible" like decimal numbers and encoded integers, then a type conversion is performed before the comparison.
 With other type of operands
like
function
,libraries
, the result is%t
if the objects are identical and%f
in the other cases.Equality comparison between operands of incompatible data types returns
%f
.

Examples
//element wise comparisons (1:5)==3 (1:5)<=4 (1:5)<=[1 4 2 3 0] 1<[] list(1,2,3)~=list(1,3,3) "foo"=="bar" sparse([1,2;4,5;3,10],[1,2,3]) == sparse([1,2;4,5;3,10],[1,2,3]) //object wise comparisons (1:10)==[4,3] 'foo'==3 1==[] list(1,2,3)==1 isequal(list(1,2,3),1) isequal(1:10,1)
Comparisons with implicit conversion of type or encoding:
int32(1) == 1 int32(1) < 1.5 int32(1:5) < int8(3) 1 == complex(1,0) 1 > complex(1,0) // still OK, but.. 1 > complex(1,1) // => error: complex numbers not orderable
> int32(1) == 1 ans = T > int32(1) < 1.5 ans = T > int32(1:5) < int8(3) ans = T T F F F > 1 == complex(1,0) ans = T > 1 > complex(1,0) // still OK, but.. ans = F > 1 > complex(1,1) // => error: complex numbers not orderable at line 11 of function %s_2_s ( SCI\modules\overloading\macros\%s_2_s.sci line 23 ) Complex comparison not supported. Please define %s_2_s_custom() or check your code.
Comparisons with polynomials and rationals:
p = 0*%s p == 0 r = p/(1+0*%s) r == 0 r == p ps = (1%s)^2, pz = (1%z)^2 ps == pz // => %F : same variable required
> p = 0*%s p = 0 > p == 0 ans = T > r = p/(1+0*%s) r = 0  1 > r == 0 ans = T > r == p ans = T > ps = (1%s)^2, pz = (1%z)^2 ps = 2 1 2s +s pz = 2 1 2z +z > ps == pz // => %F : same variable required ans = F
Comparisons with a sparse numerical matrix: All elementwise comparisons yield
a sparseencoded result, %F
otherwise.
sp = sparse([0 1 0 0 2 0 4 0 0]) sp < 0 sp == 1 sp >= [2 3 1 2 4 0 3 1 0] sp == %i sp == list(3) // => %F
> sp = sparse([0 1 0 0 2 0 4 0 0]) sp = ( 1, 9) sparse matrix ( 1, 2) 1. ( 1, 5) 2. ( 1, 7) 4. > sp < 0 ans = ( 1, 9) sparse matrix ( 1, 5) T > sp == 1 ans = ( 1, 9) sparse matrix ( 1, 2) T > sp >= [2 3 1 2 4 0 3 1 0] ans = ( 1, 9) sparse matrix ( 1, 3) T ( 1, 5) T ( 1, 6) T ( 1, 7) T ( 1, 9) T > sp == %i ans = ( 1, 9)False sparse matrix > sp == list(3) // object comparison => dense %F ans = F
Comparisons between graphics identifiers:
plot2d() e1 = gce(); e2 = e1; // e1 and e2 point to the same graphical object e2.tag e1.tag = "3 curves"; e1 == e2 e2.tag
> e2.tag ans = > e1.tag = "3 curves"; > e1 == e2 ans = T > e2.tag ans = 3 curves
Comparisons between functions aliases are possible:
> sine = sin ; > sine == sin ans = T > sinus = sind ; > sinus == sind ans = T > sinus(0:90:360) ans = 0. 1. 0. 1. 0.
See also
History
Version  Description 
6.0 

Report an issue  
<< comments  Scilab keywords  dollar >> 