Scilab Website | Contribute with GitLab | Mailing list archives | ATOMS toolboxes
Scilab Online Help
6.1.1 - 日本語

Change language to:
English - Français - 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

Scilabヘルプ >> Scilab > Scilab keywords > comparison

comparison

比較, 関係演算子

呼出し手順

a==b
a~=b or a<>b
a<b
a<=b
a>b
a>=b

引数

a

等値比較a==b, a~=b a<>bの場合は任意の変数の型とすることができ, 順序が関連する比較a<b, a<=b, a>b,a>=b に関しては,浮動小数点の実数および整数の配列に制限されます.

b

等値比較 a==b, a~=b a< > b の場合は任意の変数の型とすることができ, 順序が関連する比較 a<b, a<=b, a>b,a>=b に関しては,浮動小数点の実数および整数の配列に制限されます.

説明

2つの暮らすの演算士は区別する必要があります:

等値および不等式比較:

a==b, a~=b (または等価な a<>b). これらの演算子は任意のオペランドの型に適用できます.

順序が関連する比較:

a<b, a<=b, a>b,a>=b. これらの演算子は 浮動小数点の実数および整数の配列にのみ適用されます.

比較演算子のセマンティクスもオペランドの型に依存します:

配列変数の場合

浮動小数点の実数および整数配列, 論理値配列, 文字列配列,多項式または有理配列,ハンドル配列,リスト... のような配列変数の場合,以下の規則が適用されます:

  • aおよび b を 同じ型,同じ次元の配列として評価する場合, 要素毎の比較が行われ, 結果は同じ次元の論理値の配列となります.

  • If a および b が 型は同じだが aまたはbが1行1列の配列の場合, このスカラーが別の配列の各要素と比較されます. この結果はスカラーでないオペランドの大きさの論理値の配列となります.

  • その他の場合, 結果は論理値 %f となります.

  • オペランドのデータ型が異なるが浮動小数点と整数のように 互換性がある場合,比較の前に型変換が行われます.

その他の型のオペランドの場合

functionlibrariesのようなその他のオペランドの場合, 結果はオブジェクトが同じ場合に%t, それ以外の場合に %f となります.

互換性がないデータ型の間の等値比較は %fを返します.

  • Polynomials: %s==%z returns %F : Two polynomials can't be considered as equal if they are not about the same variable.

  • Rationals: 1/%s == 1/%z returns %F : Two rationals can't be equal if they are not about the same variable. In addition, the same rational may have different unnormalized forms that won't be considered as equal. For instance, 2/(2*%z) == 1/%z returns %F, even in simp_mode(%T) simplification mode.

  • Sparse numerical matrix: any element-wise comparison with a full-encoded numerical array always returns a boolean sparse array. See examples.

  • Graphics identifiers: A graphic handle h1 and its copy h2=h1 will always stay equal, even if the graphics is changed through one of them. See examples.

//用途毎の比較
(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])

//オブジェクト毎の比較
(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 element-wise comparisons yield a sparse-encoded 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
 = sind ;
 == sind
(0:90:360)
--> sine = sin ;
--> sine == sin
 ans  =
  T

--> 正弦 = sind ;
--> 正弦 == sind
 ans  =
  T

--> 正弦(0:90:360)
 ans  =
   0.   1.   0.  -1.   0.

参照

  • less — (<) より小さいの比較
  • greater
  • equal — (=) 代入 , 比較, 等号
  • isequal — comparison of objects
  • boolean — Scilab オブジェクト, 論理値(boolean)変数および演算子 & | ~

履歴

バージョン記述
6.0
  • ~ (not) priority is now higher than the comparisons one (== ~= < <= >= >).
  • Complex numbers with a null imaginary part are now compared as real numbers.
Report an issue
<< comments Scilab keywords dollar >>

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:
Mon Jan 03 14:37:44 CET 2022