Skip to content

Commit dc0ba78

Browse files
committed
Don't require strict equality when subnormals are flushed
1 parent 11c43c0 commit dc0ba78

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

crates/test_helpers/Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ version = "0.1.0"
44
edition = "2021"
55
publish = false
66

7-
[dependencies.proptest]
8-
version = "0.10"
9-
default-features = false
10-
features = ["alloc"]
7+
[dependencies]
8+
float_eq = "1.0"
9+
proptest = { version = "0.10", default-features = false, features = ["alloc"] }
1110

1211
[features]
1312
all_lane_counts = []

crates/test_helpers/src/biteq.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ macro_rules! impl_float_biteq {
4040
fn biteq(&self, other: &Self) -> bool {
4141
if self.is_nan() && other.is_nan() {
4242
true // exact nan bits don't matter
43+
} else if crate::flush_subnormals::<Self>() {
44+
self.to_bits() == other.to_bits() || float_eq::float_eq!(self, other, abs <= 2. * <$type>::EPSILON)
4345
} else {
4446
self.to_bits() == other.to_bits()
4547
}

crates/test_helpers/src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@ pub mod wasm;
66
#[macro_use]
77
pub mod biteq;
88

9+
/// Indicates if subnormal floats are flushed to zero.
10+
pub fn flush_subnormals<T>() -> bool {
11+
let is_f32 = core::mem::size_of::<T>() == 4;
12+
let ppc_flush = is_f32
13+
&& cfg!(all(
14+
target_arch = "powerpc64",
15+
target_endian = "big",
16+
not(target_feature = "vsx")
17+
));
18+
let arm_flush = is_f32 && cfg!(all(target_arch = "arm", target_feature = "neon"));
19+
ppc_flush || arm_flush
20+
}
21+
922
/// Specifies the default strategy for testing a type.
1023
///
1124
/// This strategy should be what "makes sense" to test.

0 commit comments

Comments
 (0)