Skip to content

Commit 3e514a0

Browse files
committed
spec: explicitly define integer, floating-point, and complex types
The terms "integer type", "floating-point type", and "complex type" are used frequently in the spec but are not explicitly (only indirectly) defined. Slightly rephrased the section on numeric types and introduce these terms explicitly. Add links to this section. Change-Id: I3fb888933bece047da8b356b684c855618e9aee4 Reviewed-on: https://go-review.googlesource.com/c/go/+/384157 Trust: Robert Griesemer <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent f524a2b commit 3e514a0

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

doc/go_spec.html

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification - Go 1.18 Draft (incomplete)",
3-
"Subtitle": "Version of Jan 31, 2022",
3+
"Subtitle": "Version of Feb 8, 2022",
44
"Path": "/ref/spec"
55
}-->
66

@@ -901,7 +901,9 @@ <h3 id="Boolean_types">Boolean types</h3>
901901
<h3 id="Numeric_types">Numeric types</h3>
902902

903903
<p>
904-
A <i>numeric type</i> represents sets of integer or floating-point values.
904+
An <i>integer</i>, <i>floating-point</i>, or <i>complex</i> type
905+
represents the set of integer, floating-point, or complex values, respectively.
906+
They are collectively called <i>numeric types</i>.
905907
The predeclared architecture-independent numeric types are:
906908
</p>
907909

@@ -932,7 +934,7 @@ <h3 id="Numeric_types">Numeric types</h3>
932934
</p>
933935

934936
<p>
935-
There is also a set of predeclared numeric types with implementation-specific sizes:
937+
There is also a set of predeclared integer types with implementation-specific sizes:
936938
</p>
937939

938940
<pre class="grammar">
@@ -1921,7 +1923,7 @@ <h3 id="Representability">Representability</h3>
19211923
</li>
19221924

19231925
<li>
1924-
<code>T</code> is a floating-point type and <code>x</code> can be rounded to <code>T</code>'s
1926+
<code>T</code> is a <a href="#Numeric_types">floating-point type</a> and <code>x</code> can be rounded to <code>T</code>'s
19251927
precision without overflow. Rounding uses IEEE 754 round-to-even rules but with an IEEE
19261928
negative zero further simplified to an unsigned zero. Note that constant values never result
19271929
in an IEEE negative zero, NaN, or infinity.
@@ -3108,7 +3110,7 @@ <h3 id="Composite_literals">Composite literals</h3>
31083110
key must be a non-negative constant
31093111
<a href="#Representability">representable</a> by
31103112
a value of type <code>int</code>; and if it is typed
3111-
it must be of integer type.
3113+
it must be of <a href="#Numeric_types">integer type</a>.
31123114
</li>
31133115
<li>An element without a key uses the previous element's index plus one.
31143116
If the first element has no key, its index is zero.
@@ -3707,7 +3709,7 @@ <h3 id="Index_expressions">Index expressions</h3>
37073709
If <code>a</code> is not a map:
37083710
</p>
37093711
<ul>
3710-
<li>the index <code>x</code> must be of integer type or an untyped constant</li>
3712+
<li>the index <code>x</code> must be of <a href="#Numeric_types">integer type</a> or an untyped constant</li>
37113713
<li>a constant index must be non-negative and
37123714
<a href="#Representability">representable</a> by a value of type <code>int</code></li>
37133715
<li>a constant index that is untyped is given type <code>int</code></li>
@@ -4660,7 +4662,7 @@ <h3 id="Operators">Operators</h3>
46604662
</p>
46614663

46624664
<p>
4663-
The right operand in a shift expression must have integer type
4665+
The right operand in a shift expression must have <a href="#Numeric_types">integer type</a>
46644666
or be an untyped constant <a href="#Representability">representable</a> by a
46654667
value of type <code>uint</code>.
46664668
If the left operand of a non-constant shift expression is an untyped constant,
@@ -4740,8 +4742,9 @@ <h3 id="Arithmetic_operators">Arithmetic operators</h3>
47404742
<p>
47414743
Arithmetic operators apply to numeric values and yield a result of the same
47424744
type as the first operand. The four standard arithmetic operators (<code>+</code>,
4743-
<code>-</code>, <code>*</code>, <code>/</code>) apply to integer,
4744-
floating-point, and complex types; <code>+</code> also applies to strings.
4745+
<code>-</code>, <code>*</code>, <code>/</code>) apply to
4746+
<a href="#Numeric_types">integer</a>, <a href="#Numeric_types">floating-point</a>, and
4747+
<a href="#Numeric_types">complex</a> types; <code>+</code> also applies to <a href="#String_types">strings</.
47454748
The bitwise logical and shift operators apply to integers only.
47464749
</p>
47474750

