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
@@ -23,6 +24,23 @@ macro_rules! const_assert {
23
24
} ;
24
25
}
25
26
27
+ fn f16 ( ) {
28
+ const_assert ! ( ( 1 f16) . to_bits( ) , 0x3c00 ) ;
29
+ const_assert ! ( u16 :: from_be_bytes( 1 f16. 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 ! ( ( 1337 f16) . to_bits( ) , 0x6539 ) ;
33
+ const_assert ! ( u16 :: from_ne_bytes( 1337 f16. 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
+
26
44
fn f32 ( ) {
27
45
const_assert ! ( ( 1f32 ) . to_bits( ) , 0x3f800000 ) ;
28
46
const_assert ! ( u32 :: from_be_bytes( 1f32 . to_be_bytes( ) ) , 0x3f800000 ) ;
@@ -57,7 +75,26 @@ fn f64() {
57
75
const_assert ! ( f64 :: from_bits( 0xc02c800000000000 ) , -14.25 ) ;
58
76
}
59
77
78
+ fn f128 ( ) {
79
+ const_assert ! ( ( 1 f128) . to_bits( ) , 0x3fff0000000000000000000000000000 ) ;
80
+ const_assert ! ( u128 :: from_be_bytes( 1 f128. 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 ! ( ( 1337 f128) . to_bits( ) , 0x40094e40000000000000000000000000 ) ;
84
+ const_assert ! ( u128 :: from_ne_bytes( 1337 f128. 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
+
60
95
fn main ( ) {
96
+ f16 ( ) ;
61
97
f32 ( ) ;
62
98
f64 ( ) ;
99
+ f128 ( ) ;
63
100
}
0 commit comments