pub fn try_f64<A: Float>(value: A) -> Result<f64>Expand description
Convert a generic float A down into f64, returning an honest error when
the value has no f64 representation.
This is the mirror image of try_scalar: try_scalar widens a concrete
literal into the generic parameter type, try_f64 narrows a generic value
back to f64 for accumulators, metrics and reporting that are natively
f64. It replaces the x.to_f64().expect("unwrap failed") pattern.
ยงExamples
use optirs_core::utils::try_f64;
assert_eq!(try_f64(0.5f32).expect("f32 always fits in f64"), 0.5);
assert_eq!(try_f64(f64::INFINITY).expect("infinity is an f64"), f64::INFINITY);