aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoy Frostig <[email protected]>2010-08-26 11:57:14 -0700
committerRoy Frostig <[email protected]>2010-08-26 11:57:48 -0700
commitc3c5e6c77388f3f81449c668e6a97b064cf41852 (patch)
tree6400455bc309e7eef62b8aafe3a7262b51be23b7 /src
parentAdd a "param handler" to demand_fn for use in automatic type parameter instan... (diff)
downloadrust-c3c5e6c77388f3f81449c668e6a97b064cf41852.tar.xz
rust-c3c5e6c77388f3f81449c668e6a97b064cf41852.zip
Workaround issue #152 in _uint.next_power_of_two
Diffstat (limited to 'src')
-rw-r--r--src/Makefile1
-rw-r--r--src/lib/_uint.rs4
-rw-r--r--src/test/run-pass/lib-uint.rs47
3 files changed, 51 insertions, 1 deletions
diff --git a/src/Makefile b/src/Makefile
index 558ba771..8faf8ed5 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -491,6 +491,7 @@ TEST_XFAILS_LLVM := $(TASK_XFAILS) \
lib-rand.rs \
lib-str.rs \
lib-task.rs \
+ lib-uint.rs \
lib-vec.rs \
lib-vec-str-conversions.rs \
linear-for-loop.rs \
diff --git a/src/lib/_uint.rs b/src/lib/_uint.rs
index f3a6f935..2c2629c9 100644
--- a/src/lib/_uint.rs
+++ b/src/lib/_uint.rs
@@ -28,7 +28,9 @@ fn next_power_of_two(uint n) -> uint {
let uint shift = 1u;
while (shift <= halfbits) {
tmp |= tmp >> shift;
- shift <<= 1u;
+ // FIXME (issue #152): This would be just a tad cuter if it were
+ // shift <<= 1u
+ shift = shift << 1u;
}
ret tmp + 1u;
}
diff --git a/src/test/run-pass/lib-uint.rs b/src/test/run-pass/lib-uint.rs
new file mode 100644
index 00000000..356ca374
--- /dev/null
+++ b/src/test/run-pass/lib-uint.rs
@@ -0,0 +1,47 @@
+// -*- rust -*-
+
+use std;
+import std._uint;
+
+fn main() {
+ check (_uint.next_power_of_two(0u) == 0u);
+ check (_uint.next_power_of_two(1u) == 1u);
+ check (_uint.next_power_of_two(2u) == 2u);
+ check (_uint.next_power_of_two(3u) == 4u);
+ check (_uint.next_power_of_two(4u) == 4u);
+ check (_uint.next_power_of_two(5u) == 8u);
+ check (_uint.next_power_of_two(6u) == 8u);
+ check (_uint.next_power_of_two(7u) == 8u);
+ check (_uint.next_power_of_two(8u) == 8u);
+ check (_uint.next_power_of_two(9u) == 16u);
+ check (_uint.next_power_of_two(10u) == 16u);
+ check (_uint.next_power_of_two(11u) == 16u);
+ check (_uint.next_power_of_two(12u) == 16u);
+ check (_uint.next_power_of_two(13u) == 16u);
+ check (_uint.next_power_of_two(14u) == 16u);
+ check (_uint.next_power_of_two(15u) == 16u);
+ check (_uint.next_power_of_two(16u) == 16u);
+ check (_uint.next_power_of_two(17u) == 32u);
+ check (_uint.next_power_of_two(18u) == 32u);
+ check (_uint.next_power_of_two(19u) == 32u);
+ check (_uint.next_power_of_two(20u) == 32u);
+ check (_uint.next_power_of_two(21u) == 32u);
+ check (_uint.next_power_of_two(22u) == 32u);
+ check (_uint.next_power_of_two(23u) == 32u);
+ check (_uint.next_power_of_two(24u) == 32u);
+ check (_uint.next_power_of_two(25u) == 32u);
+ check (_uint.next_power_of_two(26u) == 32u);
+ check (_uint.next_power_of_two(27u) == 32u);
+ check (_uint.next_power_of_two(28u) == 32u);
+ check (_uint.next_power_of_two(29u) == 32u);
+ check (_uint.next_power_of_two(30u) == 32u);
+ check (_uint.next_power_of_two(31u) == 32u);
+ check (_uint.next_power_of_two(32u) == 32u);
+ check (_uint.next_power_of_two(33u) == 64u);
+ check (_uint.next_power_of_two(34u) == 64u);
+ check (_uint.next_power_of_two(35u) == 64u);
+ check (_uint.next_power_of_two(36u) == 64u);
+ check (_uint.next_power_of_two(37u) == 64u);
+ check (_uint.next_power_of_two(38u) == 64u);
+ check (_uint.next_power_of_two(39u) == 64u);
+}