From: Robert Griesemer
-For integer values, /
and %
satisfy the following relationship:
+For two integer values x
and y
, the integer quotient
+q = x / y
and remainder r = x % y
satisfy the following
+relationships:
-(a / b) * b + a % b == a +x = q*y + r and |r| < |y|
-with (a / b)
truncated towards zero.
+with x / y
truncated towards zero
+("truncated division").
@@ -2827,6 +2830,20 @@ with (a / b)
truncated towards zero.
-5 -3 1 -2
+
+As an exception to this rule, if the dividend x
is the most
+negative value for the int type of x
, the quotient
+q = x / -1
is equal to x
(and r = 0
).
+
+ x, q +int8 -128 +int16 -32768 +int32 -2147483648 +int64 -9223372036854775808 ++
If the divisor is zero, a run-time panic occurs. If the dividend is positive and the divisor is a constant power of 2,