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§
Sourcefn pi() -> Self
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.
Sourcefn tau() -> Self
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.
Sourcefn half_pi() -> Self
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.
Sourcefn quarter_pi() -> Self
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.
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§
impl<const SCALE: u32> DecimalConsts for D9<SCALE>
impl<const SCALE: u32> DecimalConsts for D18<SCALE>
impl<const SCALE: u32> DecimalConsts for D38<SCALE>
impl<const SCALE: u32> DecimalConsts for D56<SCALE>
d56 or wide only.impl<const SCALE: u32> DecimalConsts for D76<SCALE>
d76 or wide only.impl<const SCALE: u32> DecimalConsts for D114<SCALE>
d114 or wide only.impl<const SCALE: u32> DecimalConsts for D153<SCALE>
d153 or wide only.impl<const SCALE: u32> DecimalConsts for D230<SCALE>
d230 or wide only.impl<const SCALE: u32> DecimalConsts for D307<SCALE>
d307 or wide or x-wide only.impl<const SCALE: u32> DecimalConsts for D461<SCALE>
d461 or x-wide only.impl<const SCALE: u32> DecimalConsts for D615<SCALE>
d615 or x-wide only.impl<const SCALE: u32> DecimalConsts for D923<SCALE>
d923 or xx-wide only.impl<const SCALE: u32> DecimalConsts for D1231<SCALE>
d1231 or xx-wide only.