www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5928] New: bigint modulo problem

reply d-bugmail puremagic.com writes:
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 puremagic.com
        ReportedBy: dpx.infinity gmail.com



---
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: -------
May 05 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5928


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED



This one is critical, so it's included in 2.053.

https://github.com/D-Programming-Language/phobos/commit/cca0bc8971bee225f13c67541bbdd3e5c7dcffe6

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