[Issue 13963] BigInt modulo ulong is rejected

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Jan 25 01:37:47 PST 2015


https://issues.dlang.org/show_bug.cgi?id=13963

--- Comment #4 from mfx <markus at oberhumer.com> ---
This patch seems to fix the issue for me. The unittest will still have to get
updated.

--- dmd-phobos.git/std/bigint.d 2015-01-25 06:45:36.000000000 +0100
+++ bigint.d    2015-01-25 10:34:57.000000000 +0100
@@ -157,6 +157,8 @@
             }
             // x%y always has the same sign as x.
             // This is not the same as mathematical mod.
+            if (data.isZero())
+                sign = false;
         }
         else static if (op==">>" || op=="<<")
         {
@@ -279,6 +281,14 @@
                 return r;
             }
         }
+        else static if (is(Unqual!T == uint))
+        {
+            uint u = absUnsign(y);
+            long rem = BigUint.modInt(data, u);
+            // x%y always has the same sign as x.
+            // This is not the same as mathematical mod.
+            return sign ? -rem : rem;
+        }
         else
         {
             uint u = absUnsign(y);

--


More information about the Digitalmars-d-bugs mailing list