Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARM floating point comparison tests #402

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
80 changes: 46 additions & 34 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 All @@ -150,49 +178,33 @@ mod test_trait {
storage_types! {
types: Complex;

use crate::num::Float;
use super::super::Test;

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

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