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);
-----