Benchmark games, Rust, big ints and Pi
bearophile via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Oct 20 00:03:31 PDT 2014
John Carter:
> Your paste has expired / no longer there.... but the subject
> has come up again...
> ...
> Do you still have your implementation hanging around?
I think it was this. *Untested*:
void main(string[] args) {
import core.stdc.stdio, std.bigint, core.stdc.stdlib;
immutable n = (args.length == 2) ? args[1].ptr.atoi : 100;
BigInt acc, den = 1, num = 1;
for (uint i, k; i < n; ) {
immutable k2 = ++k * 2U + 1U;
acc = (acc + num * 2U) * k2;
den *= k2;
num *= k;
if (num > acc)
continue;
immutable d = ((num * 3 + acc) / den) % 10U;
if (d != ((num * 4 + acc) / den) % 10U)
continue;
putchar('0' + d);
if (++i % 10 == 0)
printf("\t:%u\n", i);
acc = (acc - den * d) * 10U;
num *= 10U;
}
}
Bye,
bearophile
More information about the Digitalmars-d-learn
mailing list