TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
/= (division assignment) operator is a compound assignment operator in Go that divides the current value of the left-hand operand by the value of the right-hand operand, assigning the computed quotient back to the left-hand operand.
x = x / (y), but enforces two critical semantic rules:
- Single Evaluation: The left-hand operand
xis evaluated exactly once. If the left-hand operand contains a function call or side effect (e.g.,slice[i()] /= y), the functioni()is executed only once. In the expanded formslice[i()] = slice[i()] / (y),i()would be executed twice. - Operator Precedence: The right-hand operand
yis evaluated as a fully parenthesized expression. For example,x /= a + bdividesxby the sum(a + b). The expanded form without parentheses,x = x / a + b, would incorrectly dividexbyaand then addb.
Technical Characteristics
Type Constraints The operator requires both operands to resolve to the same numeric type (integer, floating-point, or complex). Because Go does not perform implicit type coercion between distinct variable types, attempting to use/= with mismatched typed variables (e.g., an int left operand and a float64 right operand) results in a compile-time error. However, if the right-hand operand is an untyped constant, it is implicitly converted to the type of the left-hand operand, provided the constant is representable by that type.
Integer Evaluation
When applied to integer types (int, int8, uint32, etc.), the underlying division operation truncates the fractional part towards zero. The assigned result is always an integer.
Floating-Point Evaluation
When applied to floating-point types (float32, float64), the operation retains the fractional quotient and adheres to IEEE 754 standard arithmetic.
Division by Zero Behavior
- Constant Zero: Dividing by a constant zero (both integer
0and floating-point0.0) is a compile-time error (division by zero). - Runtime Integer Zero: If the right-hand operand is an integer variable that evaluates to
0at runtime, the operation triggers a runtime panic (panic: runtime error: integer divide by zero). - Runtime Floating-Point Zero: If the right-hand operand is a floating-point variable that evaluates to
0.0at runtime, the operation does not panic. Instead, it assigns positive infinity (+Inf), negative infinity (-Inf), or Not-a-Number (NaN) to the left operand, depending on whether the left operand is positive, negative, or zero, respectively.
Syntax Visualization
Master Go with Deep Grasping Methodology!Learn More





