[][src]Trait almost::AlmostEqual

pub trait AlmostEqual {
    type Float;

    const DEFAULT_TOLERANCE: Self::Float;
    const MACHINE_EPSILON: Self::Float;

    fn almost_equals_with(self, rhs: Self, tol: Self::Float) -> bool;
fn almost_zero_with(self, tol: Self::Float) -> bool; fn almost_zero(self) -> bool
    where
        Self: Sized
, { ... }
fn almost_equals(self, rhs: Self) -> bool
    where
        Self: Sized
, { ... } }

A trait for comparing floating point numbers. Not broadly intended to be used by most code (instead, use the functions at the crate root), however it could be useful for generic code too.

Associated Types

type Float

The floating point type. For f32 and f64 this is Self, but for custom aggregate types it could be different.

Loading content...

Associated Constants

const DEFAULT_TOLERANCE: Self::Float

The default tolerance value for this type. Typically equivalent to T::EPSILON.sqrt(), as we assume that around half of the precision bits of any arbitrary computation have been rounded away.

const MACHINE_EPSILON: Self::Float

The machine epsilon for this type. This generally should not be used as a tolerance value (it's frequently too strict), however it can be useful when computing tolerances.

Loading content...

Required methods

fn almost_equals_with(self, rhs: Self, tol: Self::Float) -> bool

Equivalent to almost::equal_with.

const MY_TOLERANCE: f32 = almost::F32_TOLERANCE / 2.0;
assert!(a.almost_equals_with(b, MY_TOLERANCE));

fn almost_zero_with(self, tol: Self::Float) -> bool

Equivalent to almost::zero_with.

assert!(0.01.almost_zero_with(0.05));
Loading content...

Provided methods

fn almost_zero(self) -> bool where
    Self: Sized

Equivalent to almost::zero.

assert!(v.almost_zero());

fn almost_equals(self, rhs: Self) -> bool where
    Self: Sized

Equivalent to almost::equal.

assert!(a.almost_equals(b));
Loading content...

Implementors

impl AlmostEqual for f32[src]

type Float = f32

impl AlmostEqual for f64[src]

type Float = f64

Loading content...