Expand description
A Rust translation of Fabrice Bellard’s libbf, a tiny arbitrary precision floating point library.
The two main value types are BigFloat (arbitrary precision binary
floating point, corresponding to libbf’s bf_t) and BigDecimal
(arbitrary precision decimal floating point, corresponding to bfdec_t).
Type-level format wrappers Float<F> and Decimal<F> pair a value
with a StaticFormat so that arithmetic operators automatically apply
the correct precision and rounding mode.
Features include basic arithmetic, fused multiply-add, square root, transcendental functions (exp, log, pow, trig), and parsing/formatting in arbitrary radices (2–36).
The crate is no_std compatible (requires alloc).
§Aliasing-safe in-place operations
libbf’s C API allows aliased pointers — the same bf_t * can appear as
both the output and one (or both) inputs of an operation. Rust’s borrow
rules forbid this: self.mul_assign(&self, …) would require &mut self
and &self simultaneously. Three dedicated method families fill the gap:
| Method | Computes | libbf pattern |
|---|---|---|
sqr / sqr_assign | self * self | bf_mul(r, a, a, …) |
rsub_assign | lhs - self (reverse sub) | bf_sub(r, a, r, …) |
rdiv_assign | dividend / self (reverse div) | bf_div(r, a, r, …) |
The “reverse” variants are only needed for the non-commutative operations
(subtraction, division), where r == b produces a different result from
r == a. Addition and multiplication are commutative, so their existing
_assign methods already cover the r == b case.
Re-exports§
pub use decimal::BigDecimal;pub use decimal::Decimal;pub use float::BigFloat;pub use float::DivRemMode;pub use float::Float;pub use float::FpCategory;pub use float::Integer;pub use float::Sign;pub use format::formats;pub use format::mul_log2_radix;pub use format::BigFormat;pub use format::DecimalFormat;pub use format::ExpBits;pub use format::Format;pub use format::NoRadixPointPrec;pub use format::NoSubnormal;pub use format::Precision;pub use format::RadixPointPrec;pub use format::Rounding;pub use format::StaticFormat;pub use format::StaticRadixPointPrecision;pub use format::StaticRounding;pub use format::StaticSubnormal;pub use format::Subnormal;pub use status::Status;