Bug 5928 – bigint modulo problem

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
Linux
Creation time
2011-05-05T02:37:00Z
Last change time
2011-05-10T14:11:25Z
Assigned to
nobody
Creator
dpx.infinity

Comments

Comment #0 by dpx.infinity — 2011-05-05T02:37:57Z
Code foreach (long n; -5 .. 6) { writefln("%2s %% %2s = %2s, %2s, %2s, %2s", n, 5, n % 5, n % BigInt(5), BigInt(n) % 5, BigInt(n) % BigInt(5)); } outputs (note the second result column) -5 % 5 = 0, 1, 0, 0 -4 % 5 = -4, 2, -4, -4 -3 % 5 = -3, 3, -3, -3 -2 % 5 = -2, 4, -2, -2 -1 % 5 = -1, 0, -1, -1 0 % 5 = 0, 0, 0, 0 1 % 5 = 1, 1, 1, 1 2 % 5 = 2, 2, 2, 2 3 % 5 = 3, 3, 3, 3 4 % 5 = 4, 4, 4, 4 5 % 5 = 0, 0, 0, 0 Clearly, that's not like the modulo should work on negative numbers - there is no way that 0 could be the remainder of the divison of -1 by 5. There is similar behavior on other modulos. I tested this using DMD 2.052 on x86 and x86_64 linux systems.
Comment #1 by clugdbug — 2011-05-10T14:11:25Z