-
-
Save skaslev/4312690 to your computer and use it in GitHub Desktop.
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
| #include <algorithm> | |
| #include <chrono> | |
| #include <cmath> | |
| #include <iostream> | |
| #define STR_(X) (#X) | |
| #define STR(X) (STR_(X)) | |
| #define ACTUAL 2.71828182845904523536028747135266249776 | |
| typedef long long int Int; | |
| typedef long double Real; | |
| typedef std::chrono::high_resolution_clock Clock; | |
| int main() { | |
| Real actual = ACTUAL; | |
| Real e = 1;//0 | |
| Int fact = 1; | |
| int i = 1;//0 | |
| auto t1 = Clock::now(); | |
| while (fact > 0) { | |
| fact *= i;//std::max(1, i); | |
| e += 1.0 / fact; | |
| ++i; | |
| } | |
| auto t2 = Clock::now(); | |
| std::cout.precision(50); | |
| std::cout | |
| << i << " iterations in " | |
| << (t2-t1).count() << " ns\n" | |
| << e << " computed\n" | |
| << STR(ACTUAL) << " actual_str\n" | |
| << actual << " actual\n" | |
| << std::abs(actual - e) << " error\n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment