summaryrefslogtreecommitdiff
path: root/t/op/int.t
blob: 6d3b5b496ccd49b4aa6bda04d5c2672b2b9b3878 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!./perl

BEGIN {
    chdir 't' if -d 't';
    @INC = '../lib';
    require './test.pl';
}

plan 15;

# compile time evaluation

if (int(1.234) == 1) {pass()} else {fail()}

if (int(-1.234) == -1) {pass()} else {fail()}

# run time evaluation

$x = 1.234;
cmp_ok(int($x), '==', 1);
cmp_ok(int(-$x), '==', -1);

$x = length("abc") % -10;
cmp_ok($x, '==', -7);

{
    my $fail;
    use integer;
    $x = length("abc") % -10;
    $y = (3/-10)*-10;
    ok($x+$y == 3) or ++$fail;
    ok(abs($x) < 10) or ++$fail;
    if ($fail) {
	diag("\$x == $x", "\$y == $y");
    }
}

@x = ( 6, 8, 10);
cmp_ok($x["1foo"], '==', 8, 'check bad strings still get converted');

$x = 4294967303.15;
$y = int ($x);
is($y, "4294967303", 'check values > 32 bits work');

$y = int (-$x);

is($y, "-4294967303");

$x = 4294967294.2;
$y = int ($x);

is($y, "4294967294");

$x = 4294967295.7;
$y = int ($x);

is($y, "4294967295");

$x = 4294967296.11312;
$y = int ($x);

is($y, "4294967296");

$y = int(279964589018079/59);
cmp_ok($y, '==', 4745162525730);

$y = 279964589018079;
$y = int($y/59);
cmp_ok($y, '==', 4745162525730);