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 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;
$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
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);