Skip to content

Instantly share code, notes, and snippets.

@nmmmnu
Last active March 12, 2021 11:33
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 nmmmnu/fde1f0b7406372a3adbec9a72a3c61e6 to your computer and use it in GitHub Desktop.
Save nmmmnu/fde1f0b7406372a3adbec9a72a3c61e6 to your computer and use it in GitHub Desktop.
pi.2021.cc
#include <cstdio>
using myfloat = double;
constexpr size_t MAX = 2'500'000'000;
int main(){
myfloat sum = 0;
myfloat const four = 4;
for(size_t i = 0; i < MAX; ++i)
sum += 1 / (four * i + 1) - 1 / (four * i + 3);
myfloat const pi = sum * four;
printf("%f\n", pi);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment