Skip to content

Commit

Permalink
add unsigned_abs to signed integers
Browse files Browse the repository at this point in the history
  • Loading branch information
carbotaniuman committed Jul 29, 2020
1 parent 2c28244 commit 784dd22
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions library/core/src/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1601,6 +1601,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.
Expand Down

0 comments on commit 784dd22

Please sign in to comment.