Commit | Line | Data |
8d063cd8 |
1 | #!./perl |
2 | |
04c29d09 |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
20822f61 |
5 | @INC = '../lib'; |
04c29d09 |
6 | } |
7 | |
853d5ea7 |
8 | print "1..14\n"; |
8d063cd8 |
9 | |
10 | # compile time evaluation |
11 | |
12 | if (int(1.234) == 1) {print "ok 1\n";} else {print "not ok 1\n";} |
13 | |
14 | if (int(-1.234) == -1) {print "ok 2\n";} else {print "not ok 2\n";} |
15 | |
16 | # run time evaluation |
17 | |
18 | $x = 1.234; |
19 | if (int($x) == 1) {print "ok 3\n";} else {print "not ok 3\n";} |
20 | if (int(-$x) == -1) {print "ok 4\n";} else {print "not ok 4\n";} |
4bb9f687 |
21 | |
22 | $x = length("abc") % -10; |
23 | print $x == -7 ? "ok 5\n" : "# expected -7, got $x\nnot ok 5\n"; |
24 | |
25 | { |
26 | use integer; |
27 | $x = length("abc") % -10; |
ddc90e86 |
28 | $y = (3/-10)*-10; |
29 | print $x+$y == 3 && abs($x) < 10 ? "ok 6\n" : "not ok 6\n"; |
4bb9f687 |
30 | } |
0a3ece55 |
31 | |
32 | # check bad strings still get converted |
33 | |
34 | @x = ( 6, 8, 10); |
35 | print "not " if $x["1foo"] != 8; |
36 | print "ok 7\n"; |
853d5ea7 |
37 | |
38 | # check values > 32 bits work. |
39 | |
40 | $x = 4294967303.15; |
41 | $y = int ($x); |
42 | |
43 | if ($y eq "4294967303") { |
44 | print "ok 8\n" |
45 | } else { |
46 | print "not ok 8 # int($x) is $y, not 4294967303\n" |
47 | } |
48 | |
49 | $y = int (-$x); |
50 | |
51 | if ($y eq "-4294967303") { |
52 | print "ok 9\n" |
53 | } else { |
54 | print "not ok 9 # int($x) is $y, not -4294967303\n" |
55 | } |
56 | |
57 | $x = 4294967294.2; |
58 | $y = int ($x); |
59 | |
60 | if ($y eq "4294967294") { |
61 | print "ok 10\n" |
62 | } else { |
63 | print "not ok 10 # int($x) is $y, not 4294967294\n" |
64 | } |
65 | |
66 | $x = 4294967295.7; |
67 | $y = int ($x); |
68 | |
69 | if ($y eq "4294967295") { |
70 | print "ok 11\n" |
71 | } else { |
72 | print "not ok 11 # int($x) is $y, not 4294967295\n" |
73 | } |
74 | |
75 | $x = 4294967296.11312; |
76 | $y = int ($x); |
77 | |
78 | if ($y eq "4294967296") { |
79 | print "ok 12\n" |
80 | } else { |
81 | print "not ok 12 # int($x) is $y, not 4294967296\n" |
82 | } |
83 | |
84 | $y = int(279964589018079/59); |
85 | if ($y == 4745162525730) { |
86 | print "ok 13\n" |
87 | } else { |
88 | print "not ok 13 # int(279964589018079/59) is $y, not 4745162525730\n" |
89 | } |
90 | |
91 | $y = 279964589018079; |
92 | $y = int($y/59); |
93 | if ($y == 4745162525730) { |
94 | print "ok 14\n" |
95 | } else { |
96 | print "not ok 14 # int(279964589018079/59) is $y, not 4745162525730\n" |
97 | } |
98 | |