summary refs log tree commit diff
path: root/src/libcore/num
diff options
context:
space:
mode:
authorJosh Stone <cuviper@gmail.com>2015-10-17 16:27:31 -0700
committerJosh Stone <cuviper@gmail.com>2015-10-17 16:27:31 -0700
commit00d8d7bc04a882926829c65b9d6ff6448b22cfef (patch)
tree5930431bc91a0064a1a0994838377c550aa80389 /src/libcore/num
parent206af38e74ce7fa4b0e781ece7f1067c018c580e (diff)
downloadrust-00d8d7bc04a882926829c65b9d6ff6448b22cfef.tar.gz
rust-00d8d7bc04a882926829c65b9d6ff6448b22cfef.zip
Implement conversion traits for primitive float types
Diffstat (limited to 'src/libcore/num')
-rw-r--r--src/libcore/num/mod.rs23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index 8b005b2f8ba..38ad19c3cbe 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -1473,14 +1473,14 @@ impl fmt::Display for ParseIntError {
 
 pub use num::dec2flt::ParseFloatError;
 
-// Conversion traits for primitive integer types
+// Conversion traits for primitive integer and float types
 // Conversions T -> T are covered by a blanket impl and therefore excluded
 // Some conversions from and to usize/isize are not implemented due to portability concerns
 macro_rules! impl_from {
     ($Small: ty, $Large: ty) => {
-        #[stable(feature = "lossless_int_conv", since = "1.5.0")]
+        #[stable(feature = "lossless_prim_conv", since = "1.5.0")]
         impl From<$Small> for $Large {
-            #[stable(feature = "lossless_int_conv", since = "1.5.0")]
+            #[stable(feature = "lossless_prim_conv", since = "1.5.0")]
             #[inline]
             fn from(small: $Small) -> $Large {
                 small as $Large
@@ -1514,3 +1514,20 @@ impl_from! { u8, i64 }
 impl_from! { u16, i32 }
 impl_from! { u16, i64 }
 impl_from! { u32, i64 }
+
+// Signed -> Float
+impl_from! { i8, f32 }
+impl_from! { i8, f64 }
+impl_from! { i16, f32 }
+impl_from! { i16, f64 }
+impl_from! { i32, f64 }
+
+// Unsigned -> Float
+impl_from! { u8, f32 }
+impl_from! { u8, f64 }
+impl_from! { u16, f32 }
+impl_from! { u16, f64 }
+impl_from! { u32, f64 }
+
+// Float -> Float
+impl_from! { f32, f64 }