Skip to content

Commit 3a5f7f2

Browse files
committed
Keep extrema edge assertions observable under optimization
1 parent 0d664fd commit 3a5f7f2

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

‎src/math/misc.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ mod tests {
295295
for &x in crate::test::EDGE_VALUES {
296296
for &y in crate::test::EDGE_VALUES {
297297
for (result, maximum) in [(fmax(x, y), true), (fmin(x, y), false)] {
298+
// Observe the computed value: LLVM can infer a non-NaN result
299+
// from one numeric operand, but native extrema may quiet an
300+
// sNaN to NaN (notably in optimized AArch64 builds).
301+
let result = std::hint::black_box(result);
298302
if x.is_nan() && y.is_nan() {
299303
assert!(result.is_nan());
300304
} else if x.is_nan() || y.is_nan() {
@@ -304,7 +308,15 @@ mod tests {
304308
if !signaling(x) && !signaling(y) {
305309
assert_eq!(result.to_bits(), expected.to_bits());
306310
} else {
307-
assert!(result.is_nan() || result.to_bits() == expected.to_bits());
311+
assert!(
312+
result.is_nan() || result.to_bits() == expected.to_bits(),
313+
"f{}(0x{:016x}, 0x{:016x}) = 0x{:016x}; expected NaN or 0x{:016x}",
314+
if maximum { "max" } else { "min" },
315+
x.to_bits(),
316+
y.to_bits(),
317+
result.to_bits(),
318+
expected.to_bits(),
319+
);
308320
}
309321
} else {
310322
let expected = if (x > y) == maximum { x } else { y };

0 commit comments

Comments
 (0)