Skip to content

Commit a10b4cf

Browse files
committed
spec: document signed integer shift counts
Updates #19113. Change-Id: I4726f51c5061c33979cdd061f6d4616fa97edb9a Reviewed-on: https://go-review.googlesource.com/c/161201 Reviewed-by: Rob Pike <[email protected]>
1 parent 5aac0f0 commit a10b4cf

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

doc/go_spec.html

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Version of November 16, 2018",
3+
"Subtitle": "Version of February 16, 2019",
44
"Path": "/ref/spec"
55
}-->
66

@@ -3439,7 +3439,7 @@ <h3 id="Operators">Operators</h3>
34393439
</p>
34403440

34413441
<p>
3442-
The right operand in a shift expression must have unsigned integer type
3442+
The right operand in a shift expression must have integer type
34433443
or be an untyped constant <a href="#Representability">representable</a> by a
34443444
value of type <code>uint</code>.
34453445
If the left operand of a non-constant shift expression is an untyped constant,
@@ -3586,7 +3586,9 @@ <h4 id="Integer_operators">Integer operators</h4>
35863586

35873587
<p>
35883588
The shift operators shift the left operand by the shift count specified by the
3589-
right operand. They implement arithmetic shifts if the left operand is a signed
3589+
right operand, which must be positive. If the shift count is negative at run time,
3590+
a <a href="#Run_time_panics">run-time panic</a> occurs.
3591+
The shift operators implement arithmetic shifts if the left operand is a signed
35903592
integer and logical shifts if it is an unsigned integer.
35913593
There is no upper limit on the shift count. Shifts behave
35923594
as if the left operand is shifted <code>n</code> times by 1 for a shift
@@ -5921,7 +5923,7 @@ <h3 id="Complex_numbers">Manipulating complex numbers</h3>
59215923
const b = complex(1.0, -1.4) // untyped complex constant 1 - 1.4i
59225924
x := float32(math.Cos(math.Pi/2)) // float32
59235925
var c64 = complex(5, -x) // complex64
5924-
var s uint = complex(1, 0) // untyped complex constant 1 + 0i can be converted to uint
5926+
var s int = complex(1, 0) // untyped complex constant 1 + 0i can be converted to int
59255927
_ = complex(1, 2&lt;&lt;s) // illegal: 2 assumes floating-point type, cannot shift
59265928
var rl = real(c64) // float32
59275929
var im = imag(a) // float64

0 commit comments

Comments
 (0)