[Issue 5928] New: bigint modulo problem

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 5 02:41:51 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5928

           Summary: bigint modulo problem
           Product: D
           Version: D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: dpx.infinity at gmail.com


--- Comment #0 from Vladimir <dpx.infinity at gmail.com> 2011-05-05 02:37:57 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list