Don't require strict equality when subnormals are flushed

This commit is contained in:
Caleb Zulawski 2023-07-21 15:44:15 -04:00
parent 11c43c0c16
commit dc0ba78365
3 changed files with 18 additions and 4 deletions

View File

@ -4,10 +4,9 @@ version = "0.1.0"
edition = "2021"
publish = false
[dependencies.proptest]
version = "0.10"
default-features = false
features = ["alloc"]
[dependencies]
float_eq = "1.0"
proptest = { version = "0.10", default-features = false, features = ["alloc"] }
[features]
all_lane_counts = []

View File

@ -40,6 +40,8 @@ impl BitEq for $type {
fn biteq(&self, other: &Self) -> bool {
if self.is_nan() && other.is_nan() {
true // exact nan bits don't matter
} else if crate::flush_subnormals::<Self>() {
self.to_bits() == other.to_bits() || float_eq::float_eq!(self, other, abs <= 2. * <$type>::EPSILON)
} else {
self.to_bits() == other.to_bits()
}

View File

@ -6,6 +6,19 @@
#[macro_use]
pub mod biteq;
/// Indicates if subnormal floats are flushed to zero.
pub fn flush_subnormals<T>() -> bool {
let is_f32 = core::mem::size_of::<T>() == 4;
let ppc_flush = is_f32
&& cfg!(all(
target_arch = "powerpc64",
target_endian = "big",
not(target_feature = "vsx")
));
let arm_flush = is_f32 && cfg!(all(target_arch = "arm", target_feature = "neon"));
ppc_flush || arm_flush
}
/// Specifies the default strategy for testing a type.
///
/// This strategy should be what "makes sense" to test.