September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,48 +0,0 @@
|
|||
sub bool ($a, $b) {
|
||||
say 'Coerce to Boolean';
|
||||
say_bool_buff "$a and $b", $a ?& $b;
|
||||
say_bool_buff "$a or $b", $a ?| $b;
|
||||
say_bool_buff "$a xor $b", $a ?^ $b;
|
||||
say_bool_buff "not $a", !$a;
|
||||
}
|
||||
|
||||
sub buf ($a, $b) {
|
||||
say 'Coerce to Buffer';
|
||||
say_bool_buff "$a and $b", $a ~& $b;
|
||||
say_bool_buff "$a or $b", $a ~| $b;
|
||||
say_bool_buff "$a xor $b", $a ~^ $b;
|
||||
# say_bool_buff "$a bit shift right $b", $a ~> $b; #NYI in Rakudo
|
||||
# say_bool_buff "$a bit shift left $b", $a ~< $b; #NYI in Rakudo
|
||||
}
|
||||
|
||||
sub int ($a, $b) {
|
||||
say 'Coerce to Int';
|
||||
say_bit "$a and $b", $a +& $b;
|
||||
say_bit "$a or $b", $a +| $b;
|
||||
say_bit "$a xor $b", $a +^ $b;
|
||||
say_bit "$a signed bit shift right $b", $a +> $b;
|
||||
# say_bit "$a unsigned bit shift right $b", $a +> $b :unsigned; #NYI in Rakudo
|
||||
# say_bit "$a rotate right $b", $a +> $b :rotate; #NYI in Rakudo
|
||||
say_bit "$a bit shift left $b", $a +< $b;
|
||||
# say_bit "$a rotate shift left $b", $a +< $b :rotate; #NYI in Rakudo
|
||||
say_bit "twos complement not $a", +^$a;
|
||||
|
||||
}
|
||||
|
||||
bool(7,2);
|
||||
say '-' x 80;
|
||||
buf(7,2);
|
||||
say '-' x 80;
|
||||
int(7,2);
|
||||
say '-' x 80;
|
||||
|
||||
|
||||
sub say_bit ($message, $value) {
|
||||
my $INTSIZE = $*VM{'config'}{'intvalsize'} * 8; # hack to get native Int size
|
||||
printf("%30s: %4d, %032b\n", $message, $value, $value) if $INTSIZE == 32;
|
||||
printf("%30s: %4d, %064b\n", $message, $value, $value) if $INTSIZE == 64;
|
||||
}
|
||||
|
||||
sub say_bool_buff ($message, $value) {
|
||||
printf("%30s: %4d, %s\n", $message, $value, $value);
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
sub infix:<bsr>( $a, $b, :$rotate, :$unsigned ) {
|
||||
if $rotate {
|
||||
my $INTSIZE = $*VM{'config'}{'intvalsize'} * 8; # hack to get native Int size
|
||||
my $c = $b % $INTSIZE;
|
||||
return pir::lsr__III($a, $c) +| pir::shl__III((2**$c-1) +& $a, $INTSIZE-$c);
|
||||
}
|
||||
if $unsigned {
|
||||
return pir::lsr__III($a, $b);
|
||||
}
|
||||
pir::shr__III($a, $b);
|
||||
}
|
||||
|
||||
sub infix:<bsl>( $a, $b, :$rotate, :$unsigned ) {
|
||||
if $rotate {
|
||||
my $INTSIZE = $*VM{'config'}{'intvalsize'} * 8; # hack to get native Int size
|
||||
my $c = $b % $INTSIZE;
|
||||
return pir::shl__III($a, $c) +| pir::lsr__III($a, $INTSIZE-$c);
|
||||
}
|
||||
pir::shl__III($a, $b);
|
||||
}
|
||||
|
||||
bs_int(7,2);
|
||||
|
||||
sub bs_int ($a, $b) {
|
||||
say_bit "$a Signed Bit shift right $b", $a bsr $b;
|
||||
say_bit "$a Unsigned Bit shift right $b", infix:<bsr>($a, $b, :unsigned);
|
||||
say_bit "$a Rotate right $b", infix:<bsr>($a, $b, :rotate);
|
||||
say_bit "$a Bit shift left $b", $a bsl $b;
|
||||
say_bit "$a Rotate left $b", infix:<bsl>($a, $b, :rotate);
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ constant BITS = MAXINT.base(2).chars;
|
|||
|
||||
# define rotate ops for the fun of it
|
||||
multi sub infix:<⥁>(Int:D \a, Int:D \b) { :2[(a +& MAXINT).polymod(2 xx BITS-1).list.rotate(b).reverse] }
|
||||
multi sub infix:<⥀>(Int:D \a, Int:D \b) { :2[(a +& MAXINT).polymod(2 xx BITS-1).reverse.rotate(b)] }
|
||||
multi sub infix:<⥀>(Int:D \a, Int:D \b) { :2[(a +& MAXINT).polymod(2 xx BITS-1).reverse.list.rotate(b)] }
|
||||
|
||||
sub int-bits (Int $a, Int $b) {
|
||||
say '';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue