From afe7676bf49a3033e06d6f830cf44f9ee99ae443 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sat, 23 Sep 2023 23:02:42 +0200 Subject: [PATCH] add test checking behavior of matching on floats --- tests/ui/match/match-float.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 tests/ui/match/match-float.rs diff --git a/tests/ui/match/match-float.rs b/tests/ui/match/match-float.rs new file mode 100644 index 0000000000000..8da6a9ed2049c --- /dev/null +++ b/tests/ui/match/match-float.rs @@ -0,0 +1,11 @@ +// run-pass +// Makes sure we use `==` (not bitwise) semantics for float comparison. + +fn main() { + 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)); +}