Skip to content

High-performance, multi-threaded PI digit calculator using the Chudnovsky algorithm and GMP/MPFR with binary splitting.

License

Notifications You must be signed in to change notification settings

harispdev/high-precision-pi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

High-precision PI digit calculator

Build License: MIT

This project implements a high-performance π digit calculator using the Chudnovsky algorithm with binary splitting, multi-threading, and arbitrary-precision arithmetic via GMP and MPFR. It is capable of computing tens of thousands (or more) digits of PI efficiently and accurately.


📌 Features:

  • Chudnovsky algorithm (fastest known formula for PI digit generation)
  • Binary splitting for efficient recursive term combination
  • Multi-threaded execution with system-aware thread limiting
  • Signal-safe and interruptible (Ctrl+C gracefully terminates computation)
  • Dynamic precision scaling based on actual operand bit size
  • CLI progress bar and execution time reporting
  • Verified accuracy up to 100,000 digits and beyond

📷 Example output:

[INFO] Computing π with 100 digits using up to 8 threads...
[INFO] Progress:
[##################################################] 100%
[INFO] Combining results... (this may take a while)
[INFO] Using MPFR precision: 2250498 bits (T: 2045908 bits, Q: 2045884 bits)
3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798e0
[INFO] Finished in 0.081 seconds.

⚙️ Dependencies

Runtime libraries are installed automatically via Docker. If you wish to build locally, you will need:

  • GMP (libgmp)
  • MPFR (libmpfr)

On macOS:

brew install gmp mpfr

On Ubuntu/Debian:

sudo apt-get install libgmp-dev libmpfr-dev

🚀 Building and running

Run with Docker:

docker build -t pi-chud .
docker run --rm pi-chud

💡 Redirecting output to a file is recommended for large digit counts.


⚡ Performance Notes

  • Uses dynamic precision detection based on actual intermediate operand sizes to avoid floating-point inaccuracies.
  • Works well with up to 100,000+ digits on machines with at least 8 GB of RAM.
  • Performance scales with number of CPU cores, thanks to safe use of pthread and semaphores.
  • Graceful handling of interrupt signals makes it safe for long-running sessions.

🤔 Why this project matters

This project demonstrates:

  • Mastery of advanced numerical methods
  • Practical multithreading and synchronization
  • Dynamic memory management with zero leaks
  • Safe integration of C libraries (GMP, MPFR)
  • Attention to runtime efficiency and robustness

It is ideal for showcasing low-level performance engineering, numerical programming, and modern C software practices in real-world high-precision computation.


📄 License

This project is open-source and available under the MIT License.

About

High-performance, multi-threaded PI digit calculator using the Chudnovsky algorithm and GMP/MPFR with binary splitting.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published