Skip to content

Instantly share code, notes, and snippets.

@SpineyPete
Created January 5, 2019 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SpineyPete/3d9817b1d8e97b57be2f8fe8bbbdeca2 to your computer and use it in GitHub Desktop.
Save SpineyPete/3d9817b1d8e97b57be2f8fe8bbbdeca2 to your computer and use it in GitHub Desktop.
fibonacci number formula (untested)
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