From: Robert Griesemer +,
-, *, /) 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.
+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. +
+@@ -4857,10 +4888,10 @@ follows:
-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".
x < x + 1 is always true.
-
@@ -4931,7 +4961,6 @@ s += " and good bye" String addition creates a new string by concatenating the operands.
-@@ -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: