pub struct Ppm(/* private fields */);Expand description
A ratio in [0, 1] expressed as fixed-point parts-per-million.
Authoritative policy thresholds must not be floats: 0.25 is not representable identically in
every language/serializer, and a threshold comparison that differs by one ULP is a different
kernel decision. Ppm(250_000) is exact everywhere.
Ratios greater than 1.0 (e.g. an over-provisioning multiplier) need a distinct type with its
own bound; deliberately not invented here before a real callsite exists.
Implementations§
Source§impl Ppm
impl Ppm
pub const ZERO: Self
pub const ONE: Self
pub const MAX_PPM: u32 = 1_000_000
pub fn new(parts_per_million: u32) -> Result<Self, WireScalarError>
pub const fn get(self) -> u32
Sourcepub fn as_ratio(self) -> f64
pub fn as_ratio(self) -> f64
Observation/diagnostic projection only — never feed this back into a branch.
Sourcepub fn from_ratio(ratio: f64) -> Result<Self, WireScalarError>
pub fn from_ratio(ratio: f64) -> Result<Self, WireScalarError>
Convert a host-supplied ratio at the boundary (rounding to the nearest ppm). The float stops here: everything downstream compares integers.
Source§impl Ppm
impl Ppm
Sourcepub const fn from_ppm_const(parts_per_million: u32) -> Self
pub const fn from_ppm_const(parts_per_million: u32) -> Self
const-constructible ppm for compile-time baselines.
Ppm::new returns a Result and therefore cannot appear in a const initialiser, but
the kernel’s default policy table is a compile-time constant. Values above
Ppm::MAX_PPM saturate rather than panic: a default table that aborts the process at
startup would turn a typo into an outage, and saturation is still a legal ratio.