Created
March 14, 2020 10:04
-
-
Save nmmmnu/ec7e631d36763a20338fc4d8d5c793d0 to your computer and use it in GitHub Desktop.
PI day 2020
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
#include <cstdio> | |
using myfloat = double; | |
constexpr size_t MAX = 500'000'000; | |
int main(){ | |
myfloat pi = 0; | |
myfloat sign = +1; | |
myfloat denominator = 1; | |
for(size_t i = 0; i < MAX; ++i){ | |
pi += sign * ( 4 / denominator); | |
denominator += 2; | |
sign *= -1; | |
} | |
printf("%f\n", pi); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment