How can I write compile-time (pure) BigInt computations?
Chris Dew
cmsdew at gmail.com
Tue Oct 25 05:31:19 PDT 2011
Stuck again, looks like BigInt doesn't work with CTFE for other reasons...
Is there a way to create BigInts at compile time (I've also tried from
a string)? Or is it back to C code generation in Python :-(
Thanks anyway,
Chris.
./gcd.d(11): Error: static variable N cannot be read at compile time
./gcd.d(11): Error: cannot evaluate gcd((BigInt __ctmp1335;
, __ctmp1335).this(48),N) at compile time
Failed: dmd -v -o- './gcd.d' -I'.' >./gcd.d.deps
import std.stdio;
import std.bigint;
T gcd(T)(T a, T b) {
if (b == 0) return a;
return gcd(b, a % b);
}
BigInt N = cast(BigInt)1000000000L;
BigInt X = gcd(cast(BigInt)48, N);
int main() {
writefln("%s", X);
return 0;
}
More information about the Digitalmars-d
mailing list