mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-03 17:35:28 +03:00
add unsigned_abs to signed integers
This commit is contained in:
@@ -1601,6 +1601,29 @@ pub const fn wrapping_abs(self) -> Self {
|
||||
}
|
||||
}
|
||||
|
||||
doc_comment! {
|
||||
concat!("Computes the absolute value of `self` without any wrapping
|
||||
or panicking.
|
||||
|
||||
|
||||
# Examples
|
||||
|
||||
Basic usage:
|
||||
|
||||
```
|
||||
", $Feature, "#![feature(unsigned_abs)]
|
||||
assert_eq!(100", stringify!($SelfT), ".unsigned_abs(), 100", stringify!($UnsignedT), ");
|
||||
assert_eq!((-100", stringify!($SelfT), ").unsigned_abs(), 100", stringify!($UnsignedT), ");
|
||||
assert_eq!((-128i8).unsigned_abs(), 128u8);",
|
||||
$EndFeature, "
|
||||
```"),
|
||||
#[unstable(feature = "unsigned_abs", issue = "74913")]
|
||||
#[inline]
|
||||
pub const fn unsigned_abs(self) -> $UnsignedT {
|
||||
self.wrapping_abs() as $UnsignedT
|
||||
}
|
||||
}
|
||||
|
||||
doc_comment! {
|
||||
concat!("Wrapping (modular) exponentiation. Computes `self.pow(exp)`,
|
||||
wrapping around at the boundary of the type.
|
||||
|
||||
Reference in New Issue
Block a user