]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-float-classify.rs
feat(rustdoc): open sidebar menu when links inside it are focused
[rust.git] / src / test / ui / consts / const-float-classify.rs
1 // compile-flags: -Zmir-opt-level=0
2 // run-pass
3
4 #![feature(const_panic)]
5 #![feature(const_float_bits_conv)]
6 #![feature(const_float_classify)]
7 #![feature(const_trait_impl)]
8 #![allow(incomplete_features)]
9
10 // Don't promote
11 const fn nop<T>(x: T) -> T { x }
12
13 macro_rules! const_assert {
14     ($a:expr, $b:expr) => {
15         {
16             const _: () = assert!($a == $b);
17             assert_eq!(nop($a), nop($b));
18         }
19     };
20 }
21
22 macro_rules! suite {
23     ( $( $tt:tt )* ) => {
24         fn f32() {
25             suite_inner!(f32 $($tt)*);
26         }
27
28         fn f64() {
29             suite_inner!(f64 $($tt)*);
30         }
31     }
32
33 }
34
35 macro_rules! suite_inner {
36     (
37         $ty:ident [$( $fn:ident ),*]
38         $val:expr => [$($out:ident),*]
39
40         $( $tail:tt )*
41     ) => {
42         $( const_assert!($ty::$fn($val), $out); )*
43         suite_inner!($ty [$($fn),*] $($tail)*)
44     };
45
46     ( $ty:ident [$( $fn:ident ),*]) => {};
47 }
48
49 #[derive(Debug)]
50 struct NonDet;
51
52 impl const PartialEq<NonDet> for bool {
53     fn eq(&self, _: &NonDet) -> bool {
54         true
55     }
56     fn ne(&self, _: &NonDet) -> bool {
57         false
58     }
59 }
60
61 // The result of the `is_sign` methods are not checked for correctness, since LLVM does not
62 // guarantee anything about the signedness of NaNs. See
63 // https://github.com/rust-lang/rust/issues/55131.
64
65 suite! {
66                    [is_nan, is_infinite, is_finite, is_normal, is_sign_positive, is_sign_negative]
67      -0.0 / 0.0 => [  true,       false,     false,     false,           NonDet,           NonDet]
68       0.0 / 0.0 => [  true,       false,     false,     false,           NonDet,           NonDet]
69             1.0 => [ false,       false,      true,      true,             true,            false]
70            -1.0 => [ false,       false,      true,      true,            false,             true]
71             0.0 => [ false,       false,      true,     false,             true,            false]
72            -0.0 => [ false,       false,      true,     false,            false,             true]
73       1.0 / 0.0 => [ false,        true,     false,     false,             true,            false]
74      -1.0 / 0.0 => [ false,        true,     false,     false,            false,             true]
75 }
76
77 fn main() {
78     f32();
79     f64();
80 }