Don't require strict equality when subnormals are flushed
This commit is contained in:
parent
11c43c0c16
commit
dc0ba78365
@ -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 = []
|
||||
|
@ -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()
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user