# LibBF Library

## News

- Try LibBF online.
- New version with IEEE 754 semantics and transcendental
functions.
- A benchmark comparing MPFR/GMP and
LibBF.

## Introduction

LibBF is a small library to handle arbitrary precision floating point
numbers. Its compiled size is about 60 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
time.

The TinyPI example computes billions of digits of Pi using the
Chudnovsky formula.

Features:
- 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
flags).
- The basic arithmetic operations (addition, subtraction,
multiplication, division, square root) have a near linear running
time.
- 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.
- Trancendental 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)
are implemented.
- Easy to embed (a few C files need to be copied).
- MIT license.

## Download

Source code: libbf-2018-03-07.tar.gz.

Windows executables of TinyPI: tinypi-2018-02-03-win.zip.

TinyPI is also included in the RISCVEMU Javascript demo

## Related projects

Numcalc is an online arbitrary
precision calculator with Javascript syntax using LibBF.
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:
## Licensing

It is released under the MIT license.

Fabrice Bellard - http://bellard.org/