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