[Issue 20924] New: std.numeric.gcd cannot be used with const BigInt
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jun 12 22:50:24 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20924
Issue ID: 20924
Summary: std.numeric.gcd cannot be used with const BigInt
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: phobos
Assignee: nobody at puremagic.com
Reporter: hsteoh at quickfur.ath.cx
Code:
----------
import std.bigint;
import std.numeric;
import std.stdio;
void main() {
const a = BigInt("123143238472389492934020");
const b = BigInt("902380489324729338420924");
writeln(gcd(a, b));
}
----------
Compiler output:
----------
/usr/src/d/phobos/std/numeric.d(3044): Error: template
std.bigint.BigInt.opAssign cannot deduce function from argument types
!()(BigInt) const, candidates are:
/usr/src/d/phobos/std/bigint.d(178): opAssign(T)(T x)
/usr/src/d/phobos/std/bigint.d(194): opAssign(T : BigInt)(T x)
/usr/src/d/phobos/std/numeric.d(3045): Error: template
std.bigint.BigInt.opAssign cannot deduce function from argument types
!()(const(BigInt)) const, candidates are:
/usr/src/d/phobos/std/bigint.d(178): opAssign(T)(T x)
/usr/src/d/phobos/std/bigint.d(194): opAssign(T : BigInt)(T x)
test.d(7): Error: template instance std.numeric.gcd!(const(BigInt)) error
instantiating
----------
There's no reason why const BigInt shouldn't work with gcd, since gcd doesn't
(shouldn't!) modify its arguments, and the following does work:
----------
import std.bigint;
//import std.numeric; // NG
import std.stdio;
// Copy-n-pasted code from std.numeric.gcd
BigInt gcd(in BigInt a, in BigInt b) {
BigInt ua = a;
BigInt ub = b;
while (ub)
{
auto t = ub;
ub = ua % ub;
ua = t;
}
return ua;
}
void main() {
const a = BigInt("123143238472389492934020");
const b = BigInt("902380489324729338420924");
writeln(gcd(a, b));
}
----------
Program output: 12
--
More information about the Digitalmars-d-bugs
mailing list