// BigNumber example: Calculate decimal digits of Pi using Gosper's series
// http://www.cs.ox.ac.uk/people/jeremy.gibbons/publications/spigot.pdf
// #include <BigNumber.h> // For a normal Arduino project
#include "BigNumber.h" // For Wokwi simulation
// variables
BigNumber q(1);
BigNumber r(180);
BigNumber t(60);
BigNumber i(2);
BigNumber u, y;
void setup() {
Serial1.begin(115200);
BigNumber::begin(0); // everything is integers throughout
}
void loop() {
// Gibbons' spigot
u = BigNumber(3) * (BigNumber(3) * i + BigNumber(1)) * (BigNumber(3) * i + BigNumber(2));
y = (q * (BigNumber(27) * i - BigNumber(12)) + BigNumber(5) * r) / (BigNumber(5) * t);
r = BigNumber(10) * u * (q * (BigNumber(5) * i - BigNumber(2)) + r - y * t);
q = BigNumber(10) * q * i * (BigNumber(2) * i - BigNumber(1));
t *= u;
Serial1.print(y);
if (i++ == 2)
Serial1.print('.');
}