Skip to content

Commit

Permalink
simplify Cool.base by using the appropriate nqp op
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Dec 4, 2011
1 parent 7fd864b commit c97b172
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions src/core/Int.pm
Expand Up @@ -40,21 +40,10 @@ my class Int {

method sqrt(Int:D:) { nqp::p6box_n(nqp::sqrt_n(nqp::tonum_I(self))) }

method base(Cool $base) {
method base(Int:D: Cool $base) {
fail("base must be between 2 and 36, got $base") unless 2 <= $base <= 36;
my int $b = $base.Int;
my @conversion = qw/0 1 2 3 4 5 6 7 8 9
A B C D E F G H I J
K L M N O P Q R S T
U V W X Y Z/;
my @res;
my int $n = self.abs;
repeat {
push @res, @conversion[$n % $b];
$n = $n div $b;
} while $n > 0;
push @res, '-' if self < 0;
join '', @res.reverse;
my int $b = nqp::unbox_i($base.Int);
nqp::p6box_s(nqp::base_I(self, $b));
}
}

Expand Down

0 comments on commit c97b172

Please sign in to comment.