Files
rust/tests/ui/match/match-float.rs
Trevor Gross 8840409f7a f16,f128: Resolve cfg-releated instances of FIXME(f16_f128)
There are a number of instances of `FIXME(f16_f128)` related to target
configuration; either these could use `target_has_reliable_f128`, or the
FIXME is describing such a cfg and is thus redundant (since any
`cfg(target_has_reliable_f*)` needs to be removed before stabilization
anyway).

Switch to using `target_has_reliable_*` where applicable and remove the
redundant FIXMEs.
2026-01-22 23:41:57 -06:00

55 lines
1.3 KiB
Rust

//@ run-pass
//@ compile-flags: --check-cfg=cfg(target_has_reliable_f16,target_has_reliable_f128)
// Makes sure we use `==` (not bitwise) semantics for float comparison.
#![feature(cfg_target_has_reliable_f16_f128)]
#![feature(f128)]
#![feature(f16)]
#[cfg(target_has_reliable_f16)]
fn check_f16() {
const F1: f16 = 0.0;
const F2: f16 = -0.0;
assert_eq!(F1, F2);
assert_ne!(F1.to_bits(), F2.to_bits());
assert!(matches!(F1, F2));
assert!(matches!(F2, F1));
}
fn check_f32() {
const F1: f32 = 0.0;
const F2: f32 = -0.0;
assert_eq!(F1, F2);
assert_ne!(F1.to_bits(), F2.to_bits());
assert!(matches!(F1, F2));
assert!(matches!(F2, F1));
}
fn check_f64() {
const F1: f64 = 0.0;
const F2: f64 = -0.0;
assert_eq!(F1, F2);
assert_ne!(F1.to_bits(), F2.to_bits());
assert!(matches!(F1, F2));
assert!(matches!(F2, F1));
}
#[cfg(target_has_reliable_f128)]
fn check_f128() {
const F1: f128 = 0.0;
const F2: f128 = -0.0;
assert_eq!(F1, F2);
assert_ne!(F1.to_bits(), F2.to_bits());
assert!(matches!(F1, F2));
assert!(matches!(F2, F1));
}
fn main() {
#[cfg(target_has_reliable_f16)]
check_f16();
check_f32();
check_f64();
#[cfg(target_has_reliable_f128)]
check_f128();
}