Skip to main content

Module precision_boundary

Module precision_boundary 

Source
Expand description

Precision boundary between FinancialValue (Decimal) and StatisticalValue (f64).

Every crossing between the two representations passes through one of the two checked helpers in this module. Silent fallbacks (d.to_f64().unwrap_or(0.0), Decimal::try_from(f).unwrap_or(Decimal::ONE)) are forbidden by the specs/precision/financial-precision-boundary.md published-language spec in qbot-core — every caller must propagate the error or surface it.

§When to use

  • decimal_to_f64_checked: entering a statistical kernel (covariance, regression, HRP, z-score comparison). The kernel consumes f64 because Decimal lacks the required math (sqrt, ln, eigendecomposition).
  • f64_to_decimal_checked: exiting a statistical kernel back into any booked value (position size, hedge ratio, stop multiplier). The guard ensures NaN / ±Inf — which every well-behaved estimator produces on degenerate inputs — refuses to become a silent zero or one.

The functions return Result because the boundary is the correct place to raise a domain error: a covariance collapse, a regression that failed to converge, a rate-limiter returning ∞ backoff — all legitimate events the domain layer must decide how to handle. Converting them to arbitrary defaults hides real failures.

§Reference

  • Spec: specs/precision/financial-precision-boundary.md (qbot-core).
  • Historical scars: hedge_sizing.rs:109 (NaN β → 1:1 hedge), pair_simulation/cost.rs:34 (silent zero z-score).

Enums§

NonFiniteKind
Classification of a rejected non-finite f64 at a precision boundary.
PrecisionBoundaryError
Error returned by the precision-boundary conversion helpers.

Constants§

PRECISION_SCALE
The canonical rounding scale for f64 → Decimal crossings.

Functions§

decimal_to_f64_checked
Canonical Decimal → f64 conversion at a precision boundary.
f64_to_decimal_checked
Canonical f64 → Decimal conversion at a precision boundary.