Permalink
Browse files

Add Int.lsb to setting.

Like Int.msb in the previous commit, this is also a
"something that works" implementation.  More elegant or
performant solutions are welcomed.
  • Loading branch information...
1 parent ee11f77 commit cd5ca7c6d0074018dd4d0b6fb3a651ea66c94262 @pmichaud pmichaud committed May 30, 2013
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/core/Int.pm
View
@@ -65,6 +65,15 @@ my class Int does Real {
method round(Int:D:) { self }
method ceiling(Int:D:) { self }
+ method lsb(Int:D:) {
+ return Nil if self == 0;
+ my $lsb = 0;
+ my $x = self.abs;
+ while $x +& 0xff == 0 { $lsb += 8; $x +>= 8; }
+ while $x +& 0x01 == 0 { $lsb++; $x +>= 1; }
+ $lsb;
+ }
+
method msb(Int:D:) {
return Nil if self == 0;
return 0 if self == -1;
@@ -276,9 +285,8 @@ multi sub expmod(\base, \exp, \mod) {
nqp::expmod_I(nqp::p6decont(base.Int), nqp::p6decont(exp.Int), nqp::p6decont(mod.Int), Int);
}
+proto sub lsb($) {*}
+multi sub lsb(Int:D \i) { i.lsb }
+
proto sub msb($) {*}
multi sub msb(Int:D \i) { i.msb }
-
-# proto sub lsb($) {*}
-# multi sub lsb(Int:D \i) { i.lsb }
-

0 comments on commit cd5ca7c

Please sign in to comment.