4
4
#![ feature( const_float_bits_conv) ]
5
5
#![ feature( const_float_classify) ]
6
6
#![ allow( unused_macro_rules) ]
7
-
7
+ #![ feature( f16) ]
8
+ #![ feature( f128) ]
8
9
// Don't promote
9
10
const fn nop < T > ( x : T ) -> T { x }
10
11
@@ -28,6 +29,23 @@ fn has_broken_floats() -> bool {
28
29
std:: env:: var ( "TARGET" ) . is_ok_and ( |v| v. contains ( "i586" ) )
29
30
}
30
31
32
+ fn f16 ( ) {
33
+ const_assert ! ( ( 1 f16) . to_bits( ) , 0x3c00 ) ;
34
+ const_assert ! ( u16 :: from_be_bytes( 1 f16. 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 ! ( ( 1337 f16) . to_bits( ) , 0x6539 ) ;
38
+ const_assert ! ( u16 :: from_ne_bytes( 1337 f16. 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
+
31
49
fn f32 ( ) {
32
50
const_assert ! ( ( 1f32 ) . to_bits( ) , 0x3f800000 ) ;
33
51
const_assert ! ( u32 :: from_be_bytes( 1f32 . to_be_bytes( ) ) , 0x3f800000 ) ;
@@ -88,7 +106,43 @@ fn f64() {
88
106
}
89
107
}
90
108
109
+ fn f128 ( ) {
110
+ const_assert ! ( ( 1 f128) . to_bits( ) , 0x3fff0000000000000000000000000000 ) ;
111
+ const_assert ! ( u128 :: from_be_bytes( 1 f128. 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 ! ( ( 1337 f128) . to_bits( ) , 0x40094e40000000000000000000000000 ) ;
115
+ const_assert ! ( u128 :: from_ne_bytes( 1337 f128. 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 ! ( ( 1 f128) . to_bits( ) , 0x3fff0000000000000000000000000000 ) ;
128
+ const_assert ! ( u128 :: from_be_bytes( 1 f128. 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 ! ( ( 1337 f128) . to_bits( ) , 0x40094e40000000000000000000000000 ) ;
132
+ const_assert ! ( u128 :: from_ne_bytes( 1337 f128. 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
+
91
143
fn main ( ) {
144
+ f16 ( ) ;
92
145
f32 ( ) ;
93
146
f64 ( ) ;
147
+ f128 ( ) ;
94
148
}
0 commit comments