>>102447966
from decimal import *
def pi_bbp(n):
pi = Decimal(0)
k = 0
while k < n:
pi += (Decimal(1)/(16**k))*((Decimal(4)/(8*k+1))-(Decimal(2)/(8*k+4))-(Decimal(1)/(8*k+5))-(Decimal(1)/(8*k+6)))
k += 1
return pi
digits = 69420 # lol
print(f"Pi to {digits} digits:")
print(pi_bbp(digits))
also here's this
public class BaileyBorweinPlouffe {
private static final int DIGITS_PER_TERM = 8;
public static String piDigits(int digits) {
StringBuilder pi = new StringBuilder();
int[] a = {0, 0, 0, 0};
int[] d = {0, 0, 0, 0};
for (int k = 0; k < digits; k += DIGITS_PER_TERM) {
a[0] = 1; a[1] = 16; a[2] = 0; a[3] = 0;
d[0] = 5; d[1] = 80; d[2] = 0; d[3] = 0;
for (int j = 3; j <= k + DIGITS_PER_TERM; j++) {
int carry = 0;
for (int i = 3; i >= 0; i--) {
d[i] <<= 1;
a[i] <<= 1;
a[i] += carry;
carry = a[i] / 10;
a[i] %= 10;
}
}
int t = 0;
for (int i = 3; i >= 0; i--) {
t = t * 10 + a[i];
}
String digits8 = String.format("%08d", t);
pi.append(digits8);
}
return pi.substring(0, digits);
}
public static void main(String[] args) {
System.out.println(piDigits(1000000));
}
}