Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Check numeric shifts for two's complement semantics.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| use v6; | ||
| use Test; | ||
|
|
||
| plan 36; | ||
|
|
||
| sub check ($a, $b, $ls, $rs) { | ||
| is $a * 2**$b, $ls, "expected value for shl $a by $b is sane"; | ||
|
|
||
| # assume two's complement semantics for negative $a | ||
| is floor($a / 2**$b), $rs, "expected value for shr $a by $b is sane"; | ||
|
|
||
| is $a +< $b, $ls, "got expected value for shl $a by $b"; | ||
|
|
||
| #?niecza skip 'shift by negative bit count' | ||
| is $a +< -$b, $rs, "got expected value for shl $a by -$b"; | ||
|
|
||
| is $a +> $b, $rs, "got expected value for shr $a by $b"; | ||
|
|
||
| #?niecza skip 'shift by negative bit count' | ||
| is $a +> -$b, $ls, "got expected value for 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; |