@@ -147,22 +147,42 @@ impl_from!(i16 => isize, #[stable(feature = "lossless_iusize_conv", since = "1.2
147
147
// https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-951.pdf
148
148
149
149
// Note: integers can only be represented with full precision in a float if
150
- // they fit in the significand, which is 24 bits in f32 and 53 bits in f64.
150
+ // they fit in the significand, which is:
151
+ // * 11 bits in f16
152
+ // * 24 bits in f32
153
+ // * 53 bits in f64
154
+ // * 113 bits in f128
151
155
// Lossy float conversions are not implemented at this time.
156
+ // FIXME(f16_f128): The `f16`/`f128` impls #`[stable]` attributes should be changed to reference
157
+ // `f16`/`f128` when they are stabilised (trait impls have to have a `#[stable]` attribute, but none
158
+ // of the `f16`/`f128` impls can be used on stable as the `f16` and `f128` types are unstable).
152
159
153
160
// signed integer -> float
161
+ impl_from ! ( i8 => f16, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
154
162
impl_from ! ( i8 => f32 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
155
163
impl_from ! ( i8 => f64 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
164
+ impl_from ! ( i8 => f128, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
156
165
impl_from ! ( i16 => f32 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
157
166
impl_from ! ( i16 => f64 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
167
+ impl_from ! ( i16 => f128, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
158
168
impl_from ! ( i32 => f64 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
169
+ impl_from ! ( i32 => f128, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
170
+ // FIXME(f16_f128): This impl would allow using `f128` on stable before it is stabilised.
171
+ // impl_from!(i64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
159
172
160
173
// unsigned integer -> float
174
+ impl_from ! ( u8 => f16, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
161
175
impl_from ! ( u8 => f32 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
162
176
impl_from ! ( u8 => f64 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
177
+ impl_from ! ( u8 => f128, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
178
+ impl_from ! ( u16 => f16, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
163
179
impl_from ! ( u16 => f32 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
164
180
impl_from ! ( u16 => f64 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
181
+ impl_from ! ( u16 => f128, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
165
182
impl_from ! ( u32 => f64 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
183
+ impl_from ! ( u32 => f128, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
184
+ // FIXME(f16_f128): This impl would allow using `f128` on stable before it is stabilised.
185
+ // impl_from!(u64 => f128, #[stable(feature = "lossless_float_conv", since = "1.6.0")]);
166
186
167
187
// float -> float
168
188
// FIXME(f16_f128): adding additional `From<{float}>` impls to `f32` breaks inference. See
@@ -198,8 +218,10 @@ macro_rules! impl_float_from_bool {
198
218
}
199
219
200
220
// boolean -> float
221
+ impl_float_from_bool ! ( f16) ;
201
222
impl_float_from_bool ! ( f32 ) ;
202
223
impl_float_from_bool ! ( f64 ) ;
224
+ impl_float_from_bool ! ( f128) ;
203
225
204
226
// no possible bounds violation
205
227
macro_rules! impl_try_from_unbounded {
0 commit comments