Created
November 9, 2018 17:20
-
-
Save nikhedonia/1401780c11c810005eb72b85a78c4218 to your computer and use it in GitHub Desktop.
This file contains 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 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