about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorbmoxb <maxoblack@yahoo.com>2023-03-09 20:44:11 +0000
committerbmoxb <maxoblack@yahoo.com>2023-03-09 20:44:11 +0000
commitb439189236a8956eaf9cd37bd601f3df074716f2 (patch)
tree7006f8346e35c96fcc94aea916cce56eb5e435b0 /library/core/src
parent8d2bdb89c624d58feb0f077de6648787f8e6afbc (diff)
downloadrust-b439189236a8956eaf9cd37bd601f3df074716f2.tar.gz
rust-b439189236a8956eaf9cd37bd601f3df074716f2.zip
Add examples section which demonstrates the behaviour (specifically the sign positive aspect)
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/convert/num.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/library/core/src/convert/num.rs b/library/core/src/convert/num.rs
index baee008b7ed..a74a56bc5b2 100644
--- a/library/core/src/convert/num.rs
+++ b/library/core/src/convert/num.rs
@@ -174,6 +174,16 @@ impl_from! { f32, f64, #[stable(feature = "lossless_float_conv", since = "1.6.0"
 impl const From<bool> for f32 {
     /// Converts `bool` to `f32` losslessly. The resulting value is positive
     /// `0.0` for `false` and `1.0` for `true` values.
+    ///
+    /// # Examples
+    /// ```
+    /// let x: f32 = false.into();
+    /// assert_eq!(x, 0.0);
+    /// assert!(x.is_sign_positive());
+    ///
+    /// let y: f32 = true.into();
+    /// assert_eq!(y, 1.0);
+    /// ```
     #[inline]
     fn from(small: bool) -> Self {
         small as u8 as Self
@@ -184,6 +194,16 @@ impl const From<bool> for f32 {
 impl const From<bool> for f64 {
     /// Converts `bool` to `f64` losslessly. The resulting value is positive
     /// `0.0` for `false` and `1.0` for `true` values.
+    ///
+    /// # Examples
+    /// ```
+    /// let x: f64 = false.into();
+    /// assert_eq!(x, 0.0);
+    /// assert!(x.is_sign_positive());
+    ///
+    /// let y: f64 = true.into();
+    /// assert_eq!(y, 1.0);
+    /// ```
     #[inline]
     fn from(small: bool) -> Self {
         small as u8 as Self