1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//! 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.
//!
//! [`dashu`]: https://docs.rs/dashu
//!
//! # 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}");
//! # Ok::<_, pallas_math::math::Error>(())
//! ```
//!
//! # Overview
//!
//! - [`math`] — the public surface: [`math::FixedDecimal`] (the
//! fixed-precision number type) and the [`math::FixedPrecision`] trait it
//! implements (`new`, `from_str`, `precision`, `exp`, `ln`, `pow`,
//! `exp_cmp`, `round` / `floor` / `ceil` / `trunc`).
//! - [`math_dashu`] — `dashu`-backed implementation that
//! [`math::FixedDecimal`] aliases.
//! - [`math::DEFAULT_PRECISION`] (34), and the lazy [`math::ZERO`],
//! [`math::ONE`], [`math::MINUS_ONE`] constants for convenience.
//!
//! # Usage as part of `pallas`
//!
//! `pallas-math` is not currently re-exported from the umbrella `pallas`
//! crate; depend on it directly.
/// Public surface: the [`math::FixedDecimal`] type, the [`math::FixedPrecision`] trait,
/// and the shared constants.
/// `dashu`-backed implementation of [`math::FixedPrecision`].