2 unstable releases

0.2.0 Jan 27, 2022
0.1.0 Aug 15, 2018

#230 in No standard library

MIT/Apache

40KB
466 lines

result_float

This crate contains floating point types that error if they are set to NaN. This provides an alternative to standard library floating point types that implements Ord and Eq traits.


lib.rs:

This crate contains floating point types that error if they are set to NaN.

Examples

use result_float::{rf, Rf64, Result};

fn geometric_mean(a: Rf64, b: Rf64) -> Result<f64> {
    (a * b)?.sqrt()
}

fn mean(a: Rf64, b: Rf64) -> Result<f64> {
    (a + b)? * rf(0.5)?
}

println!("geometric_mean(10.0, 20.0) = {}", geometric_mean(rf(10.0)?, rf(20.0)?)?);
//prints 14.142...
assert!(mean(rf(10.0)?, rf(20.0)?)? == rf(15.0)?);

Dependencies

~98–335KB