[−][src]Trait almost::AlmostEqual
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.
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.
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));
Provided methods
fn almost_zero(self) -> bool where
Self: Sized,
Self: Sized,
Equivalent to almost::zero
.
assert!(v.almost_zero());
fn almost_equals(self, rhs: Self) -> bool where
Self: Sized,
Self: Sized,
Equivalent to almost::equal
.
assert!(a.almost_equals(b));