diff options
| author | carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> | 2020-07-25 15:15:12 -0500 |
|---|---|---|
| committer | carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> | 2020-07-29 10:38:58 -0500 |
| commit | 784dd22aac3f58eebc73ff54ae0ea43682392e68 (patch) | |
| tree | ba19013062c19ed3724a40e1fde82b52db7a8581 | |
| parent | 2c28244cf0fc9868f55070e55b8f332d196eaf3f (diff) | |
| download | rust-784dd22aac3f58eebc73ff54ae0ea43682392e68.tar.gz rust-784dd22aac3f58eebc73ff54ae0ea43682392e68.zip | |
add `unsigned_abs` to signed integers
| -rw-r--r-- | library/core/src/num/mod.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 048c9c5ddaa..eb50dc28b9f 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -1602,6 +1602,29 @@ $EndFeature, " } 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. |
