about summary refs log tree commit diff
path: root/tests/ui/match/match-float.rs
blob: 70283eaeec52715bee63508ec646edb753fb921a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//@ run-pass
// Makes sure we use `==` (not bitwise) semantics for float comparison.

#![feature(f128)]
#![feature(f16)]

// FIXME(f16_f128): remove gates when ABI issues are resolved

#[cfg(all(target_arch = "aarch64", target_os = "linux"))]
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(all(target_arch = "aarch64", target_os = "linux"))]
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(all(target_arch = "aarch64", target_os = "linux"))]
    check_f16();
    check_f32();
    check_f64();
    #[cfg(all(target_arch = "aarch64", target_os = "linux"))]
    check_f128();
}