Skip to content

Commit

Permalink
Disable comparing subnormal values on ARM for f32 and f64.
Browse files Browse the repository at this point in the history
Replaces dca2031 where specific tests were disabled. With the change
`f{32|64}::Test` implementation considers zero and subnormal values
equal. Part of #392.
  • Loading branch information
iliekturtles committed Jan 27, 2023
1 parent aab4751 commit 037109a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
2 changes: 0 additions & 2 deletions src/si/area.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ mod tests {
}

#[test]
// #392: Disable tests on ARM until issues with floating point behavior can be resolved.
#[cfg(not(target_arch = "arm"))]
fn check_units() {
// Values too large for f32.
if TypeId::of::<f64>() == TypeId::of::<V>() {
Expand Down
2 changes: 0 additions & 2 deletions src/si/volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ mod tests {
}

#[test]
// #392: Disable tests on ARM until issues with floating point behavior can be resolved.
#[cfg(not(target_arch = "arm"))]
fn check_units() {
// Values too large for f32.
if TypeId::of::<f64>() == TypeId::of::<V>() {
Expand Down
44 changes: 36 additions & 8 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,29 @@ mod test_trait {
impl super::super::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) => {}
use crate::lib::num::FpCategory::*;

match (lhs.classify(), rhs.classify()) {
(Nan, Nan) => {}
// #392: Disable on ARM until floating point behavior issues can be resolved.
#[cfg(target_arch = "arm")]
(Zero, Subnormal)
| (Subnormal, Zero) => {}
_ => { assert_eq!(lhs, rhs); }
}
}

/// 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) => {}
use crate::lib::num::FpCategory::*;

match (lhs.classify(), rhs.classify()) {
(Nan, Nan) => {}
// #392: Disable on ARM until floating point behavior issues can be resolved.
#[cfg(target_arch = "arm")]
(Zero, Subnormal)
| (Subnormal, Zero) => {}
_ => {
assert_ulps_eq!(lhs, rhs, epsilon = EPS_FACTOR * V::epsilon(),
max_ulps = ULPS);
Expand All @@ -128,15 +140,31 @@ mod test_trait {

/// Exactly compare `lhs` and `rhs` and return the result.
fn eq(lhs: &Self, rhs: &Self) -> bool {
(lhs.is_nan() && rhs.is_nan())
|| lhs == rhs
use crate::lib::num::FpCategory::*;

match (lhs.classify(), rhs.classify()) {
(Nan, Nan) => true,
// #392: Disable on ARM until floating point behavior issues can be resolved.
#[cfg(target_arch = "arm")]
(Zero, Subnormal)
| (Subnormal, Zero) => true,
_ => lhs == rhs,
}
}

/// 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, rhs, epsilon = EPS_FACTOR * V::epsilon(), max_ulps = ULPS)
use crate::lib::num::FpCategory::*;

match (lhs.classify(), rhs.classify()) {
(Nan, Nan) => true,
// #392: Disable on ARM until floating point behavior issues can be resolved.
#[cfg(target_arch = "arm")]
(Zero, Subnormal)
| (Subnormal, Zero) => true,
_ => ulps_eq!(lhs, rhs, epsilon = EPS_FACTOR * V::epsilon(), max_ulps = ULPS),
}
}
}
}
Expand Down

0 comments on commit 037109a

Please sign in to comment.