From: Jarkko Hietaniemi Date: Mon, 1 Oct 2001 17:04:18 +0000 (+0000) Subject: UNICOS testing patches from Nicholas Clark. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=800e6488b45c59f1e13d57d870eed97d36a4ad6e;p=p5sagit%2Fp5-mst-13.2.git UNICOS testing patches from Nicholas Clark. p4raw-id: //depot/perl@12297 --- diff --git a/t/op/arith.t b/t/op/arith.t index 890c78f..6e61477 100755 --- a/t/op/arith.t +++ b/t/op/arith.t @@ -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; @@ -233,7 +245,7 @@ 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 127, 18446744073709551616/1, 18446744073709551616; +tryeq_sloppy 127, 18446744073709551616/1, 18446744073709551616; # Bluuurg tryeq 128, 18446744073709551616/2, 9223372036854775808; tryeq 129, 18446744073709551616/4294967296, 4294967296; tryeq 130, 18446744073709551616/9223372036854775808, 2; diff --git a/t/op/pack.t b/t/op/pack.t index fcc2aba..f944aaf 100755 --- a/t/op/pack.t +++ b/t/op/pack.t @@ -378,9 +378,8 @@ sub numbers_with_total { $max_is_integer = 1 if $max - 1 < ~0; my $calc_sum; - if ($total =~ /^0b[01]*?([01]{1,$len})/) { - no warnings qw(overflow portable); - $calc_sum = oct "0b$1"; + if (ref $total) { + $calc_sum = &$total($len); } else { $calc_sum = $total; # Shift into range by some multiple of the total @@ -446,10 +445,17 @@ numbers ('d', -(2**34), -1, 0, 1, 2**34); numbers_with_total ('q', -1, -9223372036854775808, -1, 0, 1,9223372036854775807); -# This total is icky, but need a way to express 2**65-1 that is going to -# work independant of whether NVs can preserve 65 bits. -# (long double is 128 bits on sparc, so they certianly can) -numbers_with_total ('Q', "0b" . "1" x 65, +# This total is icky, but the true total is 2**65-1, and need a way to generate +# the epxected checksum on any system including those where NVs can preserve +# 65 bits. (long double is 128 bits on sparc, so they certainly can) +# or where rounding is down not up on binary conversion (crays) +numbers_with_total ('Q', sub { + my $len = shift; + $len = 65 if $len > 65; # unmasked total is 2**65-1 here + my $total = 1 + 2 * (int (2**($len - 1)) - 1); + return 0 if $total == $total - 1; # Overflowed integers + return $total; # NVs still accurate to nearest integer + }, 0, 1,9223372036854775807, 9223372036854775808, 18446744073709551615);