File: Comparison-Ops.html

package info (click to toggle)
octave 3.6.2-5%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 71,636 kB
  • sloc: cpp: 241,186; fortran: 23,651; sh: 14,790; ansic: 7,153; lex: 3,761; objc: 3,404; yacc: 3,386; makefile: 2,073; awk: 985; perl: 838
file content (172 lines) | stat: -rw-r--r-- 8,584 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<html lang="en">
<head>
<title>Comparison Ops - GNU Octave</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="GNU Octave">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Expressions.html#Expressions" title="Expressions">
<link rel="prev" href="Arithmetic-Ops.html#Arithmetic-Ops" title="Arithmetic Ops">
<link rel="next" href="Boolean-Expressions.html#Boolean-Expressions" title="Boolean Expressions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
  pre.display { font-family:inherit }
  pre.format  { font-family:inherit }
  pre.smalldisplay { font-family:inherit; font-size:smaller }
  pre.smallformat  { font-family:inherit; font-size:smaller }
  pre.smallexample { font-size:smaller }
  pre.smalllisp    { font-size:smaller }
  span.sc    { font-variant:small-caps }
  span.roman { font-family:serif; font-weight:normal; } 
  span.sansserif { font-family:sans-serif; font-weight:normal; } 
--></style>
</head>
<body>
<div class="node">
<a name="Comparison-Ops"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Boolean-Expressions.html#Boolean-Expressions">Boolean Expressions</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Arithmetic-Ops.html#Arithmetic-Ops">Arithmetic Ops</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Expressions.html#Expressions">Expressions</a>
<hr>
</div>

<h3 class="section">8.4 Comparison Operators</h3>

<p><a name="index-comparison-expressions-596"></a><a name="index-expressions_002c-comparison-597"></a><a name="index-relational-operators-598"></a><a name="index-operators_002c-relational-599"></a><a name="index-less-than-operator-600"></a><a name="index-greater-than-operator-601"></a><a name="index-equality-operator-602"></a><a name="index-tests-for-equality-603"></a><a name="index-equality_002c-tests-for-604"></a>
<dfn>Comparison operators</dfn> compare numeric values for relationships
such as equality.  They are written using
<em>relational operators</em>.

   <p>All of Octave's comparison operators return a value of 1 if the
comparison is true, or 0 if it is false.  For matrix values, they all
work on an element-by-element basis.  Broadcasting rules apply. 
See <a href="Broadcasting.html#Broadcasting">Broadcasting</a>.  For example:

<pre class="example">     [1, 2; 3, 4] == [1, 3; 2, 4]
          &rArr;  1  0
              0  1
</pre>
   <p>According to broadcasting rules, if one operand is a scalar and the
other is a matrix, the scalar is compared to each element of the matrix
in turn, and the result is the same size as the matrix.

     <dl>
<dt><var>x</var><code> &lt; </code><var>y</var><dd><a name="index-g_t_003c-605"></a>True if <var>x</var> is less than <var>y</var>.

     <br><dt><var>x</var><code> &lt;= </code><var>y</var><dd><a name="index-g_t_003c_003d-606"></a>True if <var>x</var> is less than or equal to <var>y</var>.

     <br><dt><var>x</var><code> == </code><var>y</var><dd><a name="index-g_t_003d_003d-607"></a>True if <var>x</var> is equal to <var>y</var>.

     <br><dt><var>x</var><code> &gt;= </code><var>y</var><dd><a name="index-g_t_003e_003d-608"></a>True if <var>x</var> is greater than or equal to <var>y</var>.

     <br><dt><var>x</var><code> &gt; </code><var>y</var><dd><a name="index-g_t_003e-609"></a>True if <var>x</var> is greater than <var>y</var>.

     <br><dt><var>x</var><code> != </code><var>y</var><dt><var>x</var><code> ~= </code><var>y</var><dd><a name="index-g_t_0021_003d-610"></a><a name="index-g_t_007e_003d-611"></a>True if <var>x</var> is not equal to <var>y</var>. 
</dl>

   <p>For complex numbers, the following ordering is defined:
<var>z1</var> &lt; <var>z2</var>
iff

<pre class="example">       abs(<var>z1</var>) &lt; abs(<var>z2</var>)
       || (abs(<var>z1</var>) == abs(<var>z2</var>) &amp;&amp; arg(<var>z1</var>) &lt; arg(<var>z2</var>))
</pre>
   <p>This is consistent with the ordering used by <dfn>max</dfn>, <dfn>min</dfn> and
