summaryrefslogtreecommitdiffstats
path: root/tests/ui/issues/issue-50811.rs
blob: 2a20e50fa45433ed6674701df1d1007a680a6a52 (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
55
56
// run-pass
#![feature(test)]
#![allow(invalid_nan_comparisons)]

extern crate test;

use std::mem::size_of;
use test::black_box;

// Ensure the const-eval result and runtime result of float comparison are equivalent.

macro_rules! compare {
    ($op:tt) => {
        compare!(
            [f64::NEG_INFINITY, -f64::MAX, -1.0, -0.0, 0.0, 1.0, f64::MAX, f64::INFINITY, f64::NAN],
            $op
        );
    };
    ([$($lhs:expr),+], $op:tt) => {
        $(compare!(
            $lhs,
            $op,
            [f64::NEG_INFINITY, -f64::MAX, -1.0, -0.0, 0.0, 1.0, f64::MAX, f64::INFINITY, f64::NAN]
        );)+
    };
    ($lhs:expr, $op:tt, [$($rhs:expr),+]) => {
        $({
            // Wrap the check in its own function to reduce time needed to borrowck.
            fn check() {
                static CONST_EVAL: bool = $lhs $op $rhs;
                let runtime_eval = black_box($lhs) $op black_box($rhs);
                assert_eq!(CONST_EVAL, runtime_eval, stringify!($lhs $op $rhs));
                assert_eq!(
                    size_of::<[u8; ($lhs $op $rhs) as usize]>(),
                    runtime_eval as usize,
                    stringify!($lhs $op $rhs (forced const eval))
                );
            }
            check();
        })+
    };
}

fn main() {
    assert_eq!(0.0/0.0 < 0.0/0.0, false);
    assert_eq!(0.0/0.0 > 0.0/0.0, false);
    assert_eq!(f64::NAN < f64::NAN, false);
    assert_eq!(f64::NAN > f64::NAN, false);

    compare!(==);
    compare!(!=);
    compare!(<);
    compare!(<=);
    compare!(>);
    compare!(>=);
}