mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
Rollup merge of #111186 - jmillikin:nonzero-is-positive, r=dtolnay
Add `is_positive` method for signed non-zero integers. ACP: https://github.com/rust-lang/libs-team/issues/105
This commit is contained in:
commit
ab80b7a53d
@ -713,6 +713,32 @@ macro_rules! nonzero_signed_operations {
|
|||||||
unsafe { $Uty::new_unchecked(self.get().unsigned_abs()) }
|
unsafe { $Uty::new_unchecked(self.get().unsigned_abs()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if `self` is positive and `false` if the
|
||||||
|
/// number is negative.
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// #![feature(nonzero_negation_ops)]
|
||||||
|
///
|
||||||
|
#[doc = concat!("# use std::num::", stringify!($Ty), ";")]
|
||||||
|
/// # fn main() { test().unwrap(); }
|
||||||
|
/// # fn test() -> Option<()> {
|
||||||
|
#[doc = concat!("let pos_five = ", stringify!($Ty), "::new(5)?;")]
|
||||||
|
#[doc = concat!("let neg_five = ", stringify!($Ty), "::new(-5)?;")]
|
||||||
|
///
|
||||||
|
/// assert!(pos_five.is_positive());
|
||||||
|
/// assert!(!neg_five.is_positive());
|
||||||
|
/// # Some(())
|
||||||
|
/// # }
|
||||||
|
/// ```
|
||||||
|
#[must_use]
|
||||||
|
#[inline]
|
||||||
|
#[unstable(feature = "nonzero_negation_ops", issue = "102443")]
|
||||||
|
pub const fn is_positive(self) -> bool {
|
||||||
|
self.get().is_positive()
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if `self` is negative and `false` if the
|
/// Returns `true` if `self` is negative and `false` if the
|
||||||
/// number is positive.
|
/// number is positive.
|
||||||
///
|
///
|
||||||
|
Loading…
Reference in New Issue
Block a user