Expand description
Fixed-precision arithmetic for the parts of the Cardano protocol that
need ln, exp, and pow to high precision.
The Praos VRF leader-check formula and the reward / pool-saturation
calculations both require deterministic transcendental math; this crate
supplies it. Backed by dashu for the underlying big-integer
representation.
§Usage
use pallas_math::math::{FixedDecimal, FixedPrecision};
let x = FixedDecimal::from_str("2", 34)?; // 2.0 with 34 fractional digits
let y = x.ln(); // ≈ 0.6931471805599453…
println!("ln(2) ≈ {y}");§Overview
math— the public surface:math::FixedDecimal(the fixed-precision number type) and themath::FixedPrecisiontrait it implements (new,from_str,precision,exp,ln,pow,exp_cmp,round/floor/ceil/trunc).math_dashu—dashu-backed implementation thatmath::FixedDecimalaliases.math::DEFAULT_PRECISION(34), and the lazymath::ZERO,math::ONE,math::MINUS_ONEconstants for convenience.
§Usage as part of pallas
pallas-math is not currently re-exported from the umbrella pallas
crate; depend on it directly.
Modules§
- math
- Public surface: the
math::FixedDecimaltype, themath::FixedPrecisiontrait, and the shared constants. - math_
dashu dashu-backed implementation ofmath::FixedPrecision.