Skip to content

Instantly share code, notes, and snippets.

@gerdr
Created July 3, 2013 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerdr/5920705 to your computer and use it in GitHub Desktop.
Save gerdr/5920705 to your computer and use it in GitHub Desktop.
shift tests
use v6;
use Test;
plan 60;
sub check ($a, $b, $ls, $rs) {
is $a * 2**$b, $ls, "expected value $ls for shl $a by $b is sane";
is floor($a / 2**$b), $rs, "expected value $rs for shr $a by $b is sane";
is $a +< $b, $ls, "got expected value $ls for shl $a by $b";
is $a +< -$b, $rs, "got expected value $rs for shl $a by -$b";
is $a +> $b, $rs, "got expected value $rs for shr $a by $b";
is $a +> -$b, $ls, "got expected value $ls for shr $a by -$b";
my int $na = $a;
my int $nb = $b;
is $na +< $nb, $ls, "got expected value $ls for native shl $a by $b";
is $na +< -$nb, $rs, "got expected value $rs for native shl $a by -$b";
is $na +> $nb, $rs, "got expected value $rs for native shr $a by $b";
is $na +> -$nb, $ls, "got expected value $ls for native shr $a by -$b";
}
check 15, 3, 120, 1;
check 16, 3, 128, 2;
check 17, 3, 136, 2;
check -15, 3, -120, -2;
check -16, 3, -128, -2;
check -17, 3, -136, -3;
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment