pub struct AbsoluteTolerance<RealType: RealScalar>(/* private fields */);Expand description
Type-safe wrapper for absolute tolerance values.
AbsoluteTolerance<T> represents a non-negative (≥ 0) tolerance value used for
absolute error comparisons. It ensures that the tolerance is always valid by
rejecting negative values at construction time.
§Implementation
This type is a #[repr(transparent)] wrapper around NonNegativeRealScalar<T>.
All validation is performed by the underlying NonNegativeRealScalar, and errors
are reported as ErrorsNonNegativeRealScalar.
§Mathematical Definition
An absolute tolerance ε is used in comparisons like:
|a - b| ≤ εSince ε represents a distance or error bound, it must be non-negative.
§Type Parameters
RealType: The underlying real scalar type (e.g.,f64,RealNative64StrictFinite)
§Examples
§Basic Usage
use num_valid::{*, scalars::AbsoluteTolerance};
// Create from f64
let tol = AbsoluteTolerance::try_new(1e-10_f64).unwrap();
assert_eq!(tol.as_raw_scalar_ref(), &1e-10);
// Use convenience constructors
let zero = AbsoluteTolerance::<f64>::zero();
let eps = AbsoluteTolerance::<f64>::epsilon();§In Numerical Comparisons
use num_valid::{*, scalars::*};
use try_create::{IntoInner, TryNew};
let tol = AbsoluteTolerance::try_new(1e-10_f64).unwrap();
assert!(approximately_equal(1.0, 1.0 + 1e-11, &tol));
assert!(!approximately_equal(1.0, 1.0 + 1e-9, &tol));§Zero-Cost Abstraction
This type uses #[repr(transparent)] and has zero runtime overhead beyond
the initial validation at construction time.
Implementations§
Source§impl<RealType: RealScalar> AbsoluteTolerance<RealType>
impl<RealType: RealScalar> AbsoluteTolerance<RealType>
Sourcepub fn into_inner(self) -> NonNegativeRealScalar<RealType>
pub fn into_inner(self) -> NonNegativeRealScalar<RealType>
Consumes the struct and returns the inner value.
Source§impl<RealType: RealScalar> AbsoluteTolerance<RealType>
impl<RealType: RealScalar> AbsoluteTolerance<RealType>
Sourcepub fn zero() -> Self
pub fn zero() -> Self
Creates an absolute tolerance of zero.
A zero tolerance represents an exact comparison (no error allowed).
§Examples
use num_valid::{*, scalars::AbsoluteTolerance};
let zero_tol = AbsoluteTolerance::<f64>::zero();
assert_eq!(zero_tol.as_raw_scalar_ref(), &0.0);Sourcepub fn epsilon() -> Self
pub fn epsilon() -> Self
Creates an absolute tolerance equal to machine epsilon.
Machine epsilon is the smallest value such that 1.0 + epsilon != 1.0.
This is often a good default tolerance for floating-point comparisons.
§Examples
use num_valid::{*, scalars::AbsoluteTolerance};
let eps_tol = AbsoluteTolerance::<f64>::epsilon();
assert_eq!(eps_tol.as_raw_scalar_ref(), &f64::EPSILON);Sourcepub fn new(value: NonNegativeRealScalar<RealType>) -> Self
pub fn new(value: NonNegativeRealScalar<RealType>) -> Self
Wraps a NonNegativeRealScalar<T> as an AbsoluteTolerance<T>.
This constructor allows explicit conversion from a validated non-negative scalar to a tolerance type, providing semantic clarity.
§Examples
use num_valid::{*, scalars::*};
use try_create::TryNew;
let non_neg = NonNegativeRealScalar::try_new(1e-10_f64).unwrap();
let tol = AbsoluteTolerance::new(non_neg);
assert_eq!(tol.as_raw_scalar_ref(), &1e-10);Sourcepub fn try_new(
value: RealType,
) -> Result<Self, ErrorsNonNegativeRealScalar<RealType>>
pub fn try_new( value: RealType, ) -> Result<Self, ErrorsNonNegativeRealScalar<RealType>>
Attempts to create a AbsoluteTolerance from a value.
§Errors
Returns ErrorsNonNegativeRealScalar::NegativeValue if the input is negative.
§Panics (Debug Mode Only)
In debug builds, panics if the input is not finite (NaN or infinity).
Trait Implementations§
Source§impl<RealType: RealScalar> AsRef<NonNegativeRealScalar<RealType>> for AbsoluteTolerance<RealType>
impl<RealType: RealScalar> AsRef<NonNegativeRealScalar<RealType>> for AbsoluteTolerance<RealType>
Source§fn as_ref(&self) -> &NonNegativeRealScalar<RealType>
fn as_ref(&self) -> &NonNegativeRealScalar<RealType>
Source§impl<RealType: Clone + RealScalar> Clone for AbsoluteTolerance<RealType>
impl<RealType: Clone + RealScalar> Clone for AbsoluteTolerance<RealType>
Source§fn clone(&self) -> AbsoluteTolerance<RealType>
fn clone(&self) -> AbsoluteTolerance<RealType>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<RealType: Debug + RealScalar> Debug for AbsoluteTolerance<RealType>
impl<RealType: Debug + RealScalar> Debug for AbsoluteTolerance<RealType>
Source§impl<'de, RealType> Deserialize<'de> for AbsoluteTolerance<RealType>where
RealType: for<'a> Deserialize<'a> + RealScalar,
impl<'de, RealType> Deserialize<'de> for AbsoluteTolerance<RealType>where
RealType: for<'a> Deserialize<'a> + RealScalar,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<RealType: RealScalar> Display for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: Display,
impl<RealType: RealScalar> Display for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: Display,
Source§impl<RealType: RealScalar> IntoInner for AbsoluteTolerance<RealType>
impl<RealType: RealScalar> IntoInner for AbsoluteTolerance<RealType>
Source§fn into_inner(self) -> Self::InnerType
fn into_inner(self) -> Self::InnerType
Consumes the struct and returns the inner value.
Source§type InnerType = NonNegativeRealScalar<RealType>
type InnerType = NonNegativeRealScalar<RealType>
Source§impl<RealType: RealScalar> LowerExp for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: LowerExp,
impl<RealType: RealScalar> LowerExp for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: LowerExp,
Source§impl<RealType: PartialEq + RealScalar> PartialEq for AbsoluteTolerance<RealType>
impl<RealType: PartialEq + RealScalar> PartialEq for AbsoluteTolerance<RealType>
Source§impl<RealType: PartialOrd + RealScalar> PartialOrd for AbsoluteTolerance<RealType>
impl<RealType: PartialOrd + RealScalar> PartialOrd for AbsoluteTolerance<RealType>
Source§impl<RealType: RealScalar> ScalarCore for AbsoluteTolerance<RealType>
impl<RealType: RealScalar> ScalarCore for AbsoluteTolerance<RealType>
Source§type RawScalarType = <RealType as ScalarCore>::RawScalarType
type RawScalarType = <RealType as ScalarCore>::RawScalarType
Source§fn as_raw_scalar_ref(&self) -> &Self::RawScalarType
fn as_raw_scalar_ref(&self) -> &Self::RawScalarType
Source§fn into_raw_scalar(self) -> Self::RawScalarType
fn into_raw_scalar(self) -> Self::RawScalarType
Source§impl<RealType> Serialize for AbsoluteTolerance<RealType>where
RealType: Serialize + RealScalar,
impl<RealType> Serialize for AbsoluteTolerance<RealType>where
RealType: Serialize + RealScalar,
impl<RealType: PartialEq + RealScalar> StructuralPartialEq for AbsoluteTolerance<RealType>
Auto Trait Implementations§
impl<RealType> Freeze for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: Freeze,
impl<RealType> RefUnwindSafe for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: RefUnwindSafe,
impl<RealType> Send for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: Send,
impl<RealType> Sync for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: Sync,
impl<RealType> Unpin for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: Unpin,
impl<RealType> UnsafeUnpin for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: UnsafeUnpin,
impl<RealType> UnwindSafe for AbsoluteTolerance<RealType>where
NonNegativeRealScalar<RealType>: UnwindSafe,
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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