aboutsummaryrefslogtreecommitdiff
path: root/src/lib/_uint.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-09-22 15:44:13 -0700
committerGraydon Hoare <[email protected]>2010-09-22 15:44:13 -0700
commit2880ecd73ff7443ad72eb7af3c85e673024fc7fd (patch)
treeb9e703a5e279db41fa36bdbe9674abe8f159e91c /src/lib/_uint.rs
parentMove llvm-using code in rustc to trans module. (diff)
downloadrust-2880ecd73ff7443ad72eb7af3c85e673024fc7fd.tar.xz
rust-2880ecd73ff7443ad72eb7af3c85e673024fc7fd.zip
Reformat standard library; no code changes.
Diffstat (limited to 'src/lib/_uint.rs')
-rw-r--r--src/lib/_uint.rs113
1 files changed, 61 insertions, 52 deletions
diff --git a/src/lib/_uint.rs b/src/lib/_uint.rs
index f3a6f935..0930cadc 100644
--- a/src/lib/_uint.rs
+++ b/src/lib/_uint.rs
@@ -14,73 +14,82 @@ fn ge(uint x, uint y) -> bool { ret x >= y; }
fn gt(uint x, uint y) -> bool { ret x > y; }
iter range(mutable uint lo, uint hi) -> uint {
- while (lo < hi) {
- put lo;
- lo += 1u;
- }
+ while (lo < hi) {
+ put lo;
+ lo += 1u;
+ }
}
fn next_power_of_two(uint n) -> uint {
- // FIXME change |* uint(4)| below to |* uint(8) / uint(2)| and watch the
- // world explode.
- let uint halfbits = sys.rustrt.size_of[uint]() * 4u;
- let uint tmp = n - 1u;
- let uint shift = 1u;
- while (shift <= halfbits) {
- tmp |= tmp >> shift;
- shift <<= 1u;
- }
- ret tmp + 1u;
+ // FIXME change |* uint(4)| below to |* uint(8) / uint(2)| and watch the
+ // world explode.
+ let uint halfbits = sys.rustrt.size_of[uint]() * 4u;
+ let uint tmp = n - 1u;
+ let uint shift = 1u;
+ while (shift <= halfbits) {
+ tmp |= tmp >> shift;
+ shift <<= 1u;
+ }
+ ret tmp + 1u;
}
fn to_str(mutable uint n, uint radix) -> str
{
- check (0u < radix && radix <= 16u);
- fn digit(uint n) -> char {
- alt (n) {
- case (0u) { ret '0'; }
- case (1u) { ret '1'; }
- case (2u) { ret '2'; }
- case (3u) { ret '3'; }
- case (4u) { ret '4'; }
- case (5u) { ret '5'; }
- case (6u) { ret '6'; }
- case (7u) { ret '7'; }
- case (8u) { ret '8'; }
- case (9u) { ret '9'; }
- case (10u) { ret 'a'; }
- case (11u) { ret 'b'; }
- case (12u) { ret 'c'; }
- case (13u) { ret 'd'; }
- case (14u) { ret 'e'; }
- case (15u) { ret 'f'; }
+ check (0u < radix && radix <= 16u);
+ fn digit(uint n) -> char {
+ alt (n) {
+ case (0u) { ret '0'; }
+ case (1u) { ret '1'; }
+ case (2u) { ret '2'; }
+ case (3u) { ret '3'; }
+ case (4u) { ret '4'; }
+ case (5u) { ret '5'; }
+ case (6u) { ret '6'; }
+ case (7u) { ret '7'; }
+ case (8u) { ret '8'; }
+ case (9u) { ret '9'; }
+ case (10u) { ret 'a'; }
+ case (11u) { ret 'b'; }
+ case (12u) { ret 'c'; }
+ case (13u) { ret 'd'; }
+ case (14u) { ret 'e'; }
+ case (15u) { ret 'f'; }
+ }
}
- }
- if (n == 0u) { ret "0"; }
+ if (n == 0u) { ret "0"; }
- let uint r = 1u;
- if (n > r) {
- while ((r*radix) <= n) {
- r *= radix;
+ let uint r = 1u;
+ if (n > r) {
+ while ((r*radix) <= n) {
+ r *= radix;
+ }
}
- }
- let str s = "";
- while (n > 0u) {
+ let str s = "";
+ while (n > 0u) {
- auto i = n/r;
+ auto i = n/r;
- n -= (i * r);
- r /= radix;
+ n -= (i * r);
+ r /= radix;
- s += digit(i) as u8;
- }
+ s += digit(i) as u8;
+ }
- while (r > 0u) {
- s += '0' as u8;
- r /= radix;
- }
+ while (r > 0u) {
+ s += '0' as u8;
+ r /= radix;
+ }
- ret s;
+ ret s;
}
+
+// Local Variables:
+// mode: rust;
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// compile-command: "make -k -C .. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
+// End: