This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
svleak.t: Enable syntax error tests under -Dmad
[perl5.git] / t / op / int.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require './test.pl';
7 }
8
9 plan 15;
10
11 # compile time evaluation
12
13 if (int(1.234) == 1) {pass()} else {fail()}
14
15 if (int(-1.234) == -1) {pass()} else {fail()}
16
17 # run time evaluation
18
19 $x = 1.234;
20 cmp_ok(int($x), '==', 1);
21 cmp_ok(int(-$x), '==', -1);
22
23 $x = length("abc") % -10;
24 cmp_ok($x, '==', -7);
25
26 {
27     my $fail;
28     use integer;
29     $x = length("abc") % -10;
30     $y = (3/-10)*-10;
31     ok($x+$y == 3) or ++$fail;
32     ok(abs($x) < 10) or ++$fail;
33     if ($fail) {
34         diag("\$x == $x", "\$y == $y");
35     }
36 }
37
38 @x = ( 6, 8, 10);
39 cmp_ok($x["1foo"], '==', 8, 'check bad strings still get converted');
40
41 $x = 4294967303.15;
42 $y = int ($x);
43 is($y, "4294967303", 'check values > 32 bits work');
44
45 $y = int (-$x);
46
47 is($y, "-4294967303");
48
49 $x = 4294967294.2;
50 $y = int ($x);
51
52 is($y, "4294967294");
53
54 $x = 4294967295.7;
55 $y = int ($x);
56
57 is($y, "4294967295");
58
59 $x = 4294967296.11312;
60 $y = int ($x);
61
62 is($y, "4294967296");
63
64 $y = int(279964589018079/59);
65 cmp_ok($y, '==', 4745162525730);
66
67 $y = 279964589018079;
68 $y = int($y/59);
69 cmp_ok($y, '==', 4745162525730);