natevw / pi-spig-rs

Learning Rust via a classic spigot algorithm for the digits of Pi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Pi Spigot in Rust

This is ± the classic Rabinowitz and Wagon (pdf) spigot algorithm which streams out a fixed number of Pi digits as it calculates them.

Background

A few years ago I wrote a Python version of this using https://www.cut-the-knot.org/Curriculum/Algorithms/SpigotForPi.shtml as a reference. For now I have for the most part simply ported that version into Rust (which I am learning — this being my first successful endeavor in the language) despite some of its idiosyncracies.

Now that this new Rust version is at least basically working for some initial dozens of digits, I hope to make some refinements to align it better with "the literature" and other optimizations including some noted in the book /Pi Unleashed/ (Arndt and Haenel, 2001, pp. 75–85) which I now have a copy of.

My ultimate intent — perhaps for another year's Pi day — is actually to split up the calculation between parallel processes, such that the carries also can be streamed from separate CPUs (whether multiple cores or even separate clustered machines) and maybe generate a little faster. But at least to get a little supercomputer (or rather, a "little supercomputer") experience.

See also

This isn't the fastest way to calculate a kajillion digits of Pi; it just looked like a fun one to play with. Besides the links above, here's some further reading I've found on related to this algorithm:

License

© 2023 Nathan Vander Wilt.

Shared under MIT license terms.

About

Learning Rust via a classic spigot algorithm for the digits of Pi


Languages

Language:Rust 72.4%Language:Python 27.6%