Skip to content

Instantly share code, notes, and snippets.

@nikhedonia
Created November 9, 2018 17:20
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 nikhedonia/1401780c11c810005eb72b85a78c4218 to your computer and use it in GitHub Desktop.
Save nikhedonia/1401780c11c810005eb72b85a78c4218 to your computer and use it in GitHub Desktop.
double golden(double epsilon=0.00001) {
int a = 0;
int b = 1;
double ratio = 0;
while (1) {
tie(a, b) = tuple{b, a+b};
auto delta = b / (double)a - ratio;
ratio = b / (double)a;
cout << ratio << endl;
if ( abs(delta) < epsilon )
return ratio;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment