Bug 19514 – gcd(BigInt(2), BigInt(1)) fails

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-12-26T10:09:12Z
Last change time
2019-09-08T01:19:10Z
Keywords
pull
Assigned to
No Owner
Creator
Yui Hosaka

Comments

Comment #0 by hos — 2018-12-26T10:09:12Z
The following code fails: ---- import std.bigint, std.numeric, std.stdio; void main() { writeln(gcd(BigInt(2), BigInt(1))); } ---- Output: ---- core.exception.AssertError@/dlang/dmd/linux/bin64/../../src/phobos/std/numeric.d(2714): Assertion failure ---------------- ??:? _d_assertp [0xad2af111] /dlang/dmd/linux/bin64/../../src/phobos/std/numeric.d:2714 pure nothrow std.bigint.BigInt std.numeric.gcd!(std.bigint.BigInt).gcd(std.bigint.BigInt, std.bigint.BigInt) [0xad29f564] onlineapp.d:3 _Dmain [0xad29c683] ---- In general, gcd(a, b) for BigInts will fail when a has more zero bits at the end than b: ---- static if (canUseBinaryGcd) { uint shift = 0; while ((a & 1) == 0 && (b & 1) == 0) { a >>= 1; b >>= 1; shift++; } do { assert((a & 1) != 0); ----
Comment #1 by dlang-bot — 2019-09-07T19:42:13Z
@crocopaw created dlang/phobos pull request #7174 "Fix issue 19514 - gcd(BigInt(2), BigInt(1)) fails" fixing this issue: - Fix issue 19514 - gcd(BigInt(2), BigInt(1)) fails https://github.com/dlang/phobos/pull/7174
Comment #2 by dlang-bot — 2019-09-08T01:19:10Z
dlang/phobos pull request #7174 "Fix issue 19514 - gcd(BigInt(2), BigInt(1)) fails" was merged into master: - a21bfbdab6329dfe830856842ffd4993443c299f by Berni: Fix issue 19514 - gcd(BigInt(2), BigInt(1)) fails https://github.com/dlang/phobos/pull/7174