]> git.lizzy.rs Git - rust.git/commitdiff
Make Wrapping::pow use wrapping_pow, add example
authorPhlosioneer <mattmdrr2@gmail.com>
Thu, 8 Mar 2018 07:31:15 +0000 (02:31 -0500)
committerPhlosioneer <mattmdrr2@gmail.com>
Mon, 19 Mar 2018 05:39:38 +0000 (01:39 -0400)
src/libcore/num/wrapping.rs

index 6c110aa052311ab5bc24fd742021e337ec94d11b..fb79ddd09517293884ad915270f7809db408bcaa 100644 (file)
@@ -606,10 +606,23 @@ pub fn to_le(self) -> Self {
             /// 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 platform {
     pub const u64: u32 = i64;
     pub use self::platform::usize;
 }
-
-
-