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
CommitLineData
8d063cd8
LW
1#!./perl
2
04c29d09
GS
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
44885db3 6 require './test.pl';
04c29d09
GS
7}
8
44885db3 9plan 15;
8d063cd8
LW
10
11# compile time evaluation
12
44885db3 13if (int(1.234) == 1) {pass()} else {fail()}
8d063cd8 14
44885db3 15if (int(-1.234) == -1) {pass()} else {fail()}
8d063cd8
LW
16
17# run time evaluation
18
19$x = 1.234;
44885db3
NC
20cmp_ok(int($x), '==', 1);
21cmp_ok(int(-$x), '==', -1);
4bb9f687
GS
22
23$x = length("abc") % -10;
44885db3 24cmp_ok($x, '==', -7);
4bb9f687
GS
25
26{
44885db3 27 my $fail;
4bb9f687
GS
28 use integer;
29 $x = length("abc") % -10;
ddc90e86 30 $y = (3/-10)*-10;
44885db3
NC
31 ok($x+$y == 3) or ++$fail;
32 ok(abs($x) < 10) or ++$fail;
33 if ($fail) {
34 diag("\$x == $x", "\$y == $y");
35 }
4bb9f687 36}
0a3ece55 37
0a3ece55 38@x = ( 6, 8, 10);
44885db3 39cmp_ok($x["1foo"], '==', 8, 'check bad strings still get converted');
853d5ea7
NC
40
41$x = 4294967303.15;
42$y = int ($x);
44885db3 43is($y, "4294967303", 'check values > 32 bits work');
853d5ea7
NC
44
45$y = int (-$x);
46
44885db3 47is($y, "-4294967303");
853d5ea7
NC
48
49$x = 4294967294.2;
50$y = int ($x);
51
44885db3 52is($y, "4294967294");
853d5ea7
NC
53
54$x = 4294967295.7;
55$y = int ($x);
56
44885db3 57is($y, "4294967295");
853d5ea7
NC
58
59$x = 4294967296.11312;
60$y = int ($x);
61
44885db3 62is($y, "4294967296");
853d5ea7
NC
63
64$y = int(279964589018079/59);
44885db3 65cmp_ok($y, '==', 4745162525730);
853d5ea7
NC
66
67$y = 279964589018079;
68$y = int($y/59);
44885db3 69cmp_ok($y, '==', 4745162525730);