pub trait AssertIsCloseToWithDefaultMargin<E> {
// Required methods
fn is_close_to(self, expected: E) -> Self;
fn is_not_close_to(self, expected: E) -> Self;
}float-cmp only.Expand description
Assert approximate equality for floating point numbers.
§Examples
use asserting::prelude::*;
assert_that!(5.0_f32 / 2.0).is_close_to(2.5);
assert_that!(10.0_f64 / 8.0).is_close_to(1.25);
assert_that!(5.0_f32 / 2.5).is_not_close_to(2.01);
assert_that!(10.0_f64 / 8.0).is_not_close_to(1.255);Required Methods§
Sourcefn is_close_to(self, expected: E) -> Self
fn is_close_to(self, expected: E) -> Self
Verifies that the actual value is approximately equal to the expected value.
For the approximation, a default margin with 4 * epsilon and 4 * ULPS is used.
§Examples
use asserting::prelude::*;
assert_that!(5.0_f32 / 2.0).is_close_to(2.5);
assert_that!(10.0_f64 / 8.0).is_close_to(1.25);The following articles describe the challenges with comparing floating point numbers and the meaning of the epsilon and ULPS values:
Sourcefn is_not_close_to(self, expected: E) -> Self
fn is_not_close_to(self, expected: E) -> Self
Verifies that the actual value is not approximately equal to the expected value.
For the approximation, a default margin with 4 * epsilon and 4 * ULPS is used.
§Examples
use asserting::prelude::*;
assert_that!(10.0_f32 / 2.0).is_not_close_to(5.01);
assert_that!(10.0_f64 / 2.0).is_not_close_to(5.01);The following articles describe the challenges with comparing floating point numbers and the meaning of the epsilon and ULPS values:
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.