]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issue-50811.rs
New upstream version 1.29.0+dfsg1
[rustc.git] / src / test / run-pass / issue-50811.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(test)]
12
13 extern crate test;
14
15 use std::f64::{NAN, NEG_INFINITY, INFINITY, MAX};
16 use std::mem::size_of;
17 use test::black_box;
18
19 // Ensure the const-eval result and runtime result of float comparison are equivalent.
20
21 macro_rules! compare {
22 ($op:tt) => {
23 compare!(
24 [NEG_INFINITY, -MAX, -1.0, -0.0, 0.0, 1.0, MAX, INFINITY, NAN],
25 $op
26 );
27 };
28 ([$($lhs:expr),+], $op:tt) => {
29 $(compare!(
30 $lhs,
31 $op,
32 [NEG_INFINITY, -MAX, -1.0, -0.0, 0.0, 1.0, MAX, INFINITY, NAN]
33 );)+
34 };
35 ($lhs:expr, $op:tt, [$($rhs:expr),+]) => {
36 $({
37 // Wrap the check in its own function to reduce time needed to borrowck.
38 fn check() {
39 static CONST_EVAL: bool = $lhs $op $rhs;
40 let runtime_eval = black_box($lhs) $op black_box($rhs);
41 assert_eq!(CONST_EVAL, runtime_eval, stringify!($lhs $op $rhs));
42 assert_eq!(
43 size_of::<[u8; ($lhs $op $rhs) as usize]>(),
44 runtime_eval as usize,
45 stringify!($lhs $op $rhs (forced const eval))
46 );
47 }
48 check();
49 })+
50 };
51 }
52
53 fn main() {
54 assert_eq!(0.0/0.0 < 0.0/0.0, false);
55 assert_eq!(0.0/0.0 > 0.0/0.0, false);
56 assert_eq!(NAN < NAN, false);
57 assert_eq!(NAN > NAN, false);
58
59 compare!(==);
60 compare!(!=);
61 compare!(<);
62 compare!(<=);
63 compare!(>);
64 compare!(>=);
65 }