mirror of
https://github.com/golang/go.git
synced 2024-09-29 06:17:11 +00:00
spec: better organization of arithmetic operator section
First step towards cleaning up the operator section - no language changes. Specifically: - Grouped arithmetic operations by types (integer, floating-point, string), with corresponding h4 headings. - Changed Operator precedence title from h3 to h4. - Moved Integer Overflow section after integer operations and changed its title from h3 to h4. This puts things that belong together closer. No heading id's were lost (in case of references from outside the spec). Change-Id: I6b349ba8d86a6ae29b596beb297cc45c81e69399 Reviewed-on: https://go-review.googlesource.com/13143 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
05614bfcfa
commit
3dd3ab41ac
@ -3341,7 +3341,8 @@ var v float32 = 1<<s // illegal: 1 has type float32, cannot shift
|
||||
var w int64 = 1.0<<33 // 1.0<<33 is a constant shift expression
|
||||
</pre>
|
||||
|
||||
<h3 id="Operator_precedence">Operator precedence</h3>
|
||||
|
||||
<h4 id="Operator_precedence">Operator precedence</h4>
|
||||
<p>
|
||||
Unary operators have the highest precedence.
|
||||
As the <code>++</code> and <code>--</code> operators form
|
||||
@ -3383,9 +3384,9 @@ x == y+1 && <-chanPtr > 0
|
||||
<p>
|
||||
Arithmetic operators apply to numeric values and yield a result of the same
|
||||
type as the first operand. The four standard arithmetic operators (<code>+</code>,
|
||||
<code>-</code>, <code>*</code>, <code>/</code>) apply to integer,
|
||||
floating-point, and complex types; <code>+</code> also applies
|
||||
to strings. All other arithmetic operators apply to integers only.
|
||||
<code>-</code>, <code>*</code>, <code>/</code>) apply to integer,
|
||||
floating-point, and complex types; <code>+</code> also applies to strings.
|
||||
The bitwise logical and shift operators apply to integers only.
|
||||
</p>
|
||||
|
||||
<pre class="grammar">
|
||||
@ -3404,19 +3405,9 @@ to strings. All other arithmetic operators apply to integers only.
|
||||
>> right shift integer >> unsigned integer
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
Strings can be concatenated using the <code>+</code> operator
|
||||
or the <code>+=</code> assignment operator:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
s := "hi" + string(c)
|
||||
s += " and good bye"
|
||||
</pre>
|
||||
<h4 id="Integer_operators">Integer operators</h4>
|
||||
|
||||
<p>
|
||||
String addition creates a new string by concatenating the operands.
|
||||
</p>
|
||||
<p>
|
||||
For two integer values <code>x</code> and <code>y</code>, the integer quotient
|
||||
<code>q = x / y</code> and remainder <code>r = x % y</code> satisfy the following
|
||||
@ -3493,16 +3484,8 @@ follows:
|
||||
and m = -1 for signed x
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
For floating-point and complex numbers,
|
||||
<code>+x</code> is the same as <code>x</code>,
|
||||
while <code>-x</code> is the negation of <code>x</code>.
|
||||
The result of a floating-point or complex division by zero is not specified beyond the
|
||||
IEEE-754 standard; whether a <a href="#Run_time_panics">run-time panic</a>
|
||||
occurs is implementation-specific.
|
||||
</p>
|
||||
|
||||
<h3 id="Integer_overflow">Integer overflow</h3>
|
||||
<h4 id="Integer_overflow">Integer overflow</h4>
|
||||
|
||||
<p>
|
||||
For unsigned integer values, the operations <code>+</code>,
|
||||
@ -3523,6 +3506,35 @@ not occur. For instance, it may not assume that <code>x < x + 1</code> is alw
|
||||
</p>
|
||||
|
||||
|
||||
<h4 id="Floating_point_operators">Floating-point operators</h4>
|
||||
|
||||
<p>
|
||||
For floating-point and complex numbers,
|
||||
<code>+x</code> is the same as <code>x</code>,
|
||||
while <code>-x</code> is the negation of <code>x</code>.
|
||||
The result of a floating-point or complex division by zero is not specified beyond the
|
||||
IEEE-754 standard; whether a <a href="#Run_time_panics">run-time panic</a>
|
||||
occurs is implementation-specific.
|
||||
</p>
|
||||
|
||||
|
||||
<h4 id="String_concatenation">String concatenation</h4>
|
||||
|
||||
<p>
|
||||
Strings can be concatenated using the <code>+</code> operator
|
||||
or the <code>+=</code> assignment operator:
|
||||
</p>
|
||||
|
||||
<pre>
|
||||
s := "hi" + string(c)
|
||||
s += " and good bye"
|
||||
</pre>
|
||||
|
||||
<p>
|
||||
String addition creates a new string by concatenating the operands.
|
||||
</p>
|
||||
|
||||
|
||||
<h3 id="Comparison_operators">Comparison operators</h3>
|
||||
|
||||
<p>
|
||||
|
Loading…
Reference in New Issue
Block a user