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