Skip to main content

Tolerance

Struct Tolerance 

Source
pub struct Tolerance(/* private fields */);
Expand description

A relative tolerance, from 0 up to but not including 1. A tolerance of 0 compares exactly, as Exactly does, but with more work.

Implementations§

Source§

impl Tolerance

Source

pub const EXACT: Self

Exact comparison.

Source

pub const DEFAULT: Self

Dyalog APL’s default comparison tolerance, 1e-14. It is about 45 units in the last place of an f64.

Source

pub fn new(t: f64) -> Option<Self>

The tolerance t, when it lies from 0 up to but not including 1. None for any other t, including NaN.

Source

pub fn is_exact(self) -> bool

Whether this tolerance is 0.

Source

pub const fn value(self) -> f64

The tolerance, as a relative difference.

Trait Implementations§

Source§

impl Clone for Tolerance

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Tolerance

Source§

impl Debug for Tolerance

Source§

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

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

impl PartialEq for Tolerance

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl PartialOrd for Tolerance

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Tolerance

Source§

impl Tolerant for Tolerance

Source§

fn value(self) -> f64

The tolerance: 0 for Exactly.
Source§

fn close<F: Float>(self, x: F, y: F) -> bool

Whether x and y lie within the tolerance of each other: |x-y| is less than the tolerance times the larger of |x| and |y|. NaN and the infinities are close to nothing. less and less_equal read it without equal’s x == y, because x < y already implies x != y, and x <= y already holds where x == y.
Source§

fn floor_in<F: Float, O: Ops<F> + ?Sized>(self, o: &O, y: O::V) -> O::V

floor through o: the formula that the Floor, Ceil and Residue objects give compiled code (Facts::formula).
Source§

fn equal<F: Float>(self, x: F, y: F) -> bool

Whether x equals y: it is y, or close to it. NaN equals nothing, as in IEEE, and an infinity equals only itself.
Source§

fn floor<F: Float>(self, y: F) -> F

The floor of y: the whole number nearest to y, unless it lies above y and doesn’t equal it. Then the whole number below. A floor or ceiling that is zero is 0, never -0, as BPL’s numbers give it.
Source§

fn ceil<F: Float>(self, y: F) -> F

The ceiling of y: the whole number nearest to y, unless it lies below y and doesn’t equal it. Then the whole number above.
Source§

fn ceil_in<F: Float, O: Ops<F> + ?Sized>(self, o: &O, y: O::V) -> O::V

ceil through o.
Source§

fn matches<F: Float>(self, x: F, y: F) -> bool

Whether x and y match: they are equal, or both are NaN. A search that must find NaN compares with matches.
Source§

fn less<F: Float>(self, x: F, y: F) -> bool

Whether x is below y and doesn’t equal it. Comparisons with NaN are false.
Source§

fn less_equal<F: Float>(self, x: F, y: F) -> bool

Whether x is below y or equals it. Comparisons with NaN are false.
Source§

fn greater<F: Float>(self, x: F, y: F) -> bool

Whether x is above y and doesn’t equal it. Comparisons with NaN are false.
Source§

fn greater_equal<F: Float>(self, x: F, y: F) -> bool

Whether x is above y or equals it. Comparisons with NaN are false.
Source§

fn compare<F: Float>(self, x: F, y: F) -> Option<Ordering>

The order of x and y, which is Equal when they are equal. None when either is NaN.
Source§

fn residue<F: Float>(self, x: F, y: F) -> F

y modulo x, through recipe::residue: y - x·floor(y/x) from this tolerance’s floor of the quotient, rounded once where the target fuses multiply-add. At nonzero tolerance, a product equal to y within tolerance leaves no remainder. x = 0 gives y.
Source§

fn residue_in<F: Float, O: Ops<F> + ?Sized>( self, o: &O, x: O::V, y: O::V, ) -> O::V

residue through o.
Source§

fn nearest_whole<F: Float>(self, y: F) -> (F, bool)

The whole number nearest y, and whether y equals it within this tolerance.
Source§

fn nearest_whole_in<F: Float, O: Ops<F> + ?Sized>( self, o: &O, y: O::V, ) -> (O::V, O::B)

Source§

fn whole<F: Float>(self, y: F) -> Option<F>

The whole number equal to y, when there is one.
Source§

fn range<F: Float>(self, c: F) -> Option<(F, F)>

The floats equal to c, as (lo, hi): equal(x, c) holds exactly when lo <= x && x <= hi. Comparing many floats with c then takes two plain comparisons for each, in a loop that vectorizes. None when c is NaN, which equals nothing.
Source§

fn gcd<F: Float>(self, x: F, y: F) -> F

The greatest common divisor of x and y: the larger magnitude divided by the numerator of the first convergent of the ratio of the magnitudes that equals the ratio. It computes in f64 and rounds. NaN when either argument is NaN or infinite. Whole magnitudes whose product is below 1e14 take integer gcd, which gives the same result at any tolerance up to the default.

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> TolerantComplex for T
where T: Tolerant,

Source§

fn complex_equal<R: Native>(self, x: Complex<R>, y: Complex<R>) -> bool

Whether x equals y: the magnitude of x-y is at most the tolerance times the larger magnitude, as Dyalog APL defines it. A number with an infinite or NaN part equals only itself, as IEEE compares it. A tolerance of 0 compares the parts exactly.
Source§

fn squared_equal<R: Native>(self, x: Complex<R>, y: Complex<R>) -> (bool, bool)

complex_equal through squared magnitudes, |x-y|² ≤ t² max(|x|², |y|²), with no branch or square root, and whether that test decides it. A tolerance of 0 compares the parts exactly, which always decides. Otherwise the test decides wherever the larger squared magnitude lies between 2^-800 and 2^1000 at f64, or 2^-80 and 2^120 at f32. In that range no square overflows, and t² times one doesn’t underflow. A NaN part gives false, as IEEE compares it.
Source§

fn scaled_equal<R: Native>(self, x: Complex<R>, y: Complex<R>) -> bool

complex_equal from the magnitudes themselves, which norm computes without overflow or underflow, for the pairs that squared_equal leaves undecided.
Source§

fn complex_floor<R: Native>(self, y: Complex<R>) -> Complex<R>

McDonnell’s complex floor: the floors of both parts, plus 1 on the part with the larger fraction when the fractions add up to 1.
Source§

fn complex_ceil<R: Native>(self, y: Complex<R>) -> Complex<R>

Source§

fn complex_residue<R: Native>(self, x: Complex<R>, y: Complex<R>) -> Complex<R>

y modulo x for complex numbers. A quotient equal to a Gaussian integer leaves no remainder. x = 0 gives y.
Source§

fn complex_gcd<R: Native>(self, x: Complex<R>, y: Complex<R>) -> Complex<R>

The greatest common divisor of x and y as complex numbers, by Euclid’s algorithm with the quotient rounded to the nearest Gaussian integer. It stops once the remainder is within the tolerance of the larger magnitude, and turns the result into the first quadrant, real part above 0. Two real numbers give gcd. A non-finite argument, or a remainder that stops shrinking, gives NaN.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.