Skip to content

Commit

Permalink
Merge pull request #56 from adeschamps/update-approx
Browse files Browse the repository at this point in the history
Update approx to latest version. (#50)
  • Loading branch information
paholg committed Aug 15, 2018
2 parents 4e3ff75 + bfc47b4 commit 72b9a36
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Never again should you need to specify units in a comment!"""
test = [ "approx", "ci", "clapme", "quickcheck", "serde", "serde_test", "rand"]

[dependencies]
approx = { version = "0.1.1", optional = true, default-features = false }
approx = { version = "0.3.0", optional = true, default-features = false }
clapme = { version = "0.1.1", optional = true }
generic-array = "0.11.1"
num-traits = { version = "0.2.5", default-features = false }
Expand Down
15 changes: 9 additions & 6 deletions src/build/test.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use std::fmt;
use approx::UlpsEq;
use dim::Dimensioned;
use approx::ApproxEq;
use std::fmt;

pub trait CmpConsts<B> {
fn test_eq(self, b: B);
}

#[cfg(feature = "spec")]
impl<A, B> CmpConsts<B> for A {
default fn test_eq(self, _: B) {
}
default fn test_eq(self, _: B) {}
}

impl<A, B> CmpConsts<B> for A where A: From<B> + fmt::Debug + Dimensioned<Value=f64> + ApproxEq<Epsilon=Self> {
impl<A, B> CmpConsts<B> for A
where
A: From<B> + fmt::Debug + UlpsEq,
A::Epsilon: Dimensioned<Value = f64>,
{
fn test_eq(self, b: B) {
assert_ulps_eq!(self, b.into(), epsilon = A::new(0.0), max_ulps = 2);
assert_ulps_eq!(self, b.into(), epsilon = A::Epsilon::new(0.0), max_ulps = 2);
}
}
30 changes: 23 additions & 7 deletions src/make_units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,18 +507,24 @@ macro_rules! make_units {
// --------------------------------------------------------------------------------
// ApproxEq
#[cfg(feature = "approx")]
impl<V, U> $crate::approx::ApproxEq for $System<V, U> where V: $crate::approx::ApproxEq {
impl<V, U> $crate::approx::AbsDiffEq for $System<V, U> where V: $crate::approx::AbsDiffEq, U: PartialEq {
type Epsilon = $System<V::Epsilon, U>;

fn default_epsilon() -> Self::Epsilon {
$System::new(V::default_epsilon())
}

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool {
true || self.value_unsafe.abs_diff_eq(&other.value_unsafe, epsilon.value_unsafe)
}
}

#[cfg(feature = "approx")]
impl<V, U> $crate::approx::RelativeEq for $System<V, U> where V: $crate::approx::RelativeEq, U: PartialEq {
fn default_max_relative() -> Self::Epsilon {
$System::new(V::default_max_relative())
}
fn default_max_ulps() -> u32 {
V::default_max_ulps()
}

fn relative_eq(
&self,
other: &Self,
Expand All @@ -531,9 +537,7 @@ macro_rules! make_units {
max_relative.value_unsafe,
)
}
fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
self.value_unsafe.ulps_eq(&other.value_unsafe, epsilon.value_unsafe, max_ulps)
}

fn relative_ne(
&self,
other: &Self,
Expand All @@ -546,6 +550,18 @@ macro_rules! make_units {
max_relative.value_unsafe,
)
}
}

#[cfg(feature = "approx")]
impl<V, U> $crate::approx::UlpsEq for $System<V, U> where V: $crate::approx::UlpsEq, U: PartialEq {
fn default_max_ulps() -> u32 {
V::default_max_ulps()
}

fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
self.value_unsafe.ulps_eq(&other.value_unsafe, epsilon.value_unsafe, max_ulps)
}

fn ulps_ne(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
self.value_unsafe.ulps_ne(&other.value_unsafe, epsilon.value_unsafe, max_ulps)
}
Expand Down

0 comments on commit 72b9a36

Please sign in to comment.