File tree 1 file changed +14
-4
lines changed
1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -606,10 +606,23 @@ macro_rules! wrapping_int_impl {
606
606
/// let x: Wrapping<i32> = Wrapping(2); // or any other integer type
607
607
///
608
608
/// 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
+ /// ```
609
622
#[ inline]
610
623
#[ unstable( feature = "wrapping_int_impl" , issue = "32463" ) ]
611
624
pub fn pow( self , exp: u32 ) -> Self {
612
- Wrapping ( self . 0 . pow ( exp) )
625
+ Wrapping ( self . 0 . wrapping_pow ( exp) )
613
626
}
614
627
}
615
628
) * )
@@ -651,6 +664,3 @@ mod shift_max {
651
664
pub const u64: u32 = i64;
652
665
pub use self :: platform:: usize;
653
666
}
654
-
655
-
656
-
You can’t perform that action at this time.
0 commit comments