Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 22771 - BigInt divMod can return "-0" (negative zero) #8379

Merged
merged 1 commit into from Feb 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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