Skip to content

Commit

Permalink
Fix issue 22771 - BigInt divMod can return "-0" (negative zero)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored and dlang-bot committed Feb 14, 2022
1 parent 2629671 commit 1e30d05
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion std/bigint.d
Expand Up @@ -2244,7 +2244,7 @@ void divMod(const BigInt dividend, const BigInt divisor, out BigInt quotient, ou
BigUint.divMod(dividend.data, divisor.data, q, r);
quotient.sign = dividend.sign != divisor.sign;
quotient.data = q;
remainder.sign = dividend.sign;
remainder.sign = r.isZero() ? false : dividend.sign;
remainder.data = r;
}

Expand Down Expand Up @@ -2291,6 +2291,14 @@ void divMod(const BigInt dividend, const BigInt divisor, out BigInt quotient, ou
assert(q * d + r == -c);
}

// https://issues.dlang.org/show_bug.cgi?id=22771
@safe pure nothrow unittest
{
BigInt quotient, remainder;
divMod(BigInt(-50), BigInt(1), quotient, remainder);
assert(remainder == 0);
}

// https://issues.dlang.org/show_bug.cgi?id=19740
@safe unittest
{
Expand Down

0 comments on commit 1e30d05

Please sign in to comment.