Skip to content

Instantly share code, notes, and snippets.

@nmmmnu
Created March 14, 2020 10:04
Show Gist options
  • Save nmmmnu/ec7e631d36763a20338fc4d8d5c793d0 to your computer and use it in GitHub Desktop.
Save nmmmnu/ec7e631d36763a20338fc4d8d5c793d0 to your computer and use it in GitHub Desktop.
PI day 2020
#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