Skip to content

Commit

Permalink
Add missing Wrapping methods, use doc_comment!
Browse files Browse the repository at this point in the history
  • Loading branch information
clarfonthey committed May 8, 2018
1 parent b183bd0 commit a00e68d
Show file tree
Hide file tree
Showing 2 changed files with 486 additions and 199 deletions.
27 changes: 25 additions & 2 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> {
}
}

mod wrapping;

// All these modules are technically private and only exposed for coretests:
pub mod flt2dec;
pub mod dec2flt;
Expand All @@ -203,6 +201,8 @@ macro_rules! doc_comment {
};
}

mod wrapping;

// `Int` + `SignedInt` implemented for signed integers
macro_rules! int_impl {
($SelfT:ty, $ActualT:ident, $UnsignedT:ty, $BITS:expr, $Min:expr, $Max:expr, $Feature:expr,
Expand Down Expand Up @@ -3423,6 +3423,29 @@ $EndFeature, "
}
}

doc_comment! {
concat!("Returns the smallest power of two greater than or equal to `n`. If
the next power of two is greater than the type's maximum value,
the return value is wrapped to `0`.
# Examples
Basic usage:
```
#![feature(wrapping_int_impl)]
", $Feature, "
assert_eq!(2", stringify!($SelfT), ".wrapping_next_power_of_two(), 2);
assert_eq!(3", stringify!($SelfT), ".wrapping_next_power_of_two(), 4);
assert_eq!(", stringify!($SelfT), "::max_value().wrapping_next_power_of_two(), 0);",
$EndFeature, "
```"),
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
pub fn wrapping_next_power_of_two(self) -> Self {
self.one_less_than_next_power_of_two().wrapping_add(1)
}
}

/// Return the memory representation of this integer as a byte array.
///
/// The target platform’s native endianness is used.
Expand Down
Loading

0 comments on commit a00e68d

Please sign in to comment.