]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-50811.rs
Auto merge of #78066 - bugadani:wat, r=jonas-schievink
[rust.git] / src / test / ui / issues / issue-50811.rs
1 // run-pass
2 #![feature(test)]
3
4 extern crate test;
5
6 use std::f64::{NAN, NEG_INFINITY, INFINITY, MAX};
7 use std::mem::size_of;
8 use test::black_box;
9
10 // Ensure the const-eval result and runtime result of float comparison are equivalent.
11
12 macro_rules! compare {
13     ($op:tt) => {
14         compare!(
15             [NEG_INFINITY, -MAX, -1.0, -0.0, 0.0, 1.0, MAX, INFINITY, NAN],
16             $op
17         );
18     };
19     ([$($lhs:expr),+], $op:tt) => {
20         $(compare!(
21             $lhs,
22             $op,
23             [NEG_INFINITY, -MAX, -1.0, -0.0, 0.0, 1.0, MAX, INFINITY, NAN]
24         );)+
25     };
26     ($lhs:expr, $op:tt, [$($rhs:expr),+]) => {
27         $({
28             // Wrap the check in its own function to reduce time needed to borrowck.
29             fn check() {
30                 static CONST_EVAL: bool = $lhs $op $rhs;
31                 let runtime_eval = black_box($lhs) $op black_box($rhs);
32                 assert_eq!(CONST_EVAL, runtime_eval, stringify!($lhs $op $rhs));
33                 assert_eq!(
34                     size_of::<[u8; ($lhs $op $rhs) as usize]>(),
35                     runtime_eval as usize,
36                     stringify!($lhs $op $rhs (forced const eval))
37                 );
38             }
39             check();
40         })+
41     };
42 }
43
44 fn main() {
45     assert_eq!(0.0/0.0 < 0.0/0.0, false);
46     assert_eq!(0.0/0.0 > 0.0/0.0, false);
47     assert_eq!(NAN < NAN, false);
48     assert_eq!(NAN > NAN, false);
49
50     compare!(==);
51     compare!(!=);
52     compare!(<);
53     compare!(<=);
54     compare!(>);
55     compare!(>=);
56 }