Closed
Description
Hi.
I noticed that the core test f16::test_total_cmp
fails when ran in debug mode.
And it passes in release mode.
Here's a small reproducer:
I tried this code:
#![feature(f16)]
use std::cmp::Ordering;
fn q_nan() -> f16 {
f16::from_bits(f16::NAN.to_bits() | quiet_bit_mask())
}
fn s_nan() -> f16 {
f16::from_bits((f16::NAN.to_bits() & !quiet_bit_mask()) + 42)
}
fn quiet_bit_mask() -> u16 {
1 << (f16::MANTISSA_DIGITS - 2)
}
fn main() {
assert_eq!(Ordering::Less, (-q_nan()).total_cmp(&-s_nan()));
}
I expected to see this happen: this test should pass
Instead, this happened: the test fails with:
thread 'main' panicked at src/main.rs:18:5:
assertion `left == right` failed
left: Less
right: Greater
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Meta
rustc --version --verbose
:
rustc 1.89.0-nightly (3e674b06b 2025-05-23)
binary: rustc
commit-hash: 3e674b06b5c74adea662bd0b0b06450757994b16
commit-date: 2025-05-23
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
Backtrace
thread 'main' panicked at src/main.rs:19:5:
assertion `left == right` failed
left: Less
right: Greater
stack backtrace:
0: __rustc::rust_begin_unwind
at /rustc/3e674b06b5c74adea662bd0b0b06450757994b16/library/std/src/panicking.rs:697:5
1: core::panicking::panic_fmt
at /rustc/3e674b06b5c74adea662bd0b0b06450757994b16/library/core/src/panicking.rs:75:14
2: core::panicking::assert_failed_inner
at /rustc/3e674b06b5c74adea662bd0b0b06450757994b16/library/core/src/panicking.rs:432:17
3: core::panicking::assert_failed
at /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:387:5
4: rust_test::main
at ./src/main.rs:19:5
5: core::ops::function::FnOnce::call_once
at /home/user/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.