www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How can I write compile-time (pure) BigInt computations?

I would like to do some expensive BigInt computation at compile-time.

The basic arithmetic operations on BigInt seem to be impure, which
seems to make this impossible.

How can I work round this?

Thanks,

Chris.


gcd.d:

import std.stdio;
import std.bigint;

pure BigInt gcd(BigInt a, BigInt b) {=C2=A0 if (b =3D=3D 0) return a;=C2=A0=
 return
gcd(b, a % b);}
int main() {=C2=A0 BigInt n =3D "10000000000";=C2=A0 writefln("%s", gcd(cas=
t(BigInt)48, n));
=C2=A0 return 0;}
./gcd.d(6): Error: pure function 'gcd' cannot call impure function 'opBinar=
y'
Failed: dmd  -v -o- './gcd.d' -I'.' >./gcd.d.deps
Oct 25 2011