diff options
author | Chip Salzenberg <chip@atlantic.net> | 1996-11-24 02:01:27 +1200 |
---|---|---|
committer | Chip Salzenberg <chip@atlantic.net> | 1996-11-26 20:48:00 +1200 |
commit | d1f8c7a45dc381aadd1554d536a49dff9ab0c3d5 (patch) | |
tree | 93bce952338db0ec9cf8f59f217b9c7ca8fd967b /t/op/bop.t | |
parent | 6158a1acbe5b192950193bb2d789928975cfd9e6 (diff) | |
download | perl-d1f8c7a45dc381aadd1554d536a49dff9ab0c3d5.tar.gz |
Fix bitwise op test; clean up a couple of others
Diffstat (limited to 't/op/bop.t')
-rwxr-xr-x | t/op/bop.t | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/t/op/bop.t b/t/op/bop.t index 7cf200ff25..0c55029b93 100755 --- a/t/op/bop.t +++ b/t/op/bop.t @@ -4,6 +4,11 @@ # test the bit operators '&', '|', '^', '~', '<<', and '>>' # +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + print "1..18\n"; # numerics @@ -19,16 +24,22 @@ print ((33023 >> 7) == 257 ? "ok 6\n" : "not ok 6\n"); # signed vs. unsigned print ((~0 > 0 && do { use integer; ~0 } == -1) ? "ok 7\n" : "not ok 7\n"); -print (((2147483648 & -1) > 0 && do { use integer; 2147483648 & -1 } < 0) + +my $bits = 0; +for (my $i = ~0; $i; $i >>= 1) { ++$bits; } +my $cusp = 1 << ($bits - 1); + +print ((($cusp & -1) > 0 && do { use integer; $cusp & -1 } < 0) ? "ok 8\n" : "not ok 8\n"); -print (((2147483648 | 1) > 0 && do { use integer; 2147483648 | 1 } < 0) +print ((($cusp | 1) > 0 && do { use integer; $cusp | 1 } < 0) ? "ok 9\n" : "not ok 9\n"); -print (((2147483648 ^ 1) > 0 && do { use integer; 2147483648 ^ 1 } < 0) +print ((($cusp ^ 1) > 0 && do { use integer; $cusp ^ 1 } < 0) ? "ok 10\n" : "not ok 10\n"); -print (((1 << 31) == 2147483648 && do { use integer; 1 << 31 } == -2147483648) +print (((1 << ($bits - 1)) == $cusp && + do { use integer; 1 << ($bits - 1) } == -$cusp) ? "ok 11\n" : "not ok 11\n"); -print (((2147483648 >> 1) == 1073741824 && - do { use integer; 2147483648 >> 1 } == -1073741824) +print ((($cusp >> 1) == ($cusp / 2) && + do { use integer; $cusp >> 1 } == -($cusp / 2)) ? "ok 12\n" : "not ok 12\n"); # short strings |