mirror of
https://github.com/dlang/phobos.git
synced 2025-05-02 08:00:48 +03:00
Fix issue 20924
This commit is contained in:
parent
d4bb2846e1
commit
653e0e8e86
1 changed files with 63 additions and 48 deletions
|
@ -2987,13 +2987,18 @@ if (isIntegral!T)
|
|||
// This overload is for non-builtin numerical types like BigInt or
|
||||
// user-defined types.
|
||||
/// ditto
|
||||
T gcd(T)(T a, T b)
|
||||
auto gcd(T)(T a, T b)
|
||||
if (!isIntegral!T &&
|
||||
is(typeof(T.init % T.init)) &&
|
||||
is(typeof(T.init == 0 || T.init > 0)))
|
||||
{
|
||||
static if (!is(T == Unqual!T))
|
||||
{
|
||||
return gcd!(Unqual!T)(a, b);
|
||||
}
|
||||
else
|
||||
{
|
||||
import std.algorithm.mutation : swap;
|
||||
|
||||
enum canUseBinaryGcd = is(typeof(() {
|
||||
T t, u;
|
||||
t <<= 1;
|
||||
|
@ -3046,6 +3051,7 @@ if (!isIntegral!T &&
|
|||
}
|
||||
return a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://issues.dlang.org/show_bug.cgi?id=7102
|
||||
|
@ -3085,6 +3091,15 @@ if (!isIntegral!T &&
|
|||
assert(gcd(BigInt(2), BigInt(1)) == BigInt(1));
|
||||
}
|
||||
|
||||
// Issue 20924
|
||||
@safe unittest
|
||||
{
|
||||
import std.bigint : BigInt;
|
||||
const a = BigInt("123143238472389492934020");
|
||||
const b = BigInt("902380489324729338420924");
|
||||
assert(__traits(compiles, gcd(a, b)));
|
||||
}
|
||||
|
||||
// This is to make tweaking the speed/size vs. accuracy tradeoff easy,
|
||||
// though floats seem accurate enough for all practical purposes, since
|
||||
// they pass the "approxEqual(inverseFft(fft(arr)), arr)" test even for
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue