@@ -147,22 +147,42 @@ impl_from!(i16 => isize, #[stable(feature = "lossless_iusize_conv", since = "1.2
147147// https://www.cl.cam.ac.uk/techreports/UCAM-CL-TR-951.pdf
148148
149149// 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
151155// 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).
152159
153160// signed integer -> float
161+ impl_from ! ( i8 => f16, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
154162impl_from ! ( i8 => f32 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
155163impl_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" ) ] ) ;
156165impl_from ! ( i16 => f32 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
157166impl_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" ) ] ) ;
158168impl_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")]);
159172
160173// unsigned integer -> float
174+ impl_from ! ( u8 => f16, #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
161175impl_from ! ( u8 => f32 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
162176impl_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" ) ] ) ;
163179impl_from ! ( u16 => f32 , #[ stable( feature = "lossless_float_conv" , since = "1.6.0" ) ] ) ;
164180impl_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" ) ] ) ;
165182impl_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")]);
166186
167187// float -> float
168188// FIXME(f16_f128): adding additional `From<{float}>` impls to `f32` breaks inference. See
@@ -198,8 +218,10 @@ macro_rules! impl_float_from_bool {
198218}
199219
200220// boolean -> float
221+ impl_float_from_bool ! ( f16) ;
201222impl_float_from_bool ! ( f32 ) ;
202223impl_float_from_bool ! ( f64 ) ;
224+ impl_float_from_bool ! ( f128) ;
203225
204226// no possible bounds violation
205227macro_rules! impl_try_from_unbounded {
0 commit comments