Skip to main content

DecimalConsts

Trait DecimalConsts 

Source
pub trait DecimalConsts: Sized {
    // Required methods
    fn pi() -> Self;
    fn tau() -> Self;
    fn half_pi() -> Self;
    fn quarter_pi() -> Self;
    fn golden() -> Self;
    fn e() -> Self;
}
Expand description

Well-known mathematical constants available on every decimal width (D9 / D18 / D38 / D76 / D153 / D307).

Import this trait to call D38s12::pi(), D76::<35>::e(), etc.

All returned values are computed from a raw integer reference at the tier’s maximum storage precision (75 digits for D9/D18/D38 and D76; 153 for D153; 307 for D307) without passing through f64, then rescaled down to the caller’s SCALE with half-to-even rounding. The result is within 0.5 ULP of the canonical decimal expansion at every supported scale on every width.

The one situation where a method does not return a value is when the constant’s magnitude exceeds the type’s storage range at the caller’s SCALE — e.g. D38<38>::pi() would need 3.14 × 10³⁸, which exceeds i128::MAX ≈ 1.7×10³⁸. The method panics with a clear “constant out of storage range” message in that case.

Required Methods§

Source

fn pi() -> Self

Pi (~3.14159265…). One half-turn in radians.

Source: ISO 80000-2 / OEIS A000796. Rescaled per-tier (see the module-level table) to the caller’s SCALE via the crate-default rounding mode.

§Precision

N/A: constant value, no arithmetic performed.

Source

fn tau() -> Self

Tau (~6.28318530…). One full turn in radians.

Defined as 2 * pi. Rescaled per-tier (see the module-level table) to the caller’s SCALE via the crate-default rounding mode.

§Precision

N/A: constant value, no arithmetic performed.

Source

fn half_pi() -> Self

Half-pi (~1.57079632…). One quarter-turn in radians.

Defined as pi / 2. Rescaled per-tier (see the module-level table) to the caller’s SCALE via the crate-default rounding mode.

§Precision

N/A: constant value, no arithmetic performed.

Source

fn quarter_pi() -> Self

Quarter-pi (~0.78539816…). One eighth-turn in radians.

Defined as pi / 4. Rescaled per-tier (see the module-level table) to the caller’s SCALE via the crate-default rounding mode.

§Precision

N/A: constant value, no arithmetic performed.

Source

fn golden() -> Self

The golden ratio (~1.61803398…). Dimensionless.

Defined as (1 + sqrt(5)) / 2. Source: OEIS A001622. Rescaled per-tier (see the module-level table) to the caller’s SCALE via the crate-default rounding mode.

§Precision

N/A: constant value, no arithmetic performed.

Source

fn e() -> Self

Euler’s number (~2.71828182…). Dimensionless.

Source: OEIS A001113. Rescaled per-tier (see the module-level table) to the caller’s SCALE via the crate-default rounding mode.

§Precision

N/A: constant value, no arithmetic performed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<const SCALE: u32> DecimalConsts for D9<SCALE>

Source§

impl<const SCALE: u32> DecimalConsts for D18<SCALE>

Source§

impl<const SCALE: u32> DecimalConsts for D38<SCALE>

Source§

impl<const SCALE: u32> DecimalConsts for D56<SCALE>

Available on crate features d56 or wide only.
Source§

impl<const SCALE: u32> DecimalConsts for D76<SCALE>

Available on crate features d76 or wide only.
Source§

impl<const SCALE: u32> DecimalConsts for D114<SCALE>

Available on crate features d114 or wide only.
Source§

impl<const SCALE: u32> DecimalConsts for D153<SCALE>

Available on crate features d153 or wide only.
Source§

impl<const SCALE: u32> DecimalConsts for D230<SCALE>

Available on crate features d230 or wide only.
Source§

impl<const SCALE: u32> DecimalConsts for D307<SCALE>

Available on crate features d307 or wide or x-wide only.
Source§

impl<const SCALE: u32> DecimalConsts for D461<SCALE>

Available on crate features d461 or x-wide only.
Source§

impl<const SCALE: u32> DecimalConsts for D615<SCALE>

Available on crate features d615 or x-wide only.
Source§

impl<const SCALE: u32> DecimalConsts for D923<SCALE>

Available on crate features d923 or xx-wide only.
Source§

impl<const SCALE: u32> DecimalConsts for D1231<SCALE>

Available on crate features d1231 or xx-wide only.