#!./perl
#
# test the conversion operators
#
# Notations:
#
# "N p i N vs N N": Apply op-N, then op-p, then op-i, then reporter-N
# Compare with application of op-N, then reporter-N
# Right below are descriptions of different ops and reporters.
# We do not use these subroutines any more, sub overhead makes a "switch"
# solution better:
# obviously, 0, 1 and 2, 3 are destructive. (XXXX 64-bit? 4 destructive too)
# *0 = sub {--$_[0]}; # -
# *1 = sub {++$_[0]}; # +
# # Converters
# *2 = sub { $_[0] = $max_uv & $_[0]}; # U
# *3 = sub { use integer; $_[0] += $zero}; # I
# *4 = sub { $_[0] += $zero}; # N
# *5 = sub { $_[0] = "$_[0]" }; # P
# # Side effects
# *6 = sub { $max_uv & $_[0]}; # u
# *7 = sub { use integer; $_[0] + $zero}; # i
# *8 = sub { $_[0] + $zero}; # n
# *9 = sub { $_[0] . "" }; # p
# # Reporters
# sub a2 { sprintf "%u", $_[0] } # U
# sub a3 { sprintf "%d", $_[0] } # I
# sub a4 { sprintf "%g", $_[0] } # N
# sub a5 { "$_[0]" } # P
BEGIN {
chdir 't' if -d 't';
}
use strict 'vars';
# Bulk out if unsigned type is hopelessly wrong:
my $max_uv1 = ~0;
print "# max_uv_less3 = $max_uv_less3\n";
print "1..0 # skipped: unsigned perl arithmetic is not sane";
print " (common in 64-bit platforms)";
}
print "\n";
exit 0;
}
print "1..0 # skipped: this perl stringifies large unsigned integers using E notation\n";
exit 0;
}
my $st_t = 4*4; # We try 4 initializers and 4 reporters
my $num = 0;
$num += 10**$_ - 4**$_ for 1.. $max_chain;
my $max_uv = ~0;
my $zero = 0;
# Hope: the first digits are good
my $larger_than_uv = substr 97 x 100, 0, $l_uv;
my $smaller_than_iv = substr 12 x 100, 0, $l_iv;
my @list = (1, $yet_smaller_than_iv, $smaller_than_iv, $max_iv, $max_iv + 1,
print "# @list\n";
# need to special case ++ for max_uv, as ++ "magic" on a string gives
# another string, whereas ++ magic on a string used as a number gives
# a number. Not a problem when NV preserves UV, but if it doesn't then
# stringification of the latter gives something in e notation.
# Also need to cope with %g notation for max_uv_p1 that actually gives an
# integer less than max_uv because of correct rounding for the limited
# precisision. This bites for 12 byte long doubles and 8 byte UVs
my $temp = $max_uv_p1;
my $max_uv_p1_as_iv;
# @list = map { 2->($_), 3->($_), 4->($_), 5->($_), } @list; # Prepare input
#print "@list\n";
#print "'@ops'\n";
my $test = 1;
my $nok;
#@ops = ([]) unless $num_chain;
#@ops = ([6, 4]);
# print "'@ops'\n";
$nok = 0;
my $inpt;
my @ans;
# undef $inpt; # Forget all we had - some bugs were masked
} else {
}
# Saves 20% of time - not with this logic:
#my $tmp = $inpt;
#my $tmp1 = $num;
#next if $num_chain > 1
# and "$tmp" ne "$tmp1"; # Already the coercion gives problems...
--$inpt; # - 0
++$inpt; # + 1
} else {
}
} else {
}
} else {
}
} else {
}
}
} else {
}
}
print "# '$ans[0]' ne '$ans[1]',\t$num\t=> @opnames[$first,@{$curops[0]},$last] vs @opnames[$first,@{$curops[1]},$last]\n";
# XXX ought to check that "+" was in the list of opnames
# string ++ versus numeric ++. Tolerate this little
# bit of insanity
print "# ok, as string ++ of max_uv is \"$max_uv_pp\", numeric is $max_uv_p1\n"
# Max UV plus 1 is NV. This NV may stringify in E notation.
# And the number of decimal digits shown in E notation will depend
# on the binary digits in the mantissa. And it may be that
# (say) 18446744073709551616 in E notation is truncated to
# (say) 1.8446744073709551e+19 (say) which gets converted back
# as 1.8446744073709551000e+19
# ie 18446744073709551000
# which isn't the integer we first had.
# But each step of conversion is correct. So it's not an error.
# (Only shows up for 64 bit UVs and NVs with 64 bit mantissas,
# and on Crays (64 bit integers, 48 bit mantissas) IIRC)
# as aboce
# First must be in E notation (ie not just digits) and
# second must still be an integer.
# eg 1.84467440737095516e+19
# 1.84467440737095516e+19 for 64 bit mantissa is in the
# integer range, so 1.84467440737095516e+19 + 0 is treated
# as integer addition. [should it be?]
# and 18446744073709551600 + 0 is 18446744073709551600
# Which isn't the string you first thought of.
# I can't remember why there isn't symmetry in this
# exception, ie why only the first ops are tested for 'N'
print "# ok, numerically equal - notation changed due to adding zero\n";
} else {
$nok++,
}
}
}
} else {
}
#print $txt if $nok;
$test++;
}
}
}
}