1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
---|
2 | <html>
|
---|
3 | <!-- Copyright (C) 2022 Richard Stallman and Free Software Foundation, Inc.
|
---|
4 |
|
---|
5 | (The work of Trevis Rothwell and Nelson Beebe has been assigned or
|
---|
6 | licensed to the FSF.)
|
---|
7 |
|
---|
8 | Permission is granted to copy, distribute and/or modify this document
|
---|
9 | under the terms of the GNU Free Documentation License, Version 1.3 or
|
---|
10 | any later version published by the Free Software Foundation; with the
|
---|
11 | Invariant Sections being "GNU General Public License," with the
|
---|
12 | Front-Cover Texts being "A GNU Manual," and with the Back-Cover
|
---|
13 | Texts as in (a) below. A copy of the license is included in the
|
---|
14 | section entitled "GNU Free Documentation License."
|
---|
15 |
|
---|
16 | (a) The FSF's Back-Cover Text is: "You have the freedom to copy and
|
---|
17 | modify this GNU manual. Buying copies from the FSF supports it in
|
---|
18 | developing GNU and promoting software freedom." -->
|
---|
19 | <!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
|
---|
20 | <head>
|
---|
21 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
---|
22 | <title>Numeric Comparisons (GNU C Language Manual)</title>
|
---|
23 |
|
---|
24 | <meta name="description" content="Numeric Comparisons (GNU C Language Manual)">
|
---|
25 | <meta name="keywords" content="Numeric Comparisons (GNU C Language Manual)">
|
---|
26 | <meta name="resource-type" content="document">
|
---|
27 | <meta name="distribution" content="global">
|
---|
28 | <meta name="Generator" content="makeinfo">
|
---|
29 | <link href="index.html" rel="start" title="Top">
|
---|
30 | <link href="Symbol-Index.html" rel="index" title="Symbol Index">
|
---|
31 | <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
|
---|
32 | <link href="Arithmetic.html" rel="up" title="Arithmetic">
|
---|
33 | <link href="Shift-Operations.html" rel="next" title="Shift Operations">
|
---|
34 | <link href="Division-and-Remainder.html" rel="prev" title="Division and Remainder">
|
---|
35 | <style type="text/css">
|
---|
36 | <!--
|
---|
37 | a.summary-letter {text-decoration: none}
|
---|
38 | blockquote.indentedblock {margin-right: 0em}
|
---|
39 | div.display {margin-left: 3.2em}
|
---|
40 | div.example {margin-left: 3.2em}
|
---|
41 | div.lisp {margin-left: 3.2em}
|
---|
42 | kbd {font-style: oblique}
|
---|
43 | pre.display {font-family: inherit}
|
---|
44 | pre.format {font-family: inherit}
|
---|
45 | pre.menu-comment {font-family: serif}
|
---|
46 | pre.menu-preformatted {font-family: serif}
|
---|
47 | span.nolinebreak {white-space: nowrap}
|
---|
48 | span.roman {font-family: initial; font-weight: normal}
|
---|
49 | span.sansserif {font-family: sans-serif; font-weight: normal}
|
---|
50 | ul.no-bullet {list-style: none}
|
---|
51 | -->
|
---|
52 | </style>
|
---|
53 |
|
---|
54 |
|
---|
55 | </head>
|
---|
56 |
|
---|
57 | <body lang="en">
|
---|
58 | <span id="Numeric-Comparisons"></span><div class="header">
|
---|
59 | <p>
|
---|
60 | Next: <a href="Shift-Operations.html" accesskey="n" rel="next">Shift Operations</a>, Previous: <a href="Division-and-Remainder.html" accesskey="p" rel="prev">Division and Remainder</a>, Up: <a href="Arithmetic.html" accesskey="u" rel="up">Arithmetic</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Index.html" title="Index" rel="index">Index</a>]</p>
|
---|
61 | </div>
|
---|
62 | <hr>
|
---|
63 | <span id="Numeric-Comparisons-1"></span><h3 class="section">6.6 Numeric Comparisons</h3>
|
---|
64 | <span id="index-numeric-comparisons"></span>
|
---|
65 | <span id="index-comparisons"></span>
|
---|
66 | <span id="index-operators_002c-comparison"></span>
|
---|
67 | <span id="index-equal-operator"></span>
|
---|
68 | <span id="index-not_002dequal-operator"></span>
|
---|
69 | <span id="index-less_002dthan-operator"></span>
|
---|
70 | <span id="index-greater_002dthan-operator"></span>
|
---|
71 | <span id="index-less_002dor_002dequal-operator"></span>
|
---|
72 | <span id="index-greater_002dor_002dequal-operator"></span>
|
---|
73 | <span id="index-operator_002c-equal"></span>
|
---|
74 | <span id="index-operator_002c-not_002dequal"></span>
|
---|
75 | <span id="index-operator_002c-less_002dthan"></span>
|
---|
76 | <span id="index-operator_002c-greater_002dthan"></span>
|
---|
77 | <span id="index-operator_002c-less_002dor_002dequal"></span>
|
---|
78 | <span id="index-operator_002c-greater_002dor_002dequal"></span>
|
---|
79 | <span id="index-truth-value"></span>
|
---|
80 |
|
---|
81 | <p>There are two kinds of comparison operators: <em>equality</em> and
|
---|
82 | <em>ordering</em>. Equality comparisons test whether two expressions
|
---|
83 | have the same value. The result is a <em>truth value</em>: a number that
|
---|
84 | is 1 for “true” and 0 for “false.”
|
---|
85 | </p>
|
---|
86 | <div class="example">
|
---|
87 | <pre class="example">a == b /* <span class="roman">Test for equal.</span> */
|
---|
88 | a != b /* <span class="roman">Test for not equal.</span> */
|
---|
89 | </pre></div>
|
---|
90 |
|
---|
91 | <p>The equality comparison is written <code>==</code> because plain <code>=</code>
|
---|
92 | is the assignment operator.
|
---|
93 | </p>
|
---|
94 | <p>Ordering comparisons test which operand is greater or less. Their
|
---|
95 | results are truth values. These are the ordering comparisons of C:
|
---|
96 | </p>
|
---|
97 | <div class="example">
|
---|
98 | <pre class="example">a < b /* <span class="roman">Test for less-than.</span> */
|
---|
99 | a > b /* <span class="roman">Test for greater-than.</span> */
|
---|
100 | a <= b /* <span class="roman">Test for less-than-or-equal.</span> */
|
---|
101 | a >= b /* <span class="roman">Test for greater-than-or-equal.</span> */
|
---|
102 | </pre></div>
|
---|
103 |
|
---|
104 | <p>For any integers <code>a</code> and <code>b</code>, exactly one of the comparisons
|
---|
105 | <code>a < b</code>, <code>a == b</code> and <code>a > b</code> is true, just as in
|
---|
106 | mathematics. However, if <code>a</code> and <code>b</code> are special floating
|
---|
107 | point values (not ordinary numbers), all three can be false.
|
---|
108 | See <a href="Special-Float-Values.html">Special Float Values</a>, and <a href="Invalid-Optimizations.html">Invalid Optimizations</a>.
|
---|
109 | </p>
|
---|
110 |
|
---|
111 |
|
---|
112 |
|
---|
113 | </body>
|
---|
114 | </html>
|
---|