summaryrefslogtreecommitdiff
path: root/t/op/infnan.t
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2014-09-18 21:10:41 -0400
committerJarkko Hietaniemi <jhi@iki.fi>2014-09-18 22:10:09 -0400
commit5d288d736c2758c27a5943647f4a524f0e93a642 (patch)
tree7e54c5b720cd821d6bbbc7352ae1277c954d7d84 /t/op/infnan.t
parentdbc3192fe0c49a38126b4e4572de22c8ffff3a3f (diff)
downloadperl-5d288d736c2758c27a5943647f4a524f0e93a642.tar.gz
infnan: more tests.
++, math, compare.
Diffstat (limited to 't/op/infnan.t')
-rw-r--r--t/op/infnan.t69
1 files changed, 65 insertions, 4 deletions
diff --git a/t/op/infnan.t b/t/op/infnan.t
index b448c2c105..101fc24a1e 100644
--- a/t/op/infnan.t
+++ b/t/op/infnan.t
@@ -34,12 +34,16 @@ my @NaN = ("NAN", "nan", "qnan", "SNAN", "NanQ", "NANS",
my @num_fmt = qw(e f g a d u o b x p);
-my $inf_tests = 13 + @num_fmt + 8 + 3 * @PInf + 3 * @NInf + 5 + 3;
-my $nan_tests = 8 + @num_fmt + 4 + 2 * @NaN + 3;
+my $inf_tests = 13 + @num_fmt + 8 + 3 * @PInf + 3 * @NInf + 14 + 3;
+my $nan_tests = 8 + @num_fmt + 4 + 2 * @NaN + 14;
-my $infnan_tests = 4;
+my $infnan_tests = 13;
-plan tests => $inf_tests + $nan_tests + $infnan_tests;
+plan tests => $inf_tests + 1 + $nan_tests + 1 + $infnan_tests + 1;
+
+print "# inf_tests = $inf_tests\n";
+print "# nan_tests = $nan_tests\n";
+print "# infnan_tests = $infnan_tests\n";
my $has_inf;
my $has_nan;
@@ -108,6 +112,24 @@ SKIP: {
is(1/$PInf, 0, "one per +Inf is zero");
is(1/$NInf, 0, "one per -Inf is zero");
+ my ($PInfPP, $PInfMM) = ($PInf, $PInf);
+ my ($NInfPP, $NInfMM) = ($NInf, $NInf);;
+ $PInfPP++;
+ $PInfMM--;
+ $NInfPP++;
+ $NInfMM--;
+ is($PInfPP, $PInf, "+inf++ is +inf");
+ is($PInfMM, $PInf, "+inf-- is +inf");
+ is($NInfPP, $NInf, "-inf++ is -inf");
+ is($NInfMM, $NInf, "-inf-- is -inf");
+
+ ok($PInf, "+inf is true");
+ ok($NInf, "-inf is true");
+
+ is(sqrt($PInf), $PInf, "sqrt(+inf) is +inf");
+ is(exp($PInf), $PInf, "exp(+inf) is +inf");
+ is(exp($NInf), 0, "exp(-inf) is zero");
+
SKIP: {
my $here = "$^O $Config{osvers}";
if ($here =~ /^hpux 10/) {
@@ -125,6 +147,8 @@ SKIP: {
}
}
+is(curr_test() - 1, $inf_tests, "expected number of inf tests");
+
SKIP: {
if ($NaN == 0) {
skip $nan_tests, "no nan found";
@@ -164,10 +188,29 @@ SKIP: {
is("@{[$i+0]}", "NaN", "$i value stringifies as NaN");
}
+ ok(!($NaN < 0), "NaN is not lt zero");
+ ok(!($NaN == 0), "NaN is not == zero");
+ ok(!($NaN > 0), "NaN is not gt zero");
+
+ ok(!($NaN < $NaN), "NaN is not lt NaN");
+ ok(!($NaN > $NaN), "NaN is not gt NaN");
+
# is() okay with $NaN because it uses eq.
is($NaN * 0, $NaN, "NaN times zero is NaN");
is($NaN * 2, $NaN, "NaN times two is NaN");
+ my ($NaNPP, $NaNMM) = ($NaN, $NaN);
+ $NaNPP++;
+ $NaNMM--;
+ is($NaNPP, $NaN, "+inf++ is +inf");
+ is($NaNMM, $NaN, "+inf-- is +inf");
+
+ ok($NaN, "NaN is true");
+
+ is(sqrt($NaN), $NaN, "sqrt(nan) is nan");
+ is(exp($NaN), $NaN, "exp(nan) is nan");
+ is(sin($NaN), $NaN, "sin(nan) is nan");
+
SKIP: {
my $here = "$^O $Config{osvers}";
if ($here =~ /^hpux 10/) {
@@ -177,6 +220,9 @@ SKIP: {
}
}
+is(curr_test() - 1, $inf_tests + 1 + $nan_tests,
+ "expected number of nan tests");
+
SKIP: {
unless ($has_inf && $has_nan) {
skip $infnan_tests, "no both Inf and Nan";
@@ -187,4 +233,19 @@ SKIP: {
is($PInf * $NaN, $NaN, "Inf times NaN is NaN");
is($PInf + $NaN, $NaN, "Inf plus NaN is NaN");
is($PInf - $PInf, $NaN, "Inf minus inf is NaN");
+ is($PInf / $PInf, $NaN, "Inf div inf is NaN");
+ is($PInf % $PInf, $NaN, "Inf mod inf is NaN");
+
+ ok(!($NaN < $PInf), "NaN is not lt +inf");
+ ok(!($NaN == $PInf), "NaN is not eq +inf");
+ ok(!($NaN > $PInf), "NaN is not gt +inf");
+
+ ok(!($NaN > $NInf), "NaN is not lt -inf");
+ ok(!($NaN == $NInf), "NaN is not eq -inf");
+ ok(!($NaN < $NInf), "NaN is not gt -inf");
+
+ is(sin($PInf), $NaN, "sin(+inf) is nan");
}
+
+is(curr_test() - 1, $inf_tests + 1 + $nan_tests + 1 + $infnan_tests,
+ "expected number of nan tests");