Skip to content

Instantly share code, notes, and snippets.

@Wunkolo
Created February 4, 2015 02:12
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 Wunkolo/f005f3abb5d5c5fe95a7 to your computer and use it in GitHub Desktop.
Save Wunkolo/f005f3abb5d5c5fe95a7 to your computer and use it in GitHub Desktop.
Pi Approximation
// Pi approximatization
//http://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80
//Slow conversion...
#include <stdint.h>
#include <stdio.h>
int main()
{
double result = 0;
for( size_t k = 1; k <= 1000000; k++ )
{
result += ((k & 1 ? 1.0 : -1.0) / double((k << 1) - 1));
}
result *= 4;
printf("%.10lf\n", result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment