mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 13:05:18 +03:00
Add examples section which demonstrates the behaviour (specifically the sign positive aspect)
This commit is contained in:
@@ -174,6 +174,16 @@ macro_rules! impl_from_bool {
|
||||
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 @@ fn from(small: bool) -> Self {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user