Skip to content

Commit

Permalink
spec: better organization of arithmetic operator section
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
griesemer committed Aug 5, 2015
1 parent 05614bf commit 3dd3ab4
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions doc/go_spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -3341,7 +3341,8 @@ <h3 id="Operators">Operators</h3>
var w int64 = 1.0&lt;&lt;33 // 1.0&lt;&lt;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
Expand Down Expand Up @@ -3383,9 +3384,9 @@ <h3 id="Arithmetic_operators">Arithmetic operators</h3>
<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">
Expand All @@ -3404,19 +3405,9 @@ <h3 id="Arithmetic_operators">Arithmetic operators</h3>
&gt;&gt; right shift integer &gt;&gt; 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
Expand Down Expand Up @@ -3493,16 +3484,8 @@ <h3 id="Arithmetic_operators">Arithmetic operators</h3>
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>,
Expand All @@ -3523,6 +3506,35 @@ <h3 id="Integer_overflow">Integer overflow</h3>
</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>
Expand Down

0 comments on commit 3dd3ab4

Please sign in to comment.