Skip to content

Commit 4f943d4

Browse files
committed
cleanup: Use x.biteq(y) rather than x.to_bits() == y.to_bits()
1 parent 7c12df1 commit 4f943d4

File tree

6 files changed

+14
-19
lines changed

6 files changed

+14
-19
lines changed

libm-test/src/precision.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ fn unop_common<F1: Float, F2: Float>(
381381
}
382382

383383
// abs and copysign require signaling NaNs to be propagated, so verify bit equality.
384-
if actual.to_bits() == expected.to_bits() {
384+
if actual.biteq(expected) {
385385
return CheckAction::Custom(Ok(()));
386386
} else {
387387
return CheckAction::Custom(Err(anyhow::anyhow!("NaNs have different bitpatterns")));

libm-test/src/test_traits.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,7 @@ where
328328
// Check when both are NaNs
329329
if actual.is_nan() && expected.is_nan() {
330330
if require_biteq && ctx.basis == CheckBasis::None {
331-
ensure!(
332-
actual.to_bits() == expected.to_bits(),
333-
"mismatched NaN bitpatterns"
334-
);
331+
ensure!(actual.biteq(expected), "mismatched NaN bitpatterns");
335332
}
336333
// By default, NaNs have nothing special to check.
337334
return Ok(());

libm/src/math/generic/fmaximum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn fmaximum<F: Float>(x: F, y: F) -> F {
1717
x
1818
} else if y.is_nan() {
1919
y
20-
} else if x > y || (y.to_bits() == F::NEG_ZERO.to_bits() && x.is_sign_positive()) {
20+
} else if x > y || (y.biteq(F::NEG_ZERO) && x.is_sign_positive()) {
2121
x
2222
} else {
2323
y

libm/src/math/generic/fmaximum_num.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ use crate::support::Float;
1515

1616
#[inline]
1717
pub fn fmaximum_num<F: Float>(x: F, y: F) -> F {
18-
let res =
19-
if x.is_nan() || x < y || (x.to_bits() == F::NEG_ZERO.to_bits() && y.is_sign_positive()) {
20-
y
21-
} else {
22-
x
23-
};
18+
let res = if x.is_nan() || x < y || (x.biteq(F::NEG_ZERO) && y.is_sign_positive()) {
19+
y
20+
} else {
21+
x
22+
};
2423

2524
// Canonicalize
2625
res * F::ONE

libm/src/math/generic/fminimum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub fn fminimum<F: Float>(x: F, y: F) -> F {
1717
x
1818
} else if y.is_nan() {
1919
y
20-
} else if x < y || (x.to_bits() == F::NEG_ZERO.to_bits() && y.is_sign_positive()) {
20+
} else if x < y || (x.biteq(F::NEG_ZERO) && y.is_sign_positive()) {
2121
x
2222
} else {
2323
y

libm/src/math/generic/fminimum_num.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@ use crate::support::Float;
1515

1616
#[inline]
1717
pub fn fminimum_num<F: Float>(x: F, y: F) -> F {
18-
let res =
19-
if y.is_nan() || x < y || (x.to_bits() == F::NEG_ZERO.to_bits() && y.is_sign_positive()) {
20-
x
21-
} else {
22-
y
23-
};
18+
let res = if y.is_nan() || x < y || (x.biteq(F::NEG_ZERO) && y.is_sign_positive()) {
19+
x
20+
} else {
21+
y
22+
};
2423

2524
// Canonicalize
2625
res * F::ONE

0 commit comments

Comments
 (0)