cleanup: Use x.biteq(y) rather than x.to_bits() == y.to_bits()
This commit is contained in:
parent
0a7e59265a
commit
e83ca86341
6 changed files with 14 additions and 19 deletions
|
|
@ -381,7 +381,7 @@ fn unop_common<F1: Float, F2: Float>(
|
|||
}
|
||||
|
||||
// abs and copysign require signaling NaNs to be propagated, so verify bit equality.
|
||||
if actual.to_bits() == expected.to_bits() {
|
||||
if actual.biteq(expected) {
|
||||
return CheckAction::Custom(Ok(()));
|
||||
} else {
|
||||
return CheckAction::Custom(Err(anyhow::anyhow!("NaNs have different bitpatterns")));
|
||||
|
|
|
|||
|
|
@ -328,10 +328,7 @@ where
|
|||
// Check when both are NaNs
|
||||
if actual.is_nan() && expected.is_nan() {
|
||||
if require_biteq && ctx.basis == CheckBasis::None {
|
||||
ensure!(
|
||||
actual.to_bits() == expected.to_bits(),
|
||||
"mismatched NaN bitpatterns"
|
||||
);
|
||||
ensure!(actual.biteq(expected), "mismatched NaN bitpatterns");
|
||||
}
|
||||
// By default, NaNs have nothing special to check.
|
||||
return Ok(());
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub fn fmaximum<F: Float>(x: F, y: F) -> F {
|
|||
x
|
||||
} else if y.is_nan() {
|
||||
y
|
||||
} else if x > y || (y.to_bits() == F::NEG_ZERO.to_bits() && x.is_sign_positive()) {
|
||||
} else if x > y || (y.biteq(F::NEG_ZERO) && x.is_sign_positive()) {
|
||||
x
|
||||
} else {
|
||||
y
|
||||
|
|
|
|||
|
|
@ -15,12 +15,11 @@ use crate::support::Float;
|
|||
|
||||
#[inline]
|
||||
pub fn fmaximum_num<F: Float>(x: F, y: F) -> F {
|
||||
let res =
|
||||
if x.is_nan() || x < y || (x.to_bits() == F::NEG_ZERO.to_bits() && y.is_sign_positive()) {
|
||||
y
|
||||
} else {
|
||||
x
|
||||
};
|
||||
let res = if x.is_nan() || x < y || (x.biteq(F::NEG_ZERO) && y.is_sign_positive()) {
|
||||
y
|
||||
} else {
|
||||
x
|
||||
};
|
||||
|
||||
// Canonicalize
|
||||
res * F::ONE
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ pub fn fminimum<F: Float>(x: F, y: F) -> F {
|
|||
x
|
||||
} else if y.is_nan() {
|
||||
y
|
||||
} else if x < y || (x.to_bits() == F::NEG_ZERO.to_bits() && y.is_sign_positive()) {
|
||||
} else if x < y || (x.biteq(F::NEG_ZERO) && y.is_sign_positive()) {
|
||||
x
|
||||
} else {
|
||||
y
|
||||
|
|
|
|||
|
|
@ -15,12 +15,11 @@ use crate::support::Float;
|
|||
|
||||
#[inline]
|
||||
pub fn fminimum_num<F: Float>(x: F, y: F) -> F {
|
||||
let res =
|
||||
if y.is_nan() || x < y || (x.to_bits() == F::NEG_ZERO.to_bits() && y.is_sign_positive()) {
|
||||
x
|
||||
} else {
|
||||
y
|
||||
};
|
||||
let res = if y.is_nan() || x < y || (x.biteq(F::NEG_ZERO) && y.is_sign_positive()) {
|
||||
x
|
||||
} else {
|
||||
y
|
||||
};
|
||||
|
||||
// Canonicalize
|
||||
res * F::ONE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue