- New version with decimal floating point support.
- Try LibBF online.
- A benchmark comparing MPFR/GMP and
LibBF is a small library to handle arbitrary precision floating point
numbers. Its compiled size is about 90 KB of x86 code and has no
dependency on other libraries. It is not the fastest library nor the
smallest but it tries to be simple while using asymptotically optimal
algorithms. The basic arithmetic operations have a near linear running
The TinyPI example computes billions of digits of Pi using the
- Arbitrary precision floating point numbers in base 2 using
the IEEE 754
semantics (including subnormal numbers, infinities and NaN).
- All operations are exactly rounded using the 5 IEEE 754 rounding
modes (round to nearest with ties to even or away from zero, round
to zero, -/+ infinity). The additional non-deterministic faithful
rounding mode is supported when a lower or deterministic running
time is necessary.
- Stateless API (each function takes as input the rounding mode,
mantissa and exponent precisions in bits and return the IEEE status
- The basic arithmetic operations (addition, subtraction,
multiplication, division, square root) have a near linear running
- Multiplication using a SIMD optimized Number Theoretic Transform.
- Exactly rounded floating point input and output in any base between
2 and 36 with near linear runnning time. Floating point output can
select the smallest amount of digits to get the required precision.
- Transcendental functions are supported (exp, log, pow, sin, cos, tan,
asin, acos, atan, atan2).
- Operations on arbitrarily large integers are supported by using a
special "infinite" precision. Integer division with remainder and
logical operations (assuming two complement binary representation)
- Arbitrary precision floating point numbers in base 10 corresponding
to the IEEE 754 2008 semantics with the limitation that the mantissa
is always normalized. The basic arithmetic operations, output and
input are supported with a quadratic running time.
- Easy to embed: a few C files need to be copied, the memory
allocator can be redefined, the memory allocation failures are
- MIT license.
Source code: libbf-2020-01-19.tar.gz.
Windows executables of TinyPI: tinypi-2018-02-03-win.zip.
QuickJS relies on LibBF to handle the BigInt,
BigFloat and BigDecimal numbers.
Arbitrary precision floating point libraries:
Other small open source programs to compute large number of digits of PI:
Larger and faster programs to compute PI:
It is released under the MIT license.
Fabrice Bellard - http://bellard.org/