<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
<!DOCTYPE MAN SYSTEM "../../manrev.dtd">
<MAN>
  <LANGUAGE>eng</LANGUAGE>
  <TITLE>Comparison</TITLE>
  <TYPE>Scilab operator</TYPE>
  <DATE>mai 2006</DATE>
  <SHORT_DESCRIPTION name="comparison">  comparison, relational operators</SHORT_DESCRIPTION>

  <CALLING_SEQUENCE>
    <CALLING_SEQUENCE_ITEM>a==b</CALLING_SEQUENCE_ITEM>
    <CALLING_SEQUENCE_ITEM>a~=b or a&lt;&gt;b</CALLING_SEQUENCE_ITEM>
    <CALLING_SEQUENCE_ITEM>a&lt;b</CALLING_SEQUENCE_ITEM>
    <CALLING_SEQUENCE_ITEM>a&lt;=b</CALLING_SEQUENCE_ITEM>
    <CALLING_SEQUENCE_ITEM>a&gt;b</CALLING_SEQUENCE_ITEM>
    <CALLING_SEQUENCE_ITEM>a&gt;=b</CALLING_SEQUENCE_ITEM>
  </CALLING_SEQUENCE>
  <PARAM>
    <PARAM_INDENT>
      <PARAM_ITEM>
        <PARAM_NAME>a</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: any type of variable for <VERB>a==b</VERB>, <VERB>a~=b</VERB> 
	    <VERB>a&lt;&gt;b</VERB> equality comparisons and restricted to real floating point and integer
	    array for order related comparisons <VERB>a&lt;b</VERB>,
	    <VERB>a&lt;=b</VERB>, <VERB>a&gt;b</VERB>,<VERB>a&gt;=b</VERB>. </SP>
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
      <PARAM_ITEM>
        <PARAM_NAME>b</PARAM_NAME>
        <PARAM_DESCRIPTION>
          <SP>: any type of variable for <VERB>a==b</VERB>, <VERB>a~=b</VERB> 
	    <VERB>a&lt; &gt; b</VERB> equality  comparisons and restricted to
	    real floating point and integer arrays for order related comparisons
	    <VERB>a&lt;b</VERB>, <VERB>a&lt;=b</VERB>,
	    <VERB>a&gt;b</VERB>,<VERB>a&gt;=b</VERB>.</SP> 
        </PARAM_DESCRIPTION>
      </PARAM_ITEM>
    </PARAM_INDENT>
  </PARAM>
  <DESCRIPTION>
    <P>Two classes of operators have to be distinguished:</P>
    <DESCRIPTION_INDENT>
      <DESCRIPTION_ITEM label="The equality and inequality comparisons: ">
	<SP><VERB>a==b</VERB>, <VERB>a~=b</VERB> (or equivalently <VERB>a&lt;&gt;b</VERB>).
	  These operators apply to any type of operands.</SP> 
      </DESCRIPTION_ITEM>
      <DESCRIPTION_ITEM label="The order related comparisons: ">
	<SP><VERB>a&lt;b</VERB>, <VERB>a&lt;=b</VERB>,
	    <VERB>a&gt;b</VERB>,<VERB>a&gt;=b</VERB>. These operators apply
	    only to real floating point and integer arrays.</SP> 
      </DESCRIPTION_ITEM>
    </DESCRIPTION_INDENT>

   <P>The semantics of the comparison operators also depend on the operands types:</P>

    <DESCRIPTION_INDENT>
      <DESCRIPTION_ITEM label="With array variables ">
	<SP> like floating point and integer arrays, logical arrays,
	  string arrays, polynomial and rationnal arrays, handle arrays, lists... the following rules apply:</SP> 
	<DESCRIPTION_INDENT>
	  <DESCRIPTION_ITEM>
	    <SP>If <VERB> a</VERB> and <VERB> b</VERB> 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.</SP> 
	  </DESCRIPTION_ITEM>

	  <DESCRIPTION_ITEM>
	    <SP>If <VERB> a</VERB> and <VERB> b</VERB>  evaluates as arrays 
	      with same types, but <VERB> a</VERB> or <VERB> b</VERB> 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.</SP>  
	  </DESCRIPTION_ITEM>

	  <DESCRIPTION_ITEM>
	     <SP>In the others cases the result is the boolean <VERB> %f</VERB></SP>
	  </DESCRIPTION_ITEM>

	  <DESCRIPTION_ITEM>
	    <SP>If the operand data types are differents but "compatible" like
	    floating points and integers a type conversion is performed before
	    the comparison.</SP>
	  </DESCRIPTION_ITEM>

	</DESCRIPTION_INDENT>
      </DESCRIPTION_ITEM>

      <DESCRIPTION_ITEM label="With other type of operands ">
	<SP> like <VERB>function</VERB>,
	<VERB>libraries</VERB>, the result is <VERB>
	    %t</VERB> if the objects are identical and <VERB> %f</VERB> in the
	  other cases.</SP> 
	<P>Equality comparison between operands of incompatible data types
	  returns <VERB>%f</VERB>.</P> 
      </DESCRIPTION_ITEM>
    </DESCRIPTION_INDENT>
   </DESCRIPTION>

  <EXAMPLE>
    <![CDATA[
    //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

    ]]>
  </EXAMPLE>
  <SEE_ALSO>
    <SEE_ALSO_ITEM>
      <LINK>less</LINK>
    </SEE_ALSO_ITEM>
    <SEE_ALSO_ITEM>
      <LINK>boolean</LINK>
    </SEE_ALSO_ITEM>
    <SEE_ALSO_ITEM>
      <LINK>isequal</LINK>
    </SEE_ALSO_ITEM>
  </SEE_ALSO>
</MAN>
