Function ulp

Source
fn ulp<F: FixedPointNumber>() -> F
where F::Inner: From<u8>,
Expand description

Returns the smallest positive increment representable by the fixed-point generic [FixedPointNumber].

For a fixed-point number defined as:

value = inner / DIV

the ULP equals 1 / DIV.

§Behavior

  • Uses FixedPoint::from_inner(1) to construct the smallest step value.
  • Useful as a numerical tolerance in convergence or rounding checks.

§Example

let ulp_val = ulp::<FixedU128>();
assert_eq!(ulp_val, FixedU128::from_inner(1)); // represents 1e-18 if DIV = 1e18

§Notes

  • The exact decimal size of the ULP depends on FixedPoint::DIV.
  • If DIV = 10^6, then ULP = 1e-6.
  • Works for all fixed-point types whose Inner implements From<u8>.