[OT] fastest fibbonacci

Andrea Fontana via Digitalmars-d digitalmars-d at puremagic.com
Mon Oct 24 01:54:38 PDT 2016


On Monday, 24 October 2016 at 08:20:26 UTC, Matthias Bentrup 
wrote:
> PS: the exact formula is fib(n) = 1/sqrt(5) * (0.5 + 
> 0.5sqrt(5))^n - 1/sqrt(5) * (0.5 - 0.5sqrt(5))^n. If you round 
> to integer anyway, the second term can be ignored as it is 
> always <= 0.5.

You can simply write it as:
round(phi^n/sqrt(5));

Check my example above :)


More information about the Digitalmars-d mailing list