Rollup merge of #80959 - jhpratt:unsigned_abs-stabilization, r=m-ou-se
Stabilize `unsigned_abs` Resolves #74913. This PR stabilizes the `i*::unsigned_abs()` method, which returns the absolute value of an integer _as its unsigned equivalent_. This has the advantage that it does not overflow on `i*::MIN`. I have gone ahead and used this in a couple locations throughout the repository.
This commit is contained in:
commit
91ea1cbc17
6 changed files with 8 additions and 17 deletions
|
@ -1158,12 +1158,12 @@ macro_rules! int_impl {
|
|||
/// Basic usage:
|
||||
///
|
||||
/// ```
|
||||
/// #![feature(unsigned_abs)]
|
||||
#[doc = concat!("assert_eq!(100", stringify!($SelfT), ".unsigned_abs(), 100", stringify!($UnsignedT), ");")]
|
||||
#[doc = concat!("assert_eq!((-100", stringify!($SelfT), ").unsigned_abs(), 100", stringify!($UnsignedT), ");")]
|
||||
/// assert_eq!((-128i8).unsigned_abs(), 128u8);
|
||||
/// ```
|
||||
#[unstable(feature = "unsigned_abs", issue = "74913")]
|
||||
#[stable(feature = "unsigned_abs", since = "1.51.0")]
|
||||
#[rustc_const_stable(feature = "unsigned_abs", since = "1.51.0")]
|
||||
#[inline]
|
||||
pub const fn unsigned_abs(self) -> $UnsignedT {
|
||||
self.wrapping_abs() as $UnsignedT
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue