arith.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl -w
BEGIN {
chdir 't' if -d 't';
}
use Config;
print "1..134\n";
print +($_[1] ? "ok" : "not ok"), " $_[0]\n";
}
if ($_[1] == $_[2]) {
print "ok $_[0]\n";
} else {
print "not ok $_[0] # $_[1] != $_[2]\n";
}
}
if ($_[1] == $_[2]) {
print "ok $_[0]\n";
} else {
print "ok $_[0] # $_[1] is close to $_[2], \$^O eq $^O\n";
} else {
print "not ok $_[0] # $_[1] != $_[2]\n";
}
}
}
# Division (and modulo) of floating point numbers
# seem to be rather sloppy in Cray.
# UVs should behave properly
# These should trigger wrapping on 32 bit IVs and UVs
# IV + IV promote to UV
# IV + UV promote to NV
# UV + IV promote to NV
# UV + UV promote to NV
# UV + IV to IV
# IV + UV to IV
# IV + IV to NV
# Hmm. Don't forget the simple stuff
# subtraction
# IV - IV promote to UV
# UV - IV promote to NV
# IV - IV promote to NV
# UV - UV promote to IV
# IV - UV promote to IV
# No warnings should appear;
my $a;
$a += 1;
undef $a;
$a += -1;
undef $a;
$a += 4294967290;
undef $a;
$a += -4294967290;
undef $a;
$a += 4294967297;
undef $a;
$a += -4294967297;
my $s;
$s -= 1;
undef $s;
$s -= -1;
undef $s;
$s -= -4294967290;
undef $s;
$s -= 4294967290;
undef $s;
$s -= 4294967297;
undef $s;
$s -= -4294967297;
# Multiplication
# check with 0xFFFF and 0xFFFF
# check with 0xFFFF and 0x10001
# check with 0x10001 and 0xFFFF
# These should all be dones as NVs
# will overflow an IV (in 32-bit)
# will overflow a positive IV (in 32-bit)
# 2147483647 is prime. bah.
# leading space should be ignored
# divide
# The example for sloppy divide, rigged to avoid the peephole optimiser.
# Bluuurg if your floating point can't accurately cope with powers of 2
# [I suspect this is parsing string->float problems, not actual arith]
{
# The peephole optimiser is wrong to think that it can substitute intops
# in place of regular ops, because i_multiply can overflow.
# Bug reported by "Sisyphus" <kalinabears@hdc.com.au>
my $n = 1127;
tryeq_sloppy 131, $float, 21307064320;
# On a 32 bit machine, if the i_multiply op is used, you will probably get
# -167772160. It's actually undefined behaviour, so anything may happen.
my $t = time;
}
print "not ok 134 # TODO VOS raises SIGFPE instead of producing infinity.\n";
}
print "ok 134 # SKIP -- the IEEE infinity model is unavailable in this configuration.\n";
}
print "not ok 134 # TODO Ultrix enters deep nirvana instead of producing infinity.\n";
}
else {
# The computation of $v should overflow and produce "infinity"
# on any system whose max exponent is less than 10**1506.
# The exact string used to represent infinity varies by OS,
# so we don't test for it; all we care is that we don't die.
#
# Perl considers it to be an error if SIGFPE is raised.
# Chances are the interpreter will die, since it doesn't set
# up a handler for SIGFPE. That's why this test is last; to
# minimize the number of test failures. --PG
my $n = 5000;
my $v = 2;
while (--$n)
{
$v *= 2;
}
print "ok 134\n";
}