aboutsummaryrefslogtreecommitdiff
path: root/doc/go_spec.html
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2018-01-16 21:30:46 -0800
committerRobert Griesemer <gri@golang.org>2018-01-17 18:59:44 +0000
commit18d527b3f09521a21e4068917f9b4513fcfcc2ef (patch)
tree27a3202bad3dc494375b17ccb1fed215aae91371 /doc/go_spec.html
parent2dc025e4e171ee99d31d11efe5ccf53794e89020 (diff)
downloadgo-18d527b3f09521a21e4068917f9b4513fcfcc2ef.tar.gz
go-18d527b3f09521a21e4068917f9b4513fcfcc2ef.zip
spec: mention that special case for integer division is due to overflow
Fixes #23443. Change-Id: If60c39b582ee5308e9fa902f93c1b6ae7890346c Reviewed-on: https://go-review.googlesource.com/87975 Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'doc/go_spec.html')
-rw-r--r--doc/go_spec.html15
1 files changed, 8 insertions, 7 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html
index f009ec0054..1ada626bf0 100644
--- a/doc/go_spec.html
+++ b/doc/go_spec.html
@@ -1,6 +1,6 @@
<!--{
"Title": "The Go Programming Language Specification",
- "Subtitle": "Version of January 11, 2018",
+ "Subtitle": "Version of January 17, 2018",
"Path": "/ref/spec"
}-->
@@ -3558,9 +3558,10 @@ with <code>x / y</code> truncated towards zero
</pre>
<p>
-As an exception to this rule, if the dividend <code>x</code> is the most
-negative value for the int type of <code>x</code>, the quotient
-<code>q = x / -1</code> is equal to <code>x</code> (and <code>r = 0</code>).
+The one exception to this rule is that if the dividend <code>x</code> is
+the most negative value for the int type of <code>x</code>, the quotient
+<code>q = x / -1</code> is equal to <code>x</code> (and <code>r = 0</code>)
+due to two's-complement <a href="#Integer_overflow">integer overflow</a>:
</p>
<pre>
@@ -3623,11 +3624,11 @@ discard high bits upon overflow, and programs may rely on "wrap around".
</p>
<p>
For signed integers, the operations <code>+</code>,
-<code>-</code>, <code>*</code>, and <code>&lt;&lt;</code> may legally
+<code>-</code>, <code>*</code>, <code>/</code>, and <code>&lt;&lt;</code> may legally
overflow and the resulting value exists and is deterministically defined
by the signed integer representation, the operation, and its operands.
-No exception is raised as a result of overflow. A
-compiler may not optimize code under the assumption that overflow does
+No exception is raised as a result of overflow.
+A compiler may not optimize code under the assumption that overflow does
not occur. For instance, it may not assume that <code>x &lt; x + 1</code> is always true.
</p>