1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/Aprint "1..14\n";
1N/A
1N/A# compile time evaluation
1N/A
1N/Aif (int(1.234) == 1) {print "ok 1\n";} else {print "not ok 1\n";}
1N/A
1N/Aif (int(-1.234) == -1) {print "ok 2\n";} else {print "not ok 2\n";}
1N/A
1N/A# run time evaluation
1N/A
1N/A$x = 1.234;
1N/Aif (int($x) == 1) {print "ok 3\n";} else {print "not ok 3\n";}
1N/Aif (int(-$x) == -1) {print "ok 4\n";} else {print "not ok 4\n";}
1N/A
1N/A$x = length("abc") % -10;
1N/Aprint $x == -7 ? "ok 5\n" : "# expected -7, got $x\nnot ok 5\n";
1N/A
1N/A{
1N/A use integer;
1N/A $x = length("abc") % -10;
1N/A $y = (3/-10)*-10;
1N/A print $x+$y == 3 && abs($x) < 10 ? "ok 6\n" : "not ok 6\n";
1N/A}
1N/A
1N/A# check bad strings still get converted
1N/A
1N/A@x = ( 6, 8, 10);
1N/Aprint "not " if $x["1foo"] != 8;
1N/Aprint "ok 7\n";
1N/A
1N/A# check values > 32 bits work.
1N/A
1N/A$x = 4294967303.15;
1N/A$y = int ($x);
1N/A
1N/Aif ($y eq "4294967303") {
1N/A print "ok 8\n"
1N/A} else {
1N/A print "not ok 8 # int($x) is $y, not 4294967303\n"
1N/A}
1N/A
1N/A$y = int (-$x);
1N/A
1N/Aif ($y eq "-4294967303") {
1N/A print "ok 9\n"
1N/A} else {
1N/A print "not ok 9 # int($x) is $y, not -4294967303\n"
1N/A}
1N/A
1N/A$x = 4294967294.2;
1N/A$y = int ($x);
1N/A
1N/Aif ($y eq "4294967294") {
1N/A print "ok 10\n"
1N/A} else {
1N/A print "not ok 10 # int($x) is $y, not 4294967294\n"
1N/A}
1N/A
1N/A$x = 4294967295.7;
1N/A$y = int ($x);
1N/A
1N/Aif ($y eq "4294967295") {
1N/A print "ok 11\n"
1N/A} else {
1N/A print "not ok 11 # int($x) is $y, not 4294967295\n"
1N/A}
1N/A
1N/A$x = 4294967296.11312;
1N/A$y = int ($x);
1N/A
1N/Aif ($y eq "4294967296") {
1N/A print "ok 12\n"
1N/A} else {
1N/A print "not ok 12 # int($x) is $y, not 4294967296\n"
1N/A}
1N/A
1N/A$y = int(279964589018079/59);
1N/Aif ($y == 4745162525730) {
1N/A print "ok 13\n"
1N/A} else {
1N/A print "not ok 13 # int(279964589018079/59) is $y, not 4745162525730\n"
1N/A}
1N/A
1N/A$y = 279964589018079;
1N/A$y = int($y/59);
1N/Aif ($y == 4745162525730) {
1N/A print "ok 14\n"
1N/A} else {
1N/A print "not ok 14 # int(279964589018079/59) is $y, not 4745162525730\n"
1N/A}
1N/A