]>
Commit | Line | Data |
---|---|---|
3dfed10e XL |
1 | // compile-flags: -Zmir-opt-level=0 |
2 | // run-pass | |
3 | ||
3dfed10e XL |
4 | #![feature(const_float_bits_conv)] |
5 | #![feature(const_float_classify)] | |
04454e1e | 6 | #![allow(unused_macro_rules)] |
3dfed10e XL |
7 | |
8 | // Don't promote | |
9 | const fn nop<T>(x: T) -> T { x } | |
10 | ||
11 | macro_rules! const_assert { | |
12 | ($a:expr) => { | |
13 | { | |
14 | const _: () = assert!($a); | |
15 | assert!(nop($a)); | |
16 | } | |
17 | }; | |
18 | ($a:expr, $b:expr) => { | |
19 | { | |
20 | const _: () = assert!($a == $b); | |
21 | assert_eq!(nop($a), nop($b)); | |
22 | } | |
23 | }; | |
24 | } | |
25 | ||
26 | fn f32() { | |
27 | const_assert!((1f32).to_bits(), 0x3f800000); | |
28 | const_assert!(u32::from_be_bytes(1f32.to_be_bytes()), 0x3f800000); | |
29 | const_assert!((12.5f32).to_bits(), 0x41480000); | |
30 | const_assert!(u32::from_le_bytes(12.5f32.to_le_bytes()), 0x41480000); | |
31 | const_assert!((1337f32).to_bits(), 0x44a72000); | |
32 | const_assert!(u32::from_ne_bytes(1337f32.to_ne_bytes()), 0x44a72000); | |
33 | const_assert!((-14.25f32).to_bits(), 0xc1640000); | |
34 | const_assert!(f32::from_bits(0x3f800000), 1.0); | |
35 | const_assert!(f32::from_be_bytes(0x3f800000u32.to_be_bytes()), 1.0); | |
36 | const_assert!(f32::from_bits(0x41480000), 12.5); | |
37 | const_assert!(f32::from_le_bytes(0x41480000u32.to_le_bytes()), 12.5); | |
38 | const_assert!(f32::from_bits(0x44a72000), 1337.0); | |
39 | const_assert!(f32::from_ne_bytes(0x44a72000u32.to_ne_bytes()), 1337.0); | |
40 | const_assert!(f32::from_bits(0xc1640000), -14.25); | |
3dfed10e XL |
41 | } |
42 | ||
43 | fn f64() { | |
44 | const_assert!((1f64).to_bits(), 0x3ff0000000000000); | |
45 | const_assert!(u64::from_be_bytes(1f64.to_be_bytes()), 0x3ff0000000000000); | |
46 | const_assert!((12.5f64).to_bits(), 0x4029000000000000); | |
47 | const_assert!(u64::from_le_bytes(12.5f64.to_le_bytes()), 0x4029000000000000); | |
48 | const_assert!((1337f64).to_bits(), 0x4094e40000000000); | |
49 | const_assert!(u64::from_ne_bytes(1337f64.to_ne_bytes()), 0x4094e40000000000); | |
50 | const_assert!((-14.25f64).to_bits(), 0xc02c800000000000); | |
51 | const_assert!(f64::from_bits(0x3ff0000000000000), 1.0); | |
52 | const_assert!(f64::from_be_bytes(0x3ff0000000000000u64.to_be_bytes()), 1.0); | |
53 | const_assert!(f64::from_bits(0x4029000000000000), 12.5); | |
54 | const_assert!(f64::from_le_bytes(0x4029000000000000u64.to_le_bytes()), 12.5); | |
55 | const_assert!(f64::from_bits(0x4094e40000000000), 1337.0); | |
56 | const_assert!(f64::from_ne_bytes(0x4094e40000000000u64.to_ne_bytes()), 1337.0); | |
57 | const_assert!(f64::from_bits(0xc02c800000000000), -14.25); | |
3dfed10e XL |
58 | } |
59 | ||
60 | fn main() { | |
61 | f32(); | |
62 | f64(); | |
63 | } |