<dfn>sort</dfn>, but is not consistent with <span class="sc">matlab</span>, which only compares the real
parts.

   <p>String comparisons may also be performed with the <code>strcmp</code>
function, not with the comparison operators listed above. 
See <a href="Strings.html#Strings">Strings</a>.

   <p><a name="index-g_t_003d_003d-612"></a><!-- eq src/data.cc -->
<a name="doc_002deq"></a>

<div class="defun">
&mdash; Built-in Function:  <b>eq</b> (<var>x, y</var>)<var><a name="index-eq-613"></a></var><br>
<blockquote><p>Return true if the two inputs are equal. 
This function is equivalent to <code>x&nbsp;==&nbsp;y</code><!-- /@w -->. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002dne.html#doc_002dne">ne</a>, <a href="doc_002disequal.html#doc_002disequal">isequal</a>. 
</p></blockquote></div>

   <p><a name="index-g_t_003e_003d-614"></a><!-- ge src/data.cc -->
<a name="doc_002dge"></a>

<div class="defun">
&mdash; Built-in Function:  <b>ge</b> (<var>x, y</var>)<var><a name="index-ge-615"></a></var><br>
<blockquote><p>This function is equivalent to <code>x&nbsp;&gt;=&nbsp;y</code><!-- /@w -->. 
</p></blockquote></div>

   <p><a name="index-g_t_003e-616"></a><!-- gt src/data.cc -->
<a name="doc_002dgt"></a>

<div class="defun">
&mdash; Built-in Function:  <b>gt</b> (<var>x, y</var>)<var><a name="index-gt-617"></a></var><br>
<blockquote><p>This function is equivalent to <code>x&nbsp;&gt;&nbsp;y</code><!-- /@w -->. 
</p></blockquote></div>

<!-- isequal scripts/general/isequal.m -->
   <p><a name="doc_002disequal"></a>

<div class="defun">
&mdash; Function File:  <b>isequal</b> (<var>x1, x2, <small class="dots">...</small></var>)<var><a name="index-isequal-618"></a></var><br>
<blockquote><p>Return true if all of <var>x1</var>, <var>x2</var>, <small class="dots">...</small> are equal. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002disequalwithequalnans.html#doc_002disequalwithequalnans">isequalwithequalnans</a>. 
</p></blockquote></div>

<!-- isequalwithequalnans scripts/general/isequalwithequalnans.m -->
   <p><a name="doc_002disequalwithequalnans"></a>

<div class="defun">
&mdash; Function File:  <b>isequalwithequalnans</b> (<var>x1, x2, <small class="dots">...</small></var>)<var><a name="index-isequalwithequalnans-619"></a></var><br>
<blockquote><p>Assuming NaN == NaN, return true if all of <var>x1</var>, <var>x2</var>, <small class="dots">...</small>
are equal. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002disequal.html#doc_002disequal">isequal</a>. 
</p></blockquote></div>

   <p><a name="index-g_t_003c_003d-620"></a><!-- le src/data.cc -->
<a name="doc_002dle"></a>

<div class="defun">
&mdash; Built-in Function:  <b>le</b> (<var>x, y</var>)<var><a name="index-le-621"></a></var><br>
<blockquote><p>This function is equivalent to <code>x&nbsp;&lt;=&nbsp;y</code><!-- /@w -->. 
</p></blockquote></div>

   <p><a name="index-g_t_003c-622"></a><!-- lt src/data.cc -->
<a name="doc_002dlt"></a>

<div class="defun">
&mdash; Built-in Function:  <b>lt</b> (<var>x, y</var>)<var><a name="index-lt-623"></a></var><br>
<blockquote><p>This function is equivalent to <code>x&nbsp;&lt;&nbsp;y</code><!-- /@w -->. 
</p></blockquote></div>

   <p><a name="index-g_t_0021_003d-624"></a><a name="index-g_t_007e_003d-625"></a><!-- ne src/data.cc -->
<a name="doc_002dne"></a>

<div class="defun">
&mdash; Built-in Function:  <b>ne</b> (<var>x, y</var>)<var><a name="index-ne-626"></a></var><br>
<blockquote><p>Return true if the two inputs are not equal. 
This function is equivalent to <code>x&nbsp;!=&nbsp;y</code><!-- /@w -->. 
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->

     <p class="noindent"><strong>See also:</strong> <a href="doc_002deq.html#doc_002deq">eq</a>, <a href="doc_002disequal.html#doc_002disequal">isequal</a>. 
</p></blockquote></div>

   </body></html>