Created
January 5, 2019 17:51
-
-
Save SpineyPete/3d9817b1d8e97b57be2f8fe8bbbdeca2 to your computer and use it in GitHub Desktop.
fibonacci number formula (untested)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double fib(int n) { | |
const double sqrt5 = sqrt(5); | |
const double phi_a = (1 + sqrt5)/2; | |
const double phi_b = (1 - sqrt5)/2; | |
return (pow(phi_a, n) - pow(phi_b, n))/sqrt5; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment