about summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrfan Hudda <irfanhudda@gmail.com>2017-05-23 23:04:23 +0530
committerIrfan Hudda <irfanhudda@gmail.com>2017-05-23 23:04:23 +0530
commit93219a262706447c52f3f20819e5caa7b2e2e3a2 (patch)
tree9ee76e09b4a65b338c5ba3eddb346b32e5ad0cd7
parented24829985cd01ae7ab980d785b6dff2e8332868 (diff)
downloadrust-93219a262706447c52f3f20819e5caa7b2e2e3a2.tar.gz
rust-93219a262706447c52f3f20819e5caa7b2e2e3a2.zip
Add comments to explain helper functions
-rw-r--r--src/libcore/num/mod.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index cc1f9ca79a1..8fd21d77dc3 100644
--- a/src/libcore/num/mod.rs
+++ b/src/libcore/num/mod.rs
@@ -2327,12 +2327,22 @@ macro_rules! uint_impl {
             (self.wrapping_sub(1)) & self == 0 && !(self == 0)
         }
 
+        // Returns one less than next greater power of two.
+        // (For 8u8 next greater power of two is 16u8 and for 6u8 it is 8u8)
+        //
+        // 8u8.round_up_to_one_less_than_a_power_of_two() == 15
+        // 6u8.round_up_to_one_less_than_a_power_of_two() == 7
         fn round_up_to_one_less_than_a_power_of_two(self) -> Self {
             let bits = size_of::<Self>() as u32 * 8;
             let z = self.leading_zeros();
             (if z == bits { 0 as Self } else { !0 }).wrapping_shr(z)
         }
 
+        // Returns one less than next power of two.
+        // (For 8u8 next power of two is 8u8 and for 6u8 it is 8u8)
+        //
+        // 8u8.one_less_than_next_power_of_two() == 7
+        // 6u8.one_less_than_next_power_of_two() == 7
         fn one_less_than_next_power_of_two(self) -> Self {
             self.wrapping_sub(1)
                 .round_up_to_one_less_than_a_power_of_two()
@@ -2340,10 +2350,10 @@ macro_rules! uint_impl {
         }
 
         /// Returns the smallest power of two greater than or equal to `self`.
-        /// When return value overflows, it panics in debug mode and return
-        /// value is wrapped in release mode.
         ///
-        /// More details about overflow behavior can be found in [RFC 560].
+        /// When return value overflows (i.e. `self > (1 << (N-1))` for type
+        /// `uN`), it panics in debug mode and return value is wrapped to 0 in
+        /// release mode (the only situation in which method can return 0).
         ///
         /// # Examples
         ///
@@ -2353,8 +2363,6 @@ macro_rules! uint_impl {
         /// assert_eq!(2u8.next_power_of_two(), 2);
         /// assert_eq!(3u8.next_power_of_two(), 4);
         /// ```
-        ///
-        /// [RFC 560]: https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md
         #[stable(feature = "rust1", since = "1.0.0")]
         #[inline]
         pub fn next_power_of_two(self) -> Self {