Skip to content

Commit 02aa39f

Browse files
committed
Make Wrapping::pow use wrapping_pow, add example
1 parent 7e346df commit 02aa39f

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/libcore/num/wrapping.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -606,10 +606,23 @@ macro_rules! wrapping_int_impl {
606606
/// let x: Wrapping<i32> = Wrapping(2); // or any other integer type
607607
///
608608
/// assert_eq!(x.pow(4), Wrapping(16));
609+
/// ```
610+
///
611+
/// Results that are too large are wrapped:
612+
///
613+
/// ```
614+
/// #![feature(wrapping_int_impl)]
615+
/// use std::num::Wrapping;
616+
///
617+
/// // 5 ^ 4 = 625, which is too big for a u8
618+
/// let x: Wrapping<u8> = Wrapping(5);
619+
///
620+
/// assert_eq!(x.pow(4).0, 113);
621+
/// ```
609622
#[inline]
610623
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
611624
pub fn pow(self, exp: u32) -> Self {
612-
Wrapping(self.0.pow(exp))
625+
Wrapping(self.0.wrapping_pow(exp))
613626
}
614627
}
615628
)*)
@@ -651,6 +664,3 @@ mod shift_max {
651664
pub const u64: u32 = i64;
652665
pub use self::platform::usize;
653666
}
654-
655-
656-

0 commit comments

Comments
 (0)