Bug 18434 – BigInt gcd asserts when one argument is zero.

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-02-13T19:50:50Z
Last change time
2018-02-16T20:06:44Z
Keywords
pull
Assigned to
No Owner
Creator
hsteoh

Comments

Comment #0 by hsteoh — 2018-02-13T19:50:50Z
Code: ------ import std.bigint; import std.numeric; void main() { auto g1 = gcd(0, 1); // OK auto g2 = gcd(BigInt(0), BigInt(1)); // NG } ------ Output: ------ core.exception.AssertError@/usr/src/d/phobos/std/numeric.d(2699): Assertion failure ---------------- ??:? _d_assertp [0xc9cf7171] ??:? pure nothrow std.bigint.BigInt std.numeric.gcd!(std.bigint.BigInt).gcd(std.bigint.BigInt, std.bigint.BigInt) [0xc9cf5770] ??:? _Dmain [0xc9cf5079] ------ The offending line in std.numeric is in the `static if (canUseBinaryGcd)` block, in the do-loop: ----- assert((a & 1) != 0); -----
Comment #1 by hsteoh — 2018-02-13T20:02:33Z
Comment #2 by github-bugzilla — 2018-02-16T20:06:43Z
Commits pushed to master at https://github.com/dlang/phobos https://github.com/dlang/phobos/commit/fb66d07b769111664d648b5d4eb0a96d8c3e3101 Fix issue 18434: gcd(BigInt(0), BigInt(1)) fails The special cases of `gcd(0,a)` and `gcd(a,0)` are not handled correctly when `BigInt`s are involved. https://github.com/dlang/phobos/commit/ffc96fd90dceb753b5066ca09524caa5fb1f3ffa Merge pull request #6170 from quickfur/issue18434 Fix issue 18434: gcd(BigInt(0), BigInt(1)) fails merged-on-behalf-of: Jack Stouffer <[email protected]>