use crate::nearly_eq::{NearlyEqEps, NearlyEqUlps};
use crate::tolerance::{
EpsTolerance, EpsToleranceType, Tolerance, UlpsTolerance, UlpsToleranceType,
};
pub trait NearlyOrdEps<Rhs = Self, LhsTol = Self, RhsTol = Rhs>:
NearlyEqEps<Rhs, LhsTol, RhsTol>
where
Rhs: ?Sized,
LhsTol: ?Sized + EpsTolerance<RhsTol>,
RhsTol: ?Sized,
{
fn nearly_lt_eps(&self, other: &Rhs, eps: &EpsToleranceType<LhsTol, RhsTol>) -> bool;
fn nearly_le_eps(&self, other: &Rhs, eps: &EpsToleranceType<LhsTol, RhsTol>) -> bool {
self.nearly_lt_eps(other, eps) || self.nearly_eq_eps(other, eps)
}
fn nearly_gt_eps(&self, other: &Rhs, eps: &EpsToleranceType<LhsTol, RhsTol>) -> bool;
fn nearly_ge_eps(&self, other: &Rhs, eps: &EpsToleranceType<LhsTol, RhsTol>) -> bool {
self.nearly_gt_eps(other, eps) || self.nearly_eq_eps(other, eps)
}
}
pub trait NearlyOrdUlps<Rhs = Self, LhsTol = Self, RhsTol = Rhs>:
NearlyEqUlps<Rhs, LhsTol, RhsTol>
where
Rhs: ?Sized,
LhsTol: ?Sized + UlpsTolerance<RhsTol>,
RhsTol: ?Sized,
{
fn nearly_lt_ulps(&self, other: &Rhs, ulps: &UlpsToleranceType<LhsTol, RhsTol>) -> bool;
#[inline]
fn nearly_le_ulps(&self, other: &Rhs, ulps: &UlpsToleranceType<LhsTol, RhsTol>) -> bool {
self.nearly_lt_ulps(other, ulps) || self.nearly_eq_ulps(other, ulps)
}
fn nearly_gt_ulps(&self, other: &Rhs, ulps: &UlpsToleranceType<LhsTol, RhsTol>) -> bool;
#[inline]
fn nearly_ge_ulps(&self, other: &Rhs, ulps: &UlpsToleranceType<LhsTol, RhsTol>) -> bool {
self.nearly_gt_ulps(other, ulps) || self.nearly_eq_ulps(other, ulps)
}
}
pub trait NearlyOrdTol<Rhs = Self, LhsTol = Self, RhsTol = Rhs>:
NearlyOrdEps<Rhs, LhsTol, RhsTol> + NearlyOrdUlps<Rhs, LhsTol, RhsTol>
where
Rhs: ?Sized,
LhsTol: ?Sized + EpsTolerance<RhsTol> + UlpsTolerance<RhsTol>,
RhsTol: ?Sized,
{
#[inline]
fn nearly_lt_tol(&self, other: &Rhs, tol: &Tolerance<LhsTol, RhsTol>) -> bool {
self.nearly_lt_eps(other, &tol.eps) || self.nearly_lt_ulps(other, &tol.ulps)
}
#[inline]
fn nearly_le_tol(&self, other: &Rhs, tol: &Tolerance<LhsTol, RhsTol>) -> bool {
self.nearly_le_eps(other, &tol.eps) || self.nearly_le_ulps(other, &tol.ulps)
}
#[inline]
fn nearly_gt_tol(&self, other: &Rhs, tol: &Tolerance<LhsTol, RhsTol>) -> bool {
self.nearly_gt_eps(other, &tol.eps) || self.nearly_gt_ulps(other, &tol.ulps)
}
#[inline]
fn nearly_ge_tol(&self, other: &Rhs, tol: &Tolerance<LhsTol, RhsTol>) -> bool {
self.nearly_ge_eps(other, &tol.eps) || self.nearly_ge_ulps(other, &tol.ulps)
}
}
pub trait NearlyOrd<Rhs = Self, LhsTol = Self, RhsTol = Rhs>:
NearlyOrdTol<Rhs, LhsTol, RhsTol>
where
Rhs: ?Sized,
LhsTol: ?Sized + EpsTolerance<RhsTol> + UlpsTolerance<RhsTol>,
RhsTol: ?Sized,
{
#[inline]
fn nearly_lt(&self, other: &Rhs) -> bool {
self.nearly_lt_tol(other, &Tolerance::<LhsTol, RhsTol>::default())
}
#[inline]
fn nearly_le(&self, other: &Rhs) -> bool {
self.nearly_le_tol(other, &Tolerance::<LhsTol, RhsTol>::default())
}
#[inline]
fn nearly_gt(&self, other: &Rhs) -> bool {
self.nearly_gt_tol(other, &Tolerance::<LhsTol, RhsTol>::default())
}
#[inline]
fn nearly_ge(&self, other: &Rhs) -> bool {
self.nearly_ge_tol(other, &Tolerance::<LhsTol, RhsTol>::default())
}
}