Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
5.3.2 - Français

Change language to:
English - 日本語 - Português

Please note that the recommended version of Scilab is 2024.0.0. This page might be outdated.
See the recommended documentation of this function

Aide Scilab >> Scilab > Mots clés Scilab > comparison

comparison

comparison, relational operators

Calling Sequence

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 comparisons a<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 comparisons a<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 equivalently a<>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 real floating point and integer arrays.

The semantics of the comparison operators also depend on the operands types:

With array variables

like floating point and integer arrays, logical arrays, string arrays, polynomial and rationnal arrays, handle arrays, lists... the following rules apply:

  • If a and b evaluates as arrays with same types and identical dimensions, the comparison is performed element by element and the result is an array of booleans of the same.

  • If a and b evaluates as arrays with same types, but a or b is a 1 by 1 array 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.

  • In the others cases the result is the boolean %f

  • If the operand data types are differents but "compatible" like floating points and integers 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)

//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)

//comparison with type conversion
int32(1)==1
int32(1)<1.5
int32(1:5)<int8(3)
p=poly(0,'s','c')
p==0
p/poly(1,'s','c')==0

See Also

  • less — (<) lower than comparison
  • boolean — Objets Scilab, variables booléennes et opérateurs & | ~
  • isequal — objects comparison
<< while Mots clés Scilab equal >>

Copyright (c) 2022-2023 (Dassault Systèmes)
Copyright (c) 2017-2022 (ESI Group)
Copyright (c) 2011-2017 (Scilab Enterprises)
Copyright (c) 1989-2012 (INRIA)
Copyright (c) 1989-2007 (ENPC)
with contributors
Last updated:
Thu May 12 11:44:45 CEST 2011