From: Robert Griesemer Date: Tue, 8 Feb 2022 17:47:46 +0000 (-0800) Subject: spec: explicitly define integer, floating-point, and complex types X-Git-Tag: go1.18rc1~74 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3e514a0103a7e335c70104435555229f51e4d9ae;p=gostls13.git 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 Reviewed-by: Ian Lance Taylor --- diff --git a/doc/go_spec.html b/doc/go_spec.html index 69ac1d353f..358232ef91 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -901,7 +901,9 @@ it is a defined type.

Numeric types

-A numeric type represents sets of integer or floating-point values. +An integer, floating-point, or complex type +represents the set of integer, floating-point, or complex values, respectively. +They are collectively called numeric types. The predeclared architecture-independent numeric types are:

@@ -932,7 +934,7 @@ The value of an n-bit integer is n bits wide and represented using

-There is also a set of predeclared numeric types with implementation-specific sizes: +There is also a set of predeclared integer types with implementation-specific sizes:

@@ -1921,7 +1923,7 @@ if one of the following conditions applies:
 
 
 
  • -T is a floating-point type and x can be rounded to T's +T is a floating-point type and x can be rounded to T's precision without overflow. Rounding uses IEEE 754 round-to-even rules but with an IEEE negative zero further simplified to an unsigned zero. Note that constant values never result in an IEEE negative zero, NaN, or infinity. @@ -3108,7 +3110,7 @@ For array and slice literals the following rules apply: key must be a non-negative constant representable by a value of type int; and if it is typed - it must be of integer type. + it must be of integer type.
  • An element without a key uses the previous element's index plus one. If the first element has no key, its index is zero. @@ -3707,7 +3709,7 @@ The following rules apply: If a is not a map:

      -
    • the index x must be of integer type or an untyped constant
    • +
    • the index x must be of integer type or an untyped constant
    • a constant index must be non-negative and representable by a value of type int
    • a constant index that is untyped is given type int
    • @@ -4660,7 +4662,7 @@ to the type of the other operand.

      -The right operand in a shift expression must have integer type +The right operand in a shift expression must have integer type or be an untyped constant representable by a value of type uint. If the left operand of a non-constant shift expression is an untyped constant, @@ -4740,8 +4742,9 @@ x == y+1 && <-chanInt > 0

      Arithmetic operators apply to numeric values and yield a result of the same type as the first operand. The four standard arithmetic operators (+, --, *, /) apply to integer, -floating-point, and complex types; + also applies to strings. +-, *, /) apply to +integer, floating-point, and +complex types; + also applies to strings @@ -4880,7 +4883,7 @@ occurs is implementation-specific. An implementation may combine multiple floating-point operations into a single fused operation, possibly across statements, and produce a result that differs from the value obtained by executing and rounding the instructions individually. -An explicit floating-point type conversion rounds to +An explicit floating-point type conversion rounds to the precision of the target type, preventing fusion that would discard that rounding.

      @@ -5321,19 +5324,19 @@ For the conversion of non-constant numeric values, the following rules apply:
      1. -When converting between integer types, if the value is a signed integer, it is +When converting between integer types, if the value is a signed integer, it is sign extended to implicit infinite precision; otherwise it is zero extended. It is then truncated to fit in the result type's size. For example, if v := uint16(0x10F0), then uint32(int8(v)) == 0xFFFFFFF0. The conversion always yields a valid value; there is no indication of overflow.
      2. -When converting a floating-point number to an integer, the fraction is discarded +When converting a floating-point number to an integer, the fraction is discarded (truncation towards zero).
      3. When converting an integer or floating-point number to a floating-point type, -or a complex number to another complex type, the result value is rounded +or a complex number to another complex type, the result value is rounded to the precision specified by the destination type. For instance, the value of a variable x of type float32 may be stored using additional precision beyond that of an IEEE-754 32-bit number, @@ -7037,7 +7040,7 @@ make(T, n) channel buffered channel of type T, buffer size n

        -Each of the size arguments n and m must be of integer type +Each of the size arguments n and m must be of integer type or an untyped constant. A constant size argument must be non-negative and representable by a value of type int; if it is an untyped constant it is given type int. @@ -7182,7 +7185,8 @@ imag(complexT) floatT

        The type of the arguments and return value correspond. For complex, the two arguments must be of the same -floating-point type and the return type is the complex type +floating-point type and the return type is the +complex type with the corresponding floating-point constituents: complex64 for float32 arguments, and complex128 for float64 arguments. @@ -7897,7 +7901,7 @@ of constant size.

        The function Add adds len to ptr and returns the updated pointer unsafe.Pointer(uintptr(ptr) + uintptr(len)). -The len argument must be of integer type or an untyped constant. +The len argument must be of integer type or an untyped constant. A constant len argument must be representable by a value of type int; if it is an untyped constant it is given type int. The rules for valid uses of Pointer still apply. @@ -7920,7 +7924,7 @@ is nil and len is zero,

        -The len argument must be of integer type or an untyped constant. +The len argument must be of integer type or an untyped constant. A constant len argument must be non-negative and representable by a value of type int; if it is an untyped constant it is given type int. At run time, if len is negative,