Open main menu

CDOT Wiki β

Changes

Team Titans

489 bytes added, 04:18, 15 October 2015
Calculation of Pi
I decided on finding a technique which is the most efficient way to calculate pi. I found one way of doing this on http://www.codecodex.com/wiki/Calculate_digits_of_pias seen below. By parallelizing the code, it could reduce the computation time considerably. void pi_digits(int digits) { int carry = 0; int arr[digits + 1]; for (int i = 0; i <= digits; ++i) arr[i] = ARRINIT; for (int i = digits; i > 0; i-= 14) { int sum = 0; for (int j = i; j > 0; --j) { sum = sum * j + SCALE * arr[j]; arr[j] = sum % (j * 2 - 1); sum /= j * 2 - 1; } printf("%04d", carry + sum / SCALE); carry = sum % SCALE; } }
After profiling, I get the following results: