Crate result_float

Crate result_float 

Source
Expand description

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)?);

Structs§

NaN
An error which is returned when an operation returns NaN.
ResultFloat
A floating point number that cannot store NaN.

Functions§

rf
Shorthand for ResultFloat::new(value).

Type Aliases§

Result
The type returned by most ResultFloat operations.
Rf32
A floating point number behaving like f32 that does not allow NaN.
Rf64
A floating point number behaving like f64 that does not allow NaN.