Skip to content

Commit fb2a829

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

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

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

Lines changed: 55 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

@@ -28,6 +29,23 @@ fn has_broken_floats() -> bool {
2829
std::env::var("TARGET").is_ok_and(|v| v.contains("i586"))
2930
}
3031

32+
fn f16(){
33+
const_assert!((1f16).to_bits(), 0x3c00);
34+
const_assert!(u16::from_be_bytes(1f16.to_be_bytes()), 0x3c00);
35+
const_assert!((12.5f16).to_bits(), 0x4a40);
36+
const_assert!(u16::from_le_bytes(12.5f16.to_le_bytes()), 0x4a40);
37+
const_assert!((1337f16).to_bits(), 0x6539);
38+
const_assert!(u16::from_ne_bytes(1337f16.to_ne_bytes()), 0x6539);
39+
const_assert!((-14.25f16).to_bits(), 0xcb20);
40+
const_assert!(f16::from_bits(0x3c00), 1.0);
41+
const_assert!(f16::from_be_bytes(0x3c00u16.to_be_bytes()), 1.0);
42+
const_assert!(f16::from_bits(0x4a40), 12.5);
43+
const_assert!(f16::from_le_bytes(0x4a40u16.to_le_bytes()), 12.5);
44+
const_assert!(f16::from_bits(0x5be0), 252.0);
45+
const_assert!(f16::from_ne_bytes(0x5be0u16.to_ne_bytes()), 252.0);
46+
const_assert!(f16::from_bits(0xcb20), -14.25);
47+
}
48+
3149
fn f32() {
3250
const_assert!((1f32).to_bits(), 0x3f800000);
3351
const_assert!(u32::from_be_bytes(1f32.to_be_bytes()), 0x3f800000);
@@ -88,7 +106,43 @@ fn f64() {
88106
}
89107
}
90108

109+
fn f128() {
110+
const_assert!((1f128).to_bits(), 0x3fff0000000000000000000000000000);
111+
const_assert!(u128::from_be_bytes(1f128.to_be_bytes()), 0x3fff0000000000000000000000000000);
112+
const_assert!((12.5f128).to_bits(), 0x40029000000000000000000000000000);
113+
const_assert!(u128::from_le_bytes(12.5f128.to_le_bytes()), 0x40029000000000000000000000000000);
114+
const_assert!((1337f128).to_bits(), 0x40094e40000000000000000000000000);
115+
const_assert!(u128::from_ne_bytes(1337f128.to_ne_bytes()), 0x40094e40000000000000000000000000);
116+
const_assert!((-14.25f128).to_bits(), 0xc002c800000000000000000000000000);
117+
const_assert!(f128::from_bits(0x3fff0000000000000000000000000000), 1.0);
118+
const_assert!(f128::from_be_bytes(0x3fff0000000000000000000000000000u128.to_be_bytes()), 1.0);
119+
const_assert!(f128::from_bits(0x40029000000000000000000000000000), 12.5);
120+
const_assert!(f128::from_le_bytes(0x40029000000000000000000000000000u128.to_le_bytes()), 12.5);
121+
const_assert!(f128::from_bits(0x40094e40000000000000000000000000), 1337.0);
122+
const_assert!(f128::from_ne_bytes(0x40094e40000000000000000000000000u128.to_ne_bytes()), 1337.0);
123+
const_assert!(f128::from_bits(0xc002c800000000000000000000000000), -14.25);
124+
}
125+
126+
fn f128() {
127+
const_assert!((1f128).to_bits(), 0x3fff0000000000000000000000000000);
128+
const_assert!(u128::from_be_bytes(1f128.to_be_bytes()), 0x3fff0000000000000000000000000000);
129+
const_assert!((12.5f128).to_bits(), 0x40029000000000000000000000000000);
130+
const_assert!(u128::from_le_bytes(12.5f128.to_le_bytes()), 0x40029000000000000000000000000000);
131+
const_assert!((1337f128).to_bits(), 0x40094e40000000000000000000000000);
132+
const_assert!(u128::from_ne_bytes(1337f128.to_ne_bytes()), 0x40094e40000000000000000000000000);
133+
const_assert!((-14.25f128).to_bits(), 0xc002c800000000000000000000000000);
134+
const_assert!(f128::from_bits(0x3fff0000000000000000000000000000), 1.0);
135+
const_assert!(f128::from_be_bytes(0x3fff0000000000000000000000000000u128.to_be_bytes()), 1.0);
136+
const_assert!(f128::from_bits(0x40029000000000000000000000000000), 12.5);
137+
const_assert!(f128::from_le_bytes(0x40029000000000000000000000000000u128.to_le_bytes()), 12.5);
138+
const_assert!(f128::from_bits(0x40094e40000000000000000000000000), 1337.0);
139+
const_assert!(f128::from_ne_bytes(0x40094e40000000000000000000000000u128.to_ne_bytes()), 1337.0);
140+
const_assert!(f128::from_bits(0xc002c800000000000000000000000000), -14.25);
141+
}
142+
91143
fn main() {
144+
f16();
92145
f32();
93146
f64();
147+
f128();
94148
}

0 commit comments

Comments
 (0)