#!./perl -w
-print "1..109\n";
+print "1..133\n";
sub try ($$) {
print +($_[1] ? "ok" : "not ok"), " $_[0]\n";
print "not ok $_[0] # $_[1] != $_[2]\n";
}
}
+sub tryeq_sloppy ($$$) {
+ if ($_[1] == $_[2]) {
+ print "ok $_[0]\n";
+ } else {
+ my $error = abs ($_[1] - $_[2]) / $_[1];
+ if ($error < 1e-10) {
+ print "ok $_[0] # $_[1] is close to $_[2], \$^O eq $^O\n";
+ } else {
+ print "not ok $_[0] # $_[1] != $_[2]\n";
+ }
+ }
+}
tryeq 1, 13 % 4, 1;
tryeq 2, -13 % 4, 3;
tryeq 107, 46339 * -46341, -0x7ffea80f;
tryeq 108, -46339 * 46341, -0x7ffea80f;
tryeq 109, -46339 * -46341, 0x7ffea80f;
+
+# leading space should be ignored
+
+tryeq 110, 1 + " 1", 2;
+tryeq 111, 3 + " -1", 2;
+tryeq 112, 1.2, " 1.2";
+tryeq 113, -1.2, " -1.2";
+
+# divide
+
+tryeq 114, 28/14, 2;
+tryeq 115, 28/-7, -4;
+tryeq 116, -28/4, -7;
+tryeq 117, -28/-2, 14;
+
+tryeq 118, 0x80000000/1, 0x80000000;
+tryeq 119, 0x80000000/-1, -0x80000000;
+tryeq 120, -0x80000000/1, -0x80000000;
+tryeq 121, -0x80000000/-1, 0x80000000;
+
+# The example for sloppy divide, rigged to avoid the peephole optimiser.
+tryeq 122, "20." / "5.", 4;
+
+tryeq 123, 2.5 / 2, 1.25;
+tryeq 124, 3.5 / -2, -1.75;
+tryeq 125, -4.5 / 2, -2.25;
+tryeq 126, -5.5 / -2, 2.75;
+
+# Bluuurg if your floating point can't accurately cope with powers of 2
+# [I suspect this is parsing string->float problems, not actual arith]
+tryeq_sloppy 127, 18446744073709551616/1, 18446744073709551616; # Bluuurg
+tryeq 128, 18446744073709551616/2, 9223372036854775808;
+tryeq 129, 18446744073709551616/4294967296, 4294967296;
+tryeq 130, 18446744073709551616/9223372036854775808, 2;
+
+{
+ # 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;
+
+ my $float = ($n % 1000) * 167772160.0;
+ tryeq 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 $int = ($n % 1000) * 167772160;
+ tryeq 132, $int, 21307064320;
+
+ my $t = time;
+ my $t1000 = time() * 1000;
+ try 133, abs($t1000 -1000 * $t) <= 2000;
+}