@@ -4880,7 +4883,7 @@ <h4 id="Floating_point_operators">Floating-point operators</h4>
48804883
An implementation may combine multiple floating-point operations into a single
48814884
fused operation, possibly across statements, and produce a result that differs
48824885
from the value obtained by executing and rounding the instructions individually.
4883-
An explicit floating-point type <a href="#Conversions">conversion</a> rounds to
4886+
An explicit <a href="#Numeric_types">floating-point type</a> <a href="#Conversions">conversion</a> rounds to
48844887
the precision of the target type, preventing fusion that would discard that rounding.
48854888
</p>
48864889

@@ -5321,19 +5324,19 @@ <h4>Conversions between numeric types</h4>
53215324

53225325
<ol>
53235326
<li>
5324-
When converting between integer types, if the value is a signed integer, it is
5327+
When converting between <a href="#Numeric_types">integer types</a>, if the value is a signed integer, it is
53255328
sign extended to implicit infinite precision; otherwise it is zero extended.
53265329
It is then truncated to fit in the result type's size.
53275330
For example, if <code>v := uint16(0x10F0)</code>, then <code>uint32(int8(v)) == 0xFFFFFFF0</code>.
53285331
The conversion always yields a valid value; there is no indication of overflow.
53295332
</li>
53305333
<li>
5331-
When converting a floating-point number to an integer, the fraction is discarded
5334+
When converting a <a href="#Numeric_types">floating-point number</a> to an integer, the fraction is discarded
53325335
(truncation towards zero).
53335336
</li>
53345337
<li>
53355338
When converting an integer or floating-point number to a floating-point type,
5336-
or a complex number to another complex type, the result value is rounded
5339+
or a <a href="#Numeric_types">complex number</a> to another complex type, the result value is rounded
53375340
to the precision specified by the destination type.
53385341
For instance, the value of a variable <code>x</code> of type <code>float32</code>
53395342
may be stored using additional precision beyond that of an IEEE-754 32-bit number,
@@ -7037,7 +7040,7 @@ <h3 id="Making_slices_maps_and_channels">Making slices, maps and channels</h3>
70377040

70387041

70397042
<p>
7040-
Each of the size arguments <code>n</code> and <code>m</code> must be of integer type
7043+
Each of the size arguments <code>n</code> and <code>m</code> must be of <a href="#Numeric_types">integer type</a>
70417044
or an untyped <a href="#Constants">constant</a>.
70427045
A constant size argument must be non-negative and <a href="#Representability">representable</a>
70437046
by a value of type <code>int</code>; if it is an untyped constant it is given type <code>int</code>.
@@ -7182,7 +7185,8 @@ <h3 id="Complex_numbers">Manipulating complex numbers</h3>
71827185
<p>
71837186
The type of the arguments and return value correspond.
71847187
For <code>complex</code>, the two arguments must be of the same
7185-
floating-point type and the return type is the complex type
7188+
<a href="#Numeric_types">floating-point type</a> and the return type is the
7189+
<a href="#Numeric_types">complex type</a>
71867190
with the corresponding floating-point constituents:
71877191
<code>complex64</code> for <code>float32</code> arguments, and
71887192
<code>complex128</code> for <code>float64</code> arguments.
@@ -7897,7 +7901,7 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
78977901
<p>
78987902
The function <code>Add</code> adds <code>len</code> to <code>ptr</code>
78997903
and returns the updated pointer <code>unsafe.Pointer(uintptr(ptr) + uintptr(len))</code>.
7900-
The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>.
7904+
The <code>len</code> argument must be of <a href="#Numeric_types">integer type</a> or an untyped <a href="#Constants">constant</a>.
79017905
A constant <code>len</code> argument must be <a href="#Representability">representable</a> by a value of type <code>int</code>;
79027906
if it is an untyped constant it is given type <code>int</code>.
79037907
The rules for <a href="/pkg/unsafe#Pointer">valid uses</a> of <code>Pointer</code> still apply.
@@ -7920,7 +7924,7 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
79207924
</p>
79217925

79227926
<p>
7923-
The <code>len</code> argument must be of integer type or an untyped <a href="#Constants">constant</a>.
7927+
The <code>len</code> argument must be of <a href="#Numeric_types">integer type</a> or an untyped <a href="#Constants">constant</a>.
79247928
A constant <code>len</code> argument must be non-negative and <a href="#Representability">representable</a> by a value of type <code>int</code>;
79257929
if it is an untyped constant it is given type <code>int</code>.
79267930
At run time, if <code>len</code> is negative,

0 commit comments

Comments
 (0)