more prose fixups to bytes.pm deprecation warning
[p5sagit/p5-mst-13.2.git] / lib / integer.t
CommitLineData
88587957 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
4d0ed6f7 8use integer;
9
a0cec769 10use Test::More tests => 15;
4d0ed6f7 11use Config;
12
13my $x = 4.5;
14my $y = 5.6;
15my $z;
16
17$z = $x + $y;
18is($z, 9, "plus");
19
20$z = $x - $y;
21is($z, -1, "minus");
22
23$z = $x * $y;
24is($z, 20, "times");
25
26$z = $x / $y;
27is($z, 0, "divide");
28
29$z = $x / $y;
30is($z, 0, "modulo");
31
32is($x, 4.5, "scalar still floating point");
33
34isnt(sqrt($x), 2, "functions still floating point");
35
36isnt($x ** .5, 2, "power still floating point");
37
38is(++$x, 5.5, "++ still floating point");
39
40SKIP: {
41 my $ivsize = $Config{ivsize};
42 skip "ivsize == $ivsize", 2 unless $ivsize == 4 || $ivsize == 8;
43
44 if ($ivsize == 4) {
45 $z = 2**31 - 1;
46 is($z + 1, -2147483648, "left shift");
47 } elsif ($ivsize == 8) {
48 $z = 2**63 - 1;
49 is($z + 1, -9223372036854775808, "left shift");
50 }
51}
52
05f18d1e 53is(~0, -1, "signed instead of unsigned");
669ffa90 54
55# [perl #38485] use integer; 0x80000000/-1;
56SKIP: {
57 my $ivsize = $Config{ivsize};
a0cec769 58 skip "ivsize == $ivsize", 4 unless $ivsize == 4 || $ivsize == 8;
669ffa90 59
60 my $iv_min = $ivsize == 4 ? -2147483648 : -9223372036854775808;
61 my $biff;
62 eval { $biff = $iv_min / -1 };
a0cec769 63 is($@, '', 'IV_MIN / -1 succeeds');
64 is($biff, -$iv_min, 'IV_MIN / -1 == -IV_MIN');
65
66 eval { $biff = $iv_min % -1 };
67 is($@, '', 'IV_MIN % -1 succeeds');
68 is($biff, 0, 'IV_MIN % -1 == 0');
669ffa90 69}