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 consumesf64becauseDecimallacks 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§
- NonFinite
Kind - Classification of a rejected non-finite
f64at a precision boundary. - Precision
Boundary Error - Error returned by the precision-boundary conversion helpers.
Constants§
- PRECISION_
SCALE - The canonical rounding scale for
f64 → Decimalcrossings.
Functions§
- decimal_
to_ f64_ checked - Canonical
Decimal → f64conversion at a precision boundary. - f64_
to_ decimal_ checked - Canonical
f64 → Decimalconversion at a precision boundary.