Skip to content

Commit c3c5e6c

Browse files
committed
Workaround issue #152 in _uint.next_power_of_two
1 parent de5c6f1 commit c3c5e6c

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ TEST_XFAILS_LLVM := $(TASK_XFAILS) \
491491
lib-rand.rs \
492492
lib-str.rs \
493493
lib-task.rs \
494+
lib-uint.rs \
494495
lib-vec.rs \
495496
lib-vec-str-conversions.rs \
496497
linear-for-loop.rs \

src/lib/_uint.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ fn next_power_of_two(uint n) -> uint {
2828
let uint shift = 1u;
2929
while (shift <= halfbits) {
3030
tmp |= tmp >> shift;
31-
shift <<= 1u;
31+
// FIXME (issue #152): This would be just a tad cuter if it were
32+
// shift <<= 1u
33+
shift = shift << 1u;
3234
}
3335
ret tmp + 1u;
3436
}

src/test/run-pass/lib-uint.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// -*- rust -*-
2+
3+
use std;
4+
import std._uint;
5+
6+
fn main() {
7+
check (_uint.next_power_of_two(0u) == 0u);
8+
check (_uint.next_power_of_two(1u) == 1u);
9+
check (_uint.next_power_of_two(2u) == 2u);
10+
check (_uint.next_power_of_two(3u) == 4u);
11+
check (_uint.next_power_of_two(4u) == 4u);
12+
check (_uint.next_power_of_two(5u) == 8u);
13+
check (_uint.next_power_of_two(6u) == 8u);
14+
check (_uint.next_power_of_two(7u) == 8u);
15+
check (_uint.next_power_of_two(8u) == 8u);
16+
check (_uint.next_power_of_two(9u) == 16u);
17+
check (_uint.next_power_of_two(10u) == 16u);
18+
check (_uint.next_power_of_two(11u) == 16u);
19+
check (_uint.next_power_of_two(12u) == 16u);
20+
check (_uint.next_power_of_two(13u) == 16u);
21+
check (_uint.next_power_of_two(14u) == 16u);
22+
check (_uint.next_power_of_two(15u) == 16u);
23+
check (_uint.next_power_of_two(16u) == 16u);
24+
check (_uint.next_power_of_two(17u) == 32u);
25+
check (_uint.next_power_of_two(18u) == 32u);
26+
check (_uint.next_power_of_two(19u) == 32u);
27+
check (_uint.next_power_of_two(20u) == 32u);
28+
check (_uint.next_power_of_two(21u) == 32u);
29+
check (_uint.next_power_of_two(22u) == 32u);
30+
check (_uint.next_power_of_two(23u) == 32u);
31+
check (_uint.next_power_of_two(24u) == 32u);
32+
check (_uint.next_power_of_two(25u) == 32u);
33+
check (_uint.next_power_of_two(26u) == 32u);
34+
check (_uint.next_power_of_two(27u) == 32u);
35+
check (_uint.next_power_of_two(28u) == 32u);
36+
check (_uint.next_power_of_two(29u) == 32u);
37+
check (_uint.next_power_of_two(30u) == 32u);
38+
check (_uint.next_power_of_two(31u) == 32u);
39+
check (_uint.next_power_of_two(32u) == 32u);
40+
check (_uint.next_power_of_two(33u) == 64u);
41+
check (_uint.next_power_of_two(34u) == 64u);
42+
check (_uint.next_power_of_two(35u) == 64u);
43+
check (_uint.next_power_of_two(36u) == 64u);
44+
check (_uint.next_power_of_two(37u) == 64u);
45+
check (_uint.next_power_of_two(38u) == 64u);
46+
check (_uint.next_power_of_two(39u) == 64u);
47+
}

0 commit comments

Comments
 (0)