Skip to content

Commit ae1018c

Browse files
committed
Specify modulo with negative numbers
Signed-off-by: Dave Thaler <[email protected]>
1 parent 4cde694 commit ae1018c

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

isa/kernel.org/instruction-set.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,14 @@ where '(uint32_t)' indicates truncation to 32 bits.
240240
src = src ^ imm
241241

242242

243+
Also note that the modulo operation often varies by language
244+
when the dividend or divisor are negative, where Python, Ruby, etc.
245+
differ from C, Go, Java, etc. This specification requires that
246+
modulo use the widely accepted mathematical definition given by Donald
247+
Knuth and implemented in C, Go, etc.:
248+
249+
a % n = a - n * floor(a / n)
250+
243251
Byte swap instructions
244252
~~~~~~~~~~~~~~~~~~~~~~
245253

0 commit comments

Comments
 (0)