diff --git a/doc/go_spec.html b/doc/go_spec.html index c0ed27730f..751d7fea01 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -4752,7 +4752,7 @@ 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 stringscomplex types; + also applies to strings. The bitwise logical and shift operators apply to integers only.

@@ -4772,6 +4772,37 @@ The bitwise logical and shift operators apply to integers only. >> right shift integer >> integer >= 0 +

+Excluding shifts, if the operand type is a type parameter, +it must have specific types, and the operator must +apply to each specific type. +The operands are represented as values of the type argument that the type parameter +is instantiated with, and the operation is computed +with the precision of that type argument. For example, given the function: +

+ +
+func dotProduct[F ~float32|~float64](v1, v2 []F) F {
+	var s F
+	for i, x := range v1 {
+		y := v2[i]
+		s += x * y
+	}
+	return s
+}
+
+ +

+the the product x * y and the addition s += x * y +are computed with float32 or float64 precision, +respectively, depending on the type argument for F. +

+ +

+For shifts, the core type of both operands must be +an integer. +

+

Integer operators

@@ -4857,10 +4888,10 @@ follows:

Integer overflow

-For unsigned integer values, the operations +, +For unsigned integer values, the operations +, -, *, and << are computed modulo 2n, where n is the bit width of -the unsigned integer's type. +the unsigned integer's type. Loosely speaking, these unsigned integer operations discard high bits upon overflow, and programs may rely on "wrap around".

@@ -4875,7 +4906,6 @@ A compiler may not optimize code under the assumption that overflow does not occur. For instance, it may not assume that x < x + 1 is always true.

-

Floating-point operators

@@ -4931,7 +4961,6 @@ s += " and good bye" String addition creates a new string by concatenating the operands.

-

Comparison operators

@@ -5220,7 +5249,7 @@ string(65.0) // illegal: 65.0 is not an integer constant

Converting a constant to a type parameter yields a non-constant value of that type, with the value represented as a value of the type argument that the type parameter -is instantiated with. +is instantiated with. For example, given the function: