Skip to content

Commit

Permalink
Disable comparing subnormal values on ARM for Complex32 and `Comple…
Browse files Browse the repository at this point in the history
…x64`.

Part of #392.
  • Loading branch information
iliekturtles committed Jan 27, 2023
1 parent 037109a commit 5315dbf
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,49 +178,33 @@ mod test_trait {
storage_types! {
types: Complex;

use crate::num::Float;

// const EPSILON: VV = 64.0 * VV::epsilon(); //error[E0015]; calls in constants are limited...
const EPS_FACTOR: VV = 0.5;
const ULPS: u32 = 3;
use super::super::Test;

impl super::super::Test for V {
impl Test for V {
/// Assert that `lhs` and `rhs` are exactly equal.
fn assert_eq(lhs: &Self, rhs: &Self) {
match (lhs.is_nan(), rhs.is_nan()) {
(true, true) => {}
_ => { assert_eq!(lhs, rhs); }
}
Test::assert_eq(&lhs.re, &rhs.re);
Test::assert_eq(&lhs.im, &rhs.im);
}

/// Assert that `lhs` and `rhs` are approximately equal for floating point types or
/// exactly equal for other types.
fn assert_approx_eq(lhs: &Self, rhs: &Self) {
match (lhs.is_nan(), rhs.is_nan()) {
(true, true) => {}
_ => {
assert_ulps_eq!(lhs.re, rhs.re, epsilon = EPS_FACTOR * VV::epsilon(),
max_ulps = ULPS);
assert_ulps_eq!(lhs.im, rhs.im, epsilon = EPS_FACTOR * VV::epsilon(),
max_ulps = ULPS);
}
}
Test::assert_approx_eq(&lhs.re, &rhs.re);
Test::assert_approx_eq(&lhs.im, &rhs.im);
}

/// Exactly compare `lhs` and `rhs` and return the result.
fn eq(lhs: &Self, rhs: &Self) -> bool {
(lhs.is_nan() && rhs.is_nan())
|| lhs == rhs
Test::eq(&lhs.re, &rhs.re)
&& Test::eq(&lhs.im, &rhs.im)
}

/// Approximately compare `lhs` and `rhs` for floating point types or exactly compare
/// for other types and return the result.
fn approx_eq(lhs: &Self, rhs: &Self) -> bool {
(lhs.is_nan() && rhs.is_nan())
|| ulps_eq!(lhs.re, rhs.re,
epsilon = EPS_FACTOR * VV::epsilon(), max_ulps = ULPS)
|| ulps_eq!(lhs.im, rhs.im,
epsilon = EPS_FACTOR * VV::epsilon(), max_ulps = ULPS)
Test::approx_eq(&lhs.re, &rhs.re)
&& Test::approx_eq(&lhs.im, &rhs.im)
}
}
}
Expand Down

0 comments on commit 5315dbf

Please sign in to comment.