diff options
| author | Phlosioneer <mattmdrr2@gmail.com> | 2018-03-08 02:31:15 -0500 |
|---|---|---|
| committer | Phlosioneer <mattmdrr2@gmail.com> | 2018-03-19 01:39:38 -0400 |
| commit | 5258af398aced119ad5ac40192fa131a2f2827d4 (patch) | |
| tree | 2ba013cb45820a59e7492790808b6b855422026d | |
| parent | 612c4a95bce4c4dc0cddc5ab374fcb262039aede (diff) | |
| download | rust-5258af398aced119ad5ac40192fa131a2f2827d4.tar.gz rust-5258af398aced119ad5ac40192fa131a2f2827d4.zip | |
Make Wrapping::pow use wrapping_pow, add example
| -rw-r--r-- | src/libcore/num/wrapping.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/libcore/num/wrapping.rs b/src/libcore/num/wrapping.rs index 6c110aa0523..fb79ddd0951 100644 --- a/src/libcore/num/wrapping.rs +++ b/src/libcore/num/wrapping.rs @@ -606,10 +606,23 @@ macro_rules! wrapping_int_impl { /// let x: Wrapping<i32> = Wrapping(2); // or any other integer type /// /// assert_eq!(x.pow(4), Wrapping(16)); + /// ``` + /// + /// Results that are too large are wrapped: + /// + /// ``` + /// #![feature(wrapping_int_impl)] + /// use std::num::Wrapping; + /// + /// // 5 ^ 4 = 625, which is too big for a u8 + /// let x: Wrapping<u8> = Wrapping(5); + /// + /// assert_eq!(x.pow(4).0, 113); + /// ``` #[inline] #[unstable(feature = "wrapping_int_impl", issue = "32463")] pub fn pow(self, exp: u32) -> Self { - Wrapping(self.0.pow(exp)) + Wrapping(self.0.wrapping_pow(exp)) } } )*) @@ -651,6 +664,3 @@ mod shift_max { pub const u64: u32 = i64; pub use self::platform::usize; } - - - |
