diff options
| author | bors <bors@rust-lang.org> | 2017-06-08 01:07:08 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-06-08 01:07:08 +0000 |
| commit | d8d5592596b75ff1b810c15944e6bac57ab9c15a (patch) | |
| tree | 2843e9a6392fc984d574a74727caab4e34da2c83 /src/libstd | |
| parent | 03eb7109c722117322064390bc66578cde3f7b8e (diff) | |
| parent | 18fadb61c4aab3d1b2fc49ac7d7fea85b3914fb3 (diff) | |
| download | rust-d8d5592596b75ff1b810c15944e6bac57ab9c15a.tar.gz rust-d8d5592596b75ff1b810c15944e6bac57ab9c15a.zip | |
Auto merge of #40706 - irfanhudda:doc-next-power-of-two, r=alexcrichton
Improve documentation of next_power_of_two Clarify overflow behavior of `next_power_of_two`. Related Issue: #18604
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/num.rs | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libstd/num.rs b/src/libstd/num.rs index ff89887ac92..a2c133954a3 100644 --- a/src/libstd/num.rs +++ b/src/libstd/num.rs @@ -173,7 +173,10 @@ mod tests { fn $test_name() { #![test] assert_eq!((0 as $T).checked_next_power_of_two(), Some(1)); - assert!(($T::MAX / 2).checked_next_power_of_two().is_some()); + let smax = $T::MAX >> 1; + assert_eq!(smax.checked_next_power_of_two(), Some(smax+1)); + assert_eq!((smax + 1).checked_next_power_of_two(), Some(smax + 1)); + assert_eq!((smax + 2).checked_next_power_of_two(), None); assert_eq!(($T::MAX - 1).checked_next_power_of_two(), None); assert_eq!($T::MAX.checked_next_power_of_two(), None); let mut next_power = 1; |
