mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 05:30:33 +03:00
Fix issue 22771 - BigInt divMod can return "-0" (negative zero)
This commit is contained in:
parent
2629671c15
commit
1e30d05a3f
1 changed files with 9 additions and 1 deletions
10
std/bigint.d
10
std/bigint.d
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue