1
1
<!--{
2
2
"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",
4
4
"Path": "/ref/spec"
5
5
}-->
6
6
@@ -901,7 +901,9 @@ <h3 id="Boolean_types">Boolean types</h3>
901
901
< h3 id ="Numeric_types "> Numeric types</ h3 >
902
902
903
903
< 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 > .
905
907
The predeclared architecture-independent numeric types are:
906
908
</ p >
907
909
@@ -932,7 +934,7 @@ <h3 id="Numeric_types">Numeric types</h3>
932
934
</ p >
933
935
934
936
< 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:
936
938
</ p >
937
939
938
940
< pre class ="grammar ">
@@ -1921,7 +1923,7 @@ <h3 id="Representability">Representability</h3>
1921
1923
</ li >
1922
1924
1923
1925
< 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
1925
1927
precision without overflow. Rounding uses IEEE 754 round-to-even rules but with an IEEE
1926
1928
negative zero further simplified to an unsigned zero. Note that constant values never result
1927
1929
in an IEEE negative zero, NaN, or infinity.
@@ -3108,7 +3110,7 @@ <h3 id="Composite_literals">Composite literals</h3>
3108
3110
key must be a non-negative constant
3109
3111
< a href ="#Representability "> representable</ a > by
3110
3112
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 > .
3112
3114
</ li >
3113
3115
< li > An element without a key uses the previous element's index plus one.
3114
3116
If the first element has no key, its index is zero.
@@ -3707,7 +3709,7 @@ <h3 id="Index_expressions">Index expressions</h3>
3707
3709
If < code > a</ code > is not a map:
3708
3710
</ p >
3709
3711
< 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 >
3711
3713
< li > a constant index must be non-negative and
3712
3714
< a href ="#Representability "> representable</ a > by a value of type < code > int</ code > </ li >
3713
3715
< li > a constant index that is untyped is given type < code > int</ code > </ li >
@@ -4660,7 +4662,7 @@ <h3 id="Operators">Operators</h3>
4660
4662
</ p >
4661
4663
4662
4664
< 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 >
4664
4666
or be an untyped constant < a href ="#Representability "> representable</ a > by a
4665
4667
value of type < code > uint</ code > .
4666
4668
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>
4740
4742
< p >
4741
4743
Arithmetic operators apply to numeric values and yield a result of the same
4742
4744
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</ .
4745
4748
The bitwise logical and shift operators apply to integers only.
4746
4749
</ p >
4747
4750
@@ -4880,7 +4883,7 @@ <h4 id="Floating_point_operators">Floating-point operators</h4>
4880
4883
An implementation may combine multiple floating-point operations into a single
4881
4884
fused operation, possibly across statements, and produce a result that differs
4882
4885
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
4884
4887
the precision of the target type, preventing fusion that would discard that rounding.
4885
4888
</ p >
4886
4889
@@ -5321,19 +5324,19 @@ <h4>Conversions between numeric types</h4>
5321
5324
5322
5325
< ol >
5323
5326
< 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
5325
5328
sign extended to implicit infinite precision; otherwise it is zero extended.
5326
5329
It is then truncated to fit in the result type's size.
5327
5330
For example, if < code > v := uint16(0x10F0)</ code > , then < code > uint32(int8(v)) == 0xFFFFFFF0</ code > .
5328
5331
The conversion always yields a valid value; there is no indication of overflow.
5329
5332
</ li >
5330
5333
< 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
5332
5335
(truncation towards zero).
5333
5336
</ li >
5334
5337
< li >
5335
5338
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
5337
5340
to the precision specified by the destination type.
5338
5341
For instance, the value of a variable < code > x</ code > of type < code > float32</ code >
5339
5342
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>
7037
7040
7038
7041
7039
7042
< 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 >
7041
7044
or an untyped < a href ="#Constants "> constant</ a > .
7042
7045
A constant size argument must be non-negative and < a href ="#Representability "> representable</ a >
7043
7046
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>
7182
7185
< p >
7183
7186
The type of the arguments and return value correspond.
7184
7187
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 >
7186
7190
with the corresponding floating-point constituents:
7187
7191
< code > complex64</ code > for < code > float32</ code > arguments, and
7188
7192
< code > complex128</ code > for < code > float64</ code > arguments.
@@ -7897,7 +7901,7 @@ <h3 id="Package_unsafe">Package <code>unsafe</code></h3>
7897
7901
< p >
7898
7902
The function < code > Add</ code > adds < code > len</ code > to < code > ptr</ code >
7899
7903
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 > .
7901
7905
A constant < code > len</ code > argument must be < a href ="#Representability "> representable</ a > by a value of type < code > int</ code > ;
7902
7906
if it is an untyped constant it is given type < code > int</ code > .
7903
7907
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>
7920
7924
</ p >
7921
7925
7922
7926
< 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 > .
7924
7928
A constant < code > len</ code > argument must be non-negative and < a href ="#Representability "> representable</ a > by a value of type < code > int</ code > ;
7925
7929
if it is an untyped constant it is given type < code > int</ code > .
7926
7930
At run time, if < code > len</ code > is negative,
0 commit comments