]> git.lizzy.rs Git - rust.git/blob - src/test/ui/consts/const-float-classify.rs
Rollup merge of #83634 - JohnTitor:proc-macro-ice, r=varkor
[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 }
57
58 // The result of the `is_sign` methods are not checked for correctness, since LLVM does not
59 // guarantee anything about the signedness of NaNs. See
60 // https://github.com/rust-lang/rust/issues/55131.
61
62 suite! {
63                    [is_nan, is_infinite, is_finite, is_normal, is_sign_positive, is_sign_negative]
64      -0.0 / 0.0 => [  true,       false,     false,     false,           NonDet,           NonDet]
65       0.0 / 0.0 => [  true,       false,     false,     false,           NonDet,           NonDet]
66             1.0 => [ false,       false,      true,      true,             true,            false]
67            -1.0 => [ false,       false,      true,      true,            false,             true]
68             0.0 => [ false,       false,      true,     false,             true,            false]
69            -0.0 => [ false,       false,      true,     false,            false,             true]
70       1.0 / 0.0 => [ false,        true,     false,     false,             true,            false]
71      -1.0 / 0.0 => [ false,        true,     false,     false,            false,             true]
72 }
73
74 fn main() {
75     f32();
76     f64();
77 }