pi-generator
Pausable/resumable pi digits generator.
See the demo: https://betafcc.github.io/pi-generator
This module was made to demonstrate the new native BigInt fir JS.
Install
For node version > 10.x and latest Chrome:
npm install pi-generator
For older node and browsers, this equivalent package uses big-integer instead of the native BigInt:
npm install pi-generator-legacy
Usage
Print pi digits forever:
for const digit of console // 3// 1// 4// 1// 5// ...
Take some digits:
// generates first 5 digitsconst digits env = console // '31415'
Note there is an extra returned value, the 'environment' of the calculation:
console// { q: 622702080000000n,// r: -434409300281250n,// t: 213458046676875n,// k: 14n,// n: 6n,// l: 29n }
This is what makes possible to resume the digits expansion:
// generates the next 5 digits, continuing from 'env'const moreDigits nextEnv = console // '92653'
The stringify and parse functions are provided to save the calculation environment:
const digits env = // can store this one in a json file or wtvconst envString = // can parse and resume the expansion