decorum::cmp

Trait FloatEq

Source
pub trait FloatEq {
    // Required method
    fn float_eq(&self, other: &Self) -> bool;
}
Expand description

Equivalence relation for floating-point primitives.

FloatEq agrees with the total ordering provided by FloatOrd. See the module documentation for more. Importantly, given the set of NaN representations $N$, FloatEq expresses:

$$ \begin{aligned} a=b&\mid a\in{N},~b\in{N}\cr[1em] n\ne x&\mid n\in{N},~x\notin{N} \end{aligned} $$

§Examples

Comparing NaNs using primitive floating-point types:

use decorum::cmp::FloatEq;
use decorum::Infinite;

let x = 0.0f64 / 0.0; // `NaN`.
let y = f64::INFINITY - f64::INFINITY; // `NaN`.

assert!(x.float_eq(&y));

Required Methods§

Source

fn float_eq(&self, other: &Self) -> bool

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> FloatEq for [T]
where T: Float + Primitive,

Source§

fn float_eq(&self, other: &Self) -> bool

Implementors§

Source§

impl<T> FloatEq for T
where T: Float + Primitive,