Skip to content

Commit 2093b65

Browse files
committed
---
yaml --- r: 563 b: refs/heads/master c: a2bd79a h: refs/heads/master i: 561: 9bf6089 559: 34142c9 v: v3
1 parent a0377d4 commit 2093b65

File tree

2 files changed

+38
-20
lines changed

2 files changed

+38
-20
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: db377bae3a1d9b980ea6eb6f1daf3a72bdeb7b25
2+
refs/heads/master: a2bd79a6acc9fc9f1dba6e718c9d9eda7791a277

trunk/src/lib/_uint.rs

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,33 +36,51 @@ fn next_power_of_two(uint n) -> uint {
3636
fn to_str(mutable uint n, uint radix) -> str
3737
{
3838
check (0u < radix && radix <= 16u);
39-
fn digit(uint n) -> str {
39+
fn digit(uint n) -> char {
4040
alt (n) {
41-
case (0u) { ret "0"; }
42-
case (1u) { ret "1"; }
43-
case (2u) { ret "2"; }
44-
case (3u) { ret "3"; }
45-
case (4u) { ret "4"; }
46-
case (5u) { ret "5"; }
47-
case (6u) { ret "6"; }
48-
case (7u) { ret "7"; }
49-
case (8u) { ret "8"; }
50-
case (9u) { ret "9"; }
51-
case (10u) { ret "a"; }
52-
case (11u) { ret "b"; }
53-
case (12u) { ret "c"; }
54-
case (13u) { ret "d"; }
55-
case (14u) { ret "e"; }
56-
case (15u) { ret "f"; }
41+
case (0u) { ret '0'; }
42+
case (1u) { ret '1'; }
43+
case (2u) { ret '2'; }
44+
case (3u) { ret '3'; }
45+
case (4u) { ret '4'; }
46+
case (5u) { ret '5'; }
47+
case (6u) { ret '6'; }
48+
case (7u) { ret '7'; }
49+
case (8u) { ret '8'; }
50+
case (9u) { ret '9'; }
51+
case (10u) { ret 'a'; }
52+
case (11u) { ret 'b'; }
53+
case (12u) { ret 'c'; }
54+
case (13u) { ret 'd'; }
55+
case (14u) { ret 'e'; }
56+
case (15u) { ret 'f'; }
5757
}
5858
}
5959

6060
if (n == 0u) { ret "0"; }
6161

62+
let uint r = 1u;
63+
if (n > r) {
64+
while ((r*radix) < n) {
65+
r *= radix;
66+
}
67+
}
68+
6269
let str s = "";
6370
while (n > 0u) {
64-
s = digit(n % radix) + s;
65-
n /= radix;
71+
72+
auto i = n/r;
73+
74+
n -= (i * r);
75+
r /= radix;
76+
77+
s += digit(i) as u8;
78+
}
79+
80+
while (r > 0u) {
81+
s += '0' as u8;
82+
r /= radix;
6683
}
84+
6785
ret s;
6886
}

0 commit comments

Comments
 (0)