Skip to content

Commit c3ba654

Browse files
Added f16 and f128 to tests/ui/consts/const-float-bits-conv.rs
1 parent 54a50bd commit c3ba654

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

tests/ui/consts/const-float-bits-conv.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#![feature(const_float_bits_conv)]
55
#![feature(const_float_classify)]
66
#![allow(unused_macro_rules)]
7-
7+
#![feature(f16)]
8+
#![feature(f128)]
89
// Don't promote
910
const fn nop<T>(x: T) -> T { x }
1011

@@ -23,6 +24,23 @@ macro_rules! const_assert {
2324
};
2425
}
2526

27+
fn f16(){
28+
const_assert!((1f16).to_bits(), 0x3c00);
29+
const_assert!(u16::from_be_bytes(1f16.to_be_bytes()), 0x3c00);
30+
const_assert!((12.5f16).to_bits(), 0x4a40);
31+
const_assert!(u16::from_le_bytes(12.5f16.to_le_bytes()), 0x4a40);
32+
const_assert!((1337f16).to_bits(), 0x6539);
33+
const_assert!(u16::from_ne_bytes(1337f16.to_ne_bytes()), 0x6539);
34+
const_assert!((-14.25f16).to_bits(), 0xcb20);
35+
const_assert!(f16::from_bits(0x3c00), 1.0);
36+
const_assert!(f16::from_be_bytes(0x3c00u16.to_be_bytes()), 1.0);
37+
const_assert!(f16::from_bits(0x4a40), 12.5);
38+
const_assert!(f16::from_le_bytes(0x4a40u16.to_le_bytes()), 12.5);
39+
const_assert!(f16::from_bits(0x5be0), 252.0);
40+
const_assert!(f16::from_ne_bytes(0x5be0u16.to_ne_bytes()), 252.0);
41+
const_assert!(f16::from_bits(0xcb20), -14.25);
42+
}
43+
2644
fn f32() {
2745
const_assert!((1f32).to_bits(), 0x3f800000);
2846
const_assert!(u32::from_be_bytes(1f32.to_be_bytes()), 0x3f800000);
@@ -57,7 +75,26 @@ fn f64() {
5775
const_assert!(f64::from_bits(0xc02c800000000000), -14.25);
5876
}
5977

78+
fn f128() {
79+
const_assert!((1f128).to_bits(), 0x3fff0000000000000000000000000000);
80+
const_assert!(u128::from_be_bytes(1f128.to_be_bytes()), 0x3fff0000000000000000000000000000);
81+
const_assert!((12.5f128).to_bits(), 0x40029000000000000000000000000000);
82+
const_assert!(u128::from_le_bytes(12.5f128.to_le_bytes()), 0x40029000000000000000000000000000);
83+
const_assert!((1337f128).to_bits(), 0x40094e40000000000000000000000000);
84+
const_assert!(u128::from_ne_bytes(1337f128.to_ne_bytes()), 0x40094e40000000000000000000000000);
85+
const_assert!((-14.25f128).to_bits(), 0xc002c800000000000000000000000000);
86+
const_assert!(f128::from_bits(0x3fff0000000000000000000000000000), 1.0);
87+
const_assert!(f128::from_be_bytes(0x3fff0000000000000000000000000000u128.to_be_bytes()), 1.0);
88+
const_assert!(f128::from_bits(0x40029000000000000000000000000000), 12.5);
89+
const_assert!(f128::from_le_bytes(0x40029000000000000000000000000000u128.to_le_bytes()), 12.5);
90+
const_assert!(f128::from_bits(0x40094e40000000000000000000000000), 1337.0);
91+
const_assert!(f128::from_ne_bytes(0x40094e40000000000000000000000000u128.to_ne_bytes()), 1337.0);
92+
const_assert!(f128::from_bits(0xc002c800000000000000000000000000), -14.25);
93+
}
94+
6095
fn main() {
96+
f16();
6197
f32();
6298
f64();
99+
f128();
63100
}

0 commit comments

Comments
 (0)