source: public/doc/gnu-c/Arithmetic.html@ 02598c2

Last change on this file since 02598c2 was 02598c2, checked in by Mikhail Kirillov <w96k@…>, on Oct 6, 2022 at 12:36:29 PM

Add gnu-c

  • Property mode set to 100644
File size: 7.0 KB
Line 
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
6licensed to the FSF.)
7
8Permission is granted to copy, distribute and/or modify this document
9under the terms of the GNU Free Documentation License, Version 1.3 or
10any later version published by the Free Software Foundation; with the
11Invariant Sections being "GNU General Public License," with the
12Front-Cover Texts being "A GNU Manual," and with the Back-Cover
13Texts as in (a) below. A copy of the license is included in the
14section entitled "GNU Free Documentation License."
15
16(a) The FSF's Back-Cover Text is: "You have the freedom to copy and
17modify this GNU manual. Buying copies from the FSF supports it in
18developing 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>Arithmetic (GNU C Language Manual)</title>
23
24<meta name="description" content="Arithmetic (GNU C Language Manual)">
25<meta name="keywords" content="Arithmetic (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="index.html" rel="up" title="Top">
33<link href="Basic-Arithmetic.html" rel="next" title="Basic Arithmetic">
34<link href="Line-Continuation.html" rel="prev" title="Line Continuation">
35<style type="text/css">
36<!--
37a.summary-letter {text-decoration: none}
38blockquote.indentedblock {margin-right: 0em}
39div.display {margin-left: 3.2em}
40div.example {margin-left: 3.2em}
41div.lisp {margin-left: 3.2em}
42kbd {font-style: oblique}
43pre.display {font-family: inherit}
44pre.format {font-family: inherit}
45pre.menu-comment {font-family: serif}
46pre.menu-preformatted {font-family: serif}
47span.nolinebreak {white-space: nowrap}
48span.roman {font-family: initial; font-weight: normal}
49span.sansserif {font-family: sans-serif; font-weight: normal}
50ul.no-bullet {list-style: none}
51-->
52</style>
53
54
55</head>
56
57<body lang="en">
58<span id="Arithmetic"></span><div class="header">
59<p>
60Next: <a href="Assignment-Expressions.html" accesskey="n" rel="next">Assignment Expressions</a>, Previous: <a href="Lexical-Syntax.html" accesskey="p" rel="prev">Lexical Syntax</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<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="Arithmetic-1"></span><h2 class="chapter">6 Arithmetic</h2>
64<span id="index-arithmetic-operators"></span>
65<span id="index-operators_002c-arithmetic"></span>
66
67
68<p>Arithmetic operators in C attempt to be as similar as possible to the
69abstract arithmetic operations, but it is impossible to do this
70perfectly. Numbers in a computer have a finite range of possible
71values, and non-integer values have a limit on their possible
72accuracy. Nonetheless, in most cases you will encounter no surprises
73in using &lsquo;<samp>+</samp>&rsquo; for addition, &lsquo;<samp>-</samp>&rsquo; for subtraction, and &lsquo;<samp>*</samp>&rsquo;
74for multiplication.
75</p>
76<p>Each C operator has a <em>precedence</em>, which is its rank in the
77grammatical order of the various operators. The operators with the
78highest precedence grab adjoining operands first; these expressions
79then become operands for operators of lower precedence. We give some
80information about precedence of operators in this chapter where we
81describe the operators; for the full explanation, see <a href="Binary-Operator-Grammar.html">Binary Operator Grammar</a>.
82</p>
83<p>The arithmetic operators always <em>promote</em> their operands before
84operating on them. This means converting narrow integer data types to
85a wider data type (see <a href="Operand-Promotions.html">Operand Promotions</a>). If you are just
86learning C, don&rsquo;t worry about this yet.
87</p>
88<p>Given two operands that have different types, most arithmetic
89operations convert them both to their <em>common type</em>. For
90instance, if one is <code>int</code> and the other is <code>double</code>, the
91common type is <code>double</code>. (That&rsquo;s because <code>double</code> can
92represent all the values that an <code>int</code> can hold, but not vice
93versa.) For the full details, see <a href="Common-Type.html">Common Type</a>.
94</p>
95<table class="menu" border="0" cellspacing="0">
96<tr><td align="left" valign="top">&bull; <a href="Basic-Arithmetic.html" accesskey="1">Basic Arithmetic</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Addition, subtraction, multiplication,
97 and division.
98</td></tr>
99<tr><td align="left" valign="top">&bull; <a href="Integer-Arithmetic.html" accesskey="2">Integer Arithmetic</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How C performs arithmetic with integer values.
100</td></tr>
101<tr><td align="left" valign="top">&bull; <a href="Integer-Overflow.html" accesskey="3">Integer Overflow</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">When an integer value exceeds the range
102 of its type.
103</td></tr>
104<tr><td align="left" valign="top">&bull; <a href="Mixed-Mode.html" accesskey="4">Mixed Mode</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Calculating with both integer values
105 and floating-point values.
106</td></tr>
107<tr><td align="left" valign="top">&bull; <a href="Division-and-Remainder.html" accesskey="5">Division and Remainder</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">How integer division works.
108</td></tr>
109<tr><td align="left" valign="top">&bull; <a href="Numeric-Comparisons.html" accesskey="6">Numeric Comparisons</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Comparing numeric values for equality or order.
110</td></tr>
111<tr><td align="left" valign="top">&bull; <a href="Shift-Operations.html" accesskey="7">Shift Operations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Shift integer bits left or right.
112</td></tr>
113<tr><td align="left" valign="top">&bull; <a href="Bitwise-Operations.html" accesskey="8">Bitwise Operations</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">Bitwise conjunction, disjunction, negation.
114</td></tr>
115</table>
116
117<hr>
118<div class="header">
119<p>
120Next: <a href="Assignment-Expressions.html" accesskey="n" rel="next">Assignment Expressions</a>, Previous: <a href="Lexical-Syntax.html" accesskey="p" rel="prev">Lexical Syntax</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<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>
121</div>
122
123
124
125</body>
126</html>
Note: See TracBrowser for help on using the repository browser.