Commit 462860bd authored by Robert Griesemer's avatar Robert Griesemer

spec: more explicit comments for constant expression examples

Fixes #3814.

R=rsc, iant
CC=golang-dev
https://golang.org/cl/6920057
parent a9a49fe9
...@@ -3706,8 +3706,8 @@ an untyped complex constant. ...@@ -3706,8 +3706,8 @@ an untyped complex constant.
</p> </p>
<pre> <pre>
const ic = complex(0, c) // ic == 3.75i (untyped complex constant) const ic = complex(0, c) // ic == 3.75i (untyped complex constant)
const iΘ = complex(0, Θ) // iΘ == 1.5i (type complex128) const iΘ = complex(0, Θ) // iΘ == 1.5i (type complex128)
</pre> </pre>
<p> <p>
...@@ -3717,8 +3717,8 @@ by any predeclared type in the language. The following are legal declarations: ...@@ -3717,8 +3717,8 @@ by any predeclared type in the language. The following are legal declarations:
</p> </p>
<pre> <pre>
const Huge = 1 &lt;&lt; 100 const Huge = 1 &lt;&lt; 100 // Huge == 1267650600228229401496703205376 (untyped integer constant)
const Four int8 = Huge &gt;&gt; 98 const Four int8 = Huge &gt;&gt; 98 // Four == 4 (type int8)
</pre> </pre>
<p> <p>
...@@ -3737,9 +3737,9 @@ of the constant type. The following constant expressions are illegal: ...@@ -3737,9 +3737,9 @@ of the constant type. The following constant expressions are illegal:
<pre> <pre>
uint(-1) // -1 cannot be represented as a uint uint(-1) // -1 cannot be represented as a uint
int(3.14) // 3.14 cannot be represented as an int int(3.14) // 3.14 cannot be represented as an int
int64(Huge) // 1&lt;&lt;100 cannot be represented as an int64 int64(Huge) // 1267650600228229401496703205376 cannot be represented as an int64
Four * 300 // 300 cannot be represented as an int8 Four * 300 // operand 300 cannot be represented as an int8 (type of Four)
Four * 100 // 400 cannot be represented as an int8 Four * 100 // product 400 cannot be represented as an int8 (type of Four)
</pre> </pre>
<p> <p>
...@@ -3750,7 +3750,7 @@ and -1 for signed and untyped constants. ...@@ -3750,7 +3750,7 @@ and -1 for signed and untyped constants.
<pre> <pre>
^1 // untyped integer constant, equal to -2 ^1 // untyped integer constant, equal to -2
uint8(^1) // error, same as uint8(-2), out of range uint8(^1) // illegal: same as uint8(-2), -2 cannot be represented as a uint8
^uint8(1) // typed uint8 constant, same as 0xFF ^ uint8(1) = uint8(0xFE) ^uint8(1) // typed uint8 constant, same as 0xFF ^ uint8(1) = uint8(0xFE)
int8(^1) // same as int8(-2) int8(^1) // same as int8(-2)
^int8(1) // same as -1 ^ int8(1) = -2 ^int8(1) // same as -1 ^ int8(1) = -2
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment