pub struct Tol {
pub ct: f64,
pub by_smaller: bool,
}Expand description
How close two floats have to be to count as equal.
Both languages compare reals with a relative tolerance: J’s 9!:18
comparison tolerance, APL’s ⎕CT. Two values are equal when they differ
by less than the tolerance scaled by one of their magnitudes — the
smaller one in J, the larger one in APL. Both references answer strictly:
a difference exactly at the threshold is not equal. Integers, characters
and boxes are unaffected, and an exact bit-for-bit equality (the
infinities included) is equality whatever the tolerance is.
Fields§
§ct: f64Relative tolerance; zero compares exactly.
by_smaller: boolScale by the smaller magnitude (J) rather than the larger (APL).
Implementations§
Source§impl Tol
impl Tol
Sourcepub fn is_j(self) -> bool
pub fn is_j(self) -> bool
Whose rule this is. A scalar verb is handed the tolerance and nothing else about the dialect, and two rules below need to know which one they are under: J reads a magnitude below the tolerance as zero, and J’s equality is total across the box boundary where APL’s reaches inside the box instead.
Sourcepub fn is_zero(self, y: f64) -> bool
pub fn is_zero(self, y: f64) -> bool
Whether the tolerance reads this magnitude as zero.
J’s signum does: * 1e_15 is 0 and * 6e_14 is 1, the threshold
being the tolerance itself. APL’s × is exact there. With !.0 the
tolerance is zero, so the rule falls away with it.
Sourcepub fn eq_cx(self, a: Cx, b: Cx) -> bool
pub fn eq_cx(self, a: Cx, b: Cx) -> bool
Tolerant equality on complex values: the magnitude of the difference
against the same scale the real comparison uses. J answers
3j4 = 3.0000000000001j4 with 1, which is this rule on magnitudes.
Trait Implementations§
impl Copy for Tol
impl StructuralPartialEq for Tol
Auto Trait Implementations§
impl Freeze for Tol
impl RefUnwindSafe for Tol
impl Send for Tol
impl Sync for Tol
impl Unpin for Tol
impl UnsafeUnpin for Tol
impl UnwindSafe for Tol
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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