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.
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.
15 use std::f64::{NAN, NEG_INFINITY, INFINITY, MAX};
16 use std::mem::size_of;
19 // Ensure the const-eval result and runtime result of float comparison are equivalent.
21 macro_rules! compare {
24 [NEG_INFINITY, -MAX, -1.0, -0.0, 0.0, 1.0, MAX, INFINITY, NAN],
28 ([$($lhs:expr),+], $op:tt) => {
32 [NEG_INFINITY, -MAX, -1.0, -0.0, 0.0, 1.0, MAX, INFINITY, NAN]
35 ($lhs:expr, $op:tt, [$($rhs:expr),+]) => {
37 // Wrap the check in its own function to reduce time needed to borrowck.
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));
43 size_of::<[u8; ($lhs $op $rhs) as usize]>(),
44 runtime_eval as usize,
45 stringify!($lhs $op $rhs (forced const eval))
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);