Struct RelativeParams

Source
pub struct RelativeParams<T, E = T> {
    pub zero_thresh: E,
    pub max_relative: E,
    /* private fields */
}
Expand description

A struct to use for approximate equality.

let test = RelativeParams::<f32>::new(Some(0.05), Some(0.001));
assert!(test.close_to(&1.0, &1.001));
assert!(test.close_to(&1001., &1000.));
assert!(test.close_to_zero(&-0.05));
assert!(! test.close_to(&0.1, &0.11));
assert!(! test.close_to_zero(&0.06));

Fields§

§zero_thresh: E

Below this threshold in absolute value, values are considered close to zero.

§max_relative: E

Values not close to zero are considered close to each other if their relative error is at most this large.

Implementations§

Source§

impl RelativeParams<f32, f32>

Source

pub fn new(zero_thresh: Option<f32>, max_relative: Option<f32>) -> Self

Create a new closeness tester with the given parameters.

For both arguments, zero_thresh and max_relative, either the given bound is used, or machine epsilon if the argument is None.

Source§

impl RelativeParams<f64, f64>

Source

pub fn new(zero_thresh: Option<f64>, max_relative: Option<f64>) -> Self

Create a new closeness tester with the given parameters.

For both arguments, zero_thresh and max_relative, either the given bound is used, or machine epsilon if the argument is None.

Source§

impl RelativeParams<Complex32, f32>

Source

pub fn new(zero_thresh: Option<f32>, max_relative: Option<f32>) -> Self

Create a new closeness tester with the given parameters.

For both arguments, zero_thresh and max_relative, either the given bound is used, or machine epsilon if the argument is None.

Source§

impl RelativeParams<Complex64, f64>

Source

pub fn new(zero_thresh: Option<f64>, max_relative: Option<f64>) -> Self

Create a new closeness tester with the given parameters.

For both arguments, zero_thresh and max_relative, either the given bound is used, or machine epsilon if the argument is None.

Trait Implementations§

Source§

impl<T: Clone, E: Clone> Clone for RelativeParams<T, E>

Source§

fn clone(&self) -> RelativeParams<T, E>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl CloseTo for RelativeParams<Complex32, f32>

Source§

type Item = Complex<f32>

The type of thing that can be compared.
Source§

fn close_to(&self, x: &Self::Item, y: &Self::Item) -> bool

Returns true iff x is approximatey equal to y.
Source§

fn close_to_zero(&self, x: &Self::Item) -> bool

Indicates true if x is approximately zero.
Source§

fn close_to_iter<'a, Iter1, Iter2>(&'a self, x: Iter1, y: Iter2) -> bool
where Iter1: Iterator<Item = &'a Self::Item>, Iter2: Iterator<Item = &'a Self::Item>,

Checks closeness over an iteration.
Source§

impl CloseTo for RelativeParams<Complex64, f64>

Source§

type Item = Complex<f64>

The type of thing that can be compared.
Source§

fn close_to(&self, x: &Self::Item, y: &Self::Item) -> bool

Returns true iff x is approximatey equal to y.
Source§

fn close_to_zero(&self, x: &Self::Item) -> bool

Indicates true if x is approximately zero.
Source§

fn close_to_iter<'a, Iter1, Iter2>(&'a self, x: Iter1, y: Iter2) -> bool
where Iter1: Iterator<Item = &'a Self::Item>, Iter2: Iterator<Item = &'a Self::Item>,

Checks closeness over an iteration.
Source§

impl CloseTo for RelativeParams<f32, f32>

Source§

type Item = f32

The type of thing that can be compared.
Source§

fn close_to(&self, x: &Self::Item, y: &Self::Item) -> bool

Returns true iff x is approximatey equal to y.
Source§

fn close_to_zero(&self, x: &Self::Item) -> bool

Indicates true if x is approximately zero.
Source§

fn close_to_iter<'a, Iter1, Iter2>(&'a self, x: Iter1, y: Iter2) -> bool
where Iter1: Iterator<Item = &'a Self::Item>, Iter2: Iterator<Item = &'a Self::Item>,

Checks closeness over an iteration.
Source§

impl CloseTo for RelativeParams<f64, f64>

Source§

type Item = f64

The type of thing that can be compared.
Source§

fn close_to(&self, x: &Self::Item, y: &Self::Item) -> bool

Returns true iff x is approximatey equal to y.
Source§

fn close_to_zero(&self, x: &Self::Item) -> bool

Indicates true if x is approximately zero.
Source§

fn close_to_iter<'a, Iter1, Iter2>(&'a self, x: Iter1, y: Iter2) -> bool
where Iter1: Iterator<Item = &'a Self::Item>, Iter2: Iterator<Item = &'a Self::Item>,

Checks closeness over an iteration.
Source§

impl<T: Debug, E: Debug> Debug for RelativeParams<T, E>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RelativeParams<Complex32, f32>

Source§

fn default() -> Self

Create a closeness tester with machine epsilon precision.

Source§

impl Default for RelativeParams<Complex64, f64>

Source§

fn default() -> Self

Create a closeness tester with machine epsilon precision.

Source§

impl Default for RelativeParams<f32, f32>

Source§

fn default() -> Self

Create a closeness tester with machine epsilon precision.

Source§

impl Default for RelativeParams<f64, f64>

Source§

fn default() -> Self

Create a closeness tester with machine epsilon precision.

Source§

impl<T: PartialEq, E: PartialEq> PartialEq for RelativeParams<T, E>

Source§

fn eq(&self, other: &RelativeParams<T, E>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Copy, E: Copy> Copy for RelativeParams<T, E>

Source§

impl<T: Eq, E: Eq> Eq for RelativeParams<T, E>

Source§

impl<T, E> StructuralPartialEq for RelativeParams<T, E>

Auto Trait Implementations§

§

impl<T, E> Freeze for RelativeParams<T, E>
where E: Freeze,

§

impl<T, E> RefUnwindSafe for RelativeParams<T, E>

§

impl<T, E> Send for RelativeParams<T, E>
where E: Send, T: Send,

§

impl<T, E> Sync for RelativeParams<T, E>
where E: Sync, T: Sync,

§

impl<T, E> Unpin for RelativeParams<T, E>
where E: Unpin, T: Unpin,

§

impl<T, E> UnwindSafe for RelativeParams<T, E>
where E: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.