X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fop%2Farith.t;h=6e61477baf40d88d0523f001981d2e650230d08b;hb=0bc0ad857ef0ded50c72fba42503c958a1579a5a;hp=8b8e2bce2bc205dbc43307002c9809f146f90c57;hpb=96a05aee450e24b2d5686c50a7e95ce03114af79;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/op/arith.t b/t/op/arith.t index 8b8e2bc..6e61477 100755 --- a/t/op/arith.t +++ b/t/op/arith.t @@ -1,6 +1,6 @@ #!./perl -w -print "1..113\n"; +print "1..130\n"; sub try ($$) { print +($_[1] ? "ok" : "not ok"), " $_[0]\n"; @@ -12,6 +12,18 @@ sub tryeq ($$$) { 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; @@ -211,3 +223,29 @@ 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 +tryeq_sloppy 127, 18446744073709551616/1, 18446744073709551616; # Bluuurg +tryeq 128, 18446744073709551616/2, 9223372036854775808; +tryeq 129, 18446744073709551616/4294967296, 4294967296; +tryeq 130, 18446744073709551616/9223372036854775808, 2;