xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/integer.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateBEGIN {
4*0Sstevel@tonic-gate    chdir 't' if -d 't';
5*0Sstevel@tonic-gate    @INC = '../lib';
6*0Sstevel@tonic-gate}
7*0Sstevel@tonic-gate
8*0Sstevel@tonic-gateuse integer;
9*0Sstevel@tonic-gate
10*0Sstevel@tonic-gateuse Test::More tests => 11;
11*0Sstevel@tonic-gateuse Config;
12*0Sstevel@tonic-gate
13*0Sstevel@tonic-gatemy $x = 4.5;
14*0Sstevel@tonic-gatemy $y = 5.6;
15*0Sstevel@tonic-gatemy $z;
16*0Sstevel@tonic-gate
17*0Sstevel@tonic-gate$z = $x + $y;
18*0Sstevel@tonic-gateis($z, 9, "plus");
19*0Sstevel@tonic-gate
20*0Sstevel@tonic-gate$z = $x - $y;
21*0Sstevel@tonic-gateis($z, -1, "minus");
22*0Sstevel@tonic-gate
23*0Sstevel@tonic-gate$z = $x * $y;
24*0Sstevel@tonic-gateis($z, 20, "times");
25*0Sstevel@tonic-gate
26*0Sstevel@tonic-gate$z = $x / $y;
27*0Sstevel@tonic-gateis($z, 0, "divide");
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate$z = $x / $y;
30*0Sstevel@tonic-gateis($z, 0, "modulo");
31*0Sstevel@tonic-gate
32*0Sstevel@tonic-gateis($x, 4.5, "scalar still floating point");
33*0Sstevel@tonic-gate
34*0Sstevel@tonic-gateisnt(sqrt($x), 2, "functions still floating point");
35*0Sstevel@tonic-gate
36*0Sstevel@tonic-gateisnt($x ** .5, 2, "power still floating point");
37*0Sstevel@tonic-gate
38*0Sstevel@tonic-gateis(++$x, 5.5, "++ still floating point");
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gateSKIP: {
41*0Sstevel@tonic-gate    my $ivsize = $Config{ivsize};
42*0Sstevel@tonic-gate    skip "ivsize == $ivsize", 2 unless $ivsize == 4 || $ivsize == 8;
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate    if ($ivsize == 4) {
45*0Sstevel@tonic-gate	$z = 2**31 - 1;
46*0Sstevel@tonic-gate	is($z + 1, -2147483648, "left shift");
47*0Sstevel@tonic-gate    } elsif ($ivsize == 8) {
48*0Sstevel@tonic-gate	$z = 2**63 - 1;
49*0Sstevel@tonic-gate	is($z + 1, -9223372036854775808, "left shift");
50*0Sstevel@tonic-gate    }
51*0Sstevel@tonic-gate}
52*0Sstevel@tonic-gate
53*0Sstevel@tonic-gateis(~0, -1, "signed instead of unsigned");
54