On Wednesday, 6 December 2017 at 10:00:48 UTC, Biotronic wrote:
On Wednesday, 6 December 2017 at 09:12:08 UTC, helxi wrote:
[...]
Here's my version:, based on fast squaring:
auto fib(ulong n) {
import std.bigint : BigInt;
import std.meta : AliasSeq;
import std.typecons : tuple;
BigInt a = 0;
BigInt b = 1;
auto bit = 63;
while (bit > 0) {
AliasSeq!(a, b) = tuple(
a * (2*b - a),
a*a + b*b);
[...]
Nice. But why the AliasSeq?
That's because the poor compiler isn't as good at optimizing
compile-time code as run-time code,
Oh I see. We should definitely be careful with that :D