Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src IEEE corner case tests for the pow(3) family (incl. PR lib/4...



details:   https://anonhg.NetBSD.org/src/rev/d3dec64bc5bf
branches:  trunk
changeset: 769657:d3dec64bc5bf
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sat Sep 17 08:15:43 2011 +0000

description:
IEEE corner case tests for the pow(3) family (incl. PR lib/45372).

diffstat:

 distrib/sets/lists/tests/mi |    4 +-
 tests/lib/libm/Makefile     |    3 +-
 tests/lib/libm/t_pow.c      |  677 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 682 insertions(+), 2 deletions(-)

diffs (truncated from 723 to 300 lines):

diff -r 469aa0bb2006 -r d3dec64bc5bf distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Sep 17 06:21:19 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Sep 17 08:15:43 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.385 2011/09/14 05:18:18 jruoho Exp $
+# $NetBSD: mi,v 1.386 2011/09/17 08:15:43 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -553,6 +553,7 @@
 ./usr/libdata/debug/usr/tests/lib/libm/t_ldexp.debug                   tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libm/t_log.debug                     tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libm/t_libm.debug                    tests-obsolete          obsolete
+./usr/libdata/debug/usr/tests/lib/libm/t_pow.debug                     tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libm/t_round.debug                   tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libm/t_scalbn.debug                  tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libm/t_sin.debug                     tests-lib-debug         debug,atf
@@ -2262,6 +2263,7 @@
 ./usr/tests/lib/libm/t_ldexp                   tests-lib-tests         atf
 ./usr/tests/lib/libm/t_log                     tests-lib-tests         atf
 ./usr/tests/lib/libm/t_libm                    tests-obsolete          obsolete
+./usr/tests/lib/libm/t_pow                     tests-lib-tests         atf
 ./usr/tests/lib/libm/t_round                   tests-lib-tests         atf
 ./usr/tests/lib/libm/t_scalbn                  tests-lib-tests         atf
 ./usr/tests/lib/libm/t_sin                     tests-lib-tests         atf
diff -r 469aa0bb2006 -r d3dec64bc5bf tests/lib/libm/Makefile
--- a/tests/lib/libm/Makefile   Sat Sep 17 06:21:19 2011 +0000
+++ b/tests/lib/libm/Makefile   Sat Sep 17 08:15:43 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.9 2011/09/14 05:18:19 jruoho Exp $
+# $NetBSD: Makefile,v 1.10 2011/09/17 08:15:43 jruoho Exp $
 
 .include <bsd.own.mk>
 
@@ -9,6 +9,7 @@
 TESTS_C+=      t_infinity
 TESTS_C+=      t_ldexp
 TESTS_C+=      t_log
+TESTS_C+=      t_pow
 TESTS_C+=      t_round
 TESTS_C+=      t_scalbn
 TESTS_C+=      t_sin
diff -r 469aa0bb2006 -r d3dec64bc5bf tests/lib/libm/t_pow.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libm/t_pow.c    Sat Sep 17 08:15:43 2011 +0000
@@ -0,0 +1,677 @@
+/* $NetBSD: t_pow.c,v 1.1 2011/09/17 08:15:43 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jukka Ruohonen.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_pow.c,v 1.1 2011/09/17 08:15:43 jruoho Exp $");
+
+#include <atf-c.h>
+#include <math.h>
+
+/*
+ * pow(3)
+ */
+ATF_TC(pow_nan_x);
+ATF_TC_HEAD(pow_nan_x, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test pow(NaN, y) == NaN");
+}
+
+ATF_TC_BODY(pow_nan_x, tc)
+{
+#ifndef __vax__
+       const double x = 0.0L / 0.0L;
+
+       ATF_CHECK(isnan(pow(x, 2.0)) != 0);
+#endif
+}
+
+ATF_TC(pow_nan_y);
+ATF_TC_HEAD(pow_nan_y, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test pow(x, NaN) == NaN");
+}
+
+ATF_TC_BODY(pow_nan_y, tc)
+{
+#ifndef __vax__
+       const double y = 0.0L / 0.0L;
+
+       ATF_CHECK(isnan(pow(2.0, y)) != 0);
+#endif
+}
+
+ATF_TC(pow_inf_neg_x);
+ATF_TC_HEAD(pow_inf_neg_x, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test pow(-Inf, y) == +-Inf || +-0.0");
+}
+
+ATF_TC_BODY(pow_inf_neg_x, tc)
+{
+#ifndef __vax__
+       const double x = -1.0L / 0.0L;
+       double z;
+
+       /*
+        * If y is odd, y > 0, and x is -Inf, -Inf is returned.
+        * If y is even, y > 0, and x is -Inf, +Inf is returned.
+        */
+       z = pow(x, 3.0);
+
+       if (isinf(z) == 0 || signbit(z) == 0)
+               atf_tc_fail_nonfatal("pow(-Inf, 3.0) != -Inf");
+
+       z = pow(x, 4.0);
+
+       if (isinf(z) == 0 || signbit(z) != 0)
+               atf_tc_fail_nonfatal("pow(-Inf, 4.0) != +Inf");
+
+       /*
+        * If y is odd, y < 0, and x is -Inf, -0.0 is returned.
+        * If y is even, y < 0, and x is -Inf, +0.0 is returned.
+        */
+       z = pow(x, -3.0);
+
+       if (fabs(z) > 0.0 || signbit(z) == 0)
+               atf_tc_fail_nonfatal("pow(-Inf, -3.0) != -0.0");
+
+       z = pow(x, -4.0);
+
+       if (fabs(z) > 0.0 || signbit(z) != 0)
+               atf_tc_fail_nonfatal("pow(-Inf -4.0) != +0.0");
+#endif
+}
+
+ATF_TC(pow_inf_neg_y);
+ATF_TC_HEAD(pow_inf_neg_y, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test pow(x, -Inf) == +Inf || +0.0");
+}
+
+ATF_TC_BODY(pow_inf_neg_y, tc)
+{
+#ifndef __vax__
+       const double y = -1.0L / 0.0L;
+       double z;
+
+       /*
+        * If |x| < 1 and y is -Inf, +Inf is returned.
+        * If |x| > 1 and y is -Inf, +0.0 is returned.
+        */
+       z = pow(0.1, y);
+
+       if (isinf(z) == 0 || signbit(z) != 0)
+               atf_tc_fail_nonfatal("pow(0.1, -Inf) != +Inf");
+
+       z = pow(1.1, y);
+
+       if (fabs(z) > 0.0 || signbit(z) != 0)
+               atf_tc_fail_nonfatal("pow(1.1, -Inf) != +0.0");
+#endif
+}
+
+ATF_TC(pow_inf_pos_x);
+ATF_TC_HEAD(pow_inf_pos_x, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test pow(+Inf, y) == +Inf || +0.0");
+}
+
+ATF_TC_BODY(pow_inf_pos_x, tc)
+{
+#ifndef __vax__
+       const double x = 1.0L / 0.0L;
+       double z;
+
+       /*
+        * For y < 0, if x is +Inf, +0.0 is returned.
+        * For y > 0, if x is +Inf, +Inf is returned.
+        */
+       z = pow(x, -2.0);
+
+       if (fabs(z) > 0.0 || signbit(z) != 0)
+               atf_tc_fail_nonfatal("pow(+Inf, -2.0) != +0.0");
+
+       z = pow(x, 2.0);
+
+       if (isinf(z) == 0 || signbit(z) != 0)
+               atf_tc_fail_nonfatal("pow(+Inf, 2.0) != +Inf");
+#endif
+}
+
+ATF_TC(pow_inf_pos_y);
+ATF_TC_HEAD(pow_inf_pos_y, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test pow(x, +Inf) == +Inf || +0.0");
+}
+
+ATF_TC_BODY(pow_inf_pos_y, tc)
+{
+#ifndef __vax__
+       const double y = 1.0L / 0.0L;
+       double z;
+
+       /*
+        * If |x| < 1 and y is +Inf, +0.0 is returned.
+        * If |x| > 1 and y is +Inf, +Inf is returned.
+        */
+       z = pow(0.1, y);
+
+       if (fabs(z) > 0.0 || signbit(z) != 0)
+               atf_tc_fail_nonfatal("pow(0.1, +Inf) != +0.0");
+
+       z = pow(1.1, y);
+
+       if (isinf(z) == 0 || signbit(z) != 0)
+               atf_tc_fail_nonfatal("pow(1.1, +Inf) != +Inf");
+#endif
+}
+
+ATF_TC(pow_one_neg_x);
+ATF_TC_HEAD(pow_one_neg_x, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test pow(-1.0, +-Inf) == 1.0");
+}
+
+ATF_TC_BODY(pow_one_neg_x, tc)
+{
+#ifndef __vax__
+       const double infp = 1.0L / 0.0L;
+       const double infn = -1.0L / 0.0L;
+
+       /*
+        * If x is -1.0, and y is +-Inf, 1.0 shall be returned.
+        */
+       ATF_REQUIRE(isinf(infp) != 0);
+       ATF_REQUIRE(isinf(infn) != 0);
+
+       if (pow(-1.0, infp) != 1.0) {
+               atf_tc_expect_fail("PR lib/45372");
+               atf_tc_fail_nonfatal("pow(-1.0, +Inf) != 1.0");
+       }
+
+       if (pow(-1.0, infn) != 1.0) {
+               atf_tc_expect_fail("PR lib/45372");
+               atf_tc_fail_nonfatal("pow(-1.0, -Inf) != 1.0");
+       }
+#endif
+}
+
+ATF_TC(pow_one_pos_x);
+ATF_TC_HEAD(pow_one_pos_x, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test pow(1.0, y) == 1.0");
+}
+
+ATF_TC_BODY(pow_one_pos_x, tc)
+{
+#ifndef __vax__
+       const double y[] = { 0.0, 0.1, 2.0, -3.0, 99.0, 99.99, 9999999.9 };
+       const double z = 0.0L / 0.0L;
+       size_t i;
+
+       /*
+        * For any value of y (including NaN),
+        * if x is 1.0, 1.0 shall be returned.
+        */
+       if (pow(1.0, z) != 1.0)
+               atf_tc_fail_nonfatal("pow(1.0, NaN) != 1.0");
+
+       for (i = 0; i < __arraycount(y); i++) {
+
+               if (pow(1.0, y[i]) != 1.0)
+                       atf_tc_fail_nonfatal("pow(1.0, %0.01f) != 1.0", y[i]);
+       }
+#endif
+}
+
+ATF_TC(pow_zero_x);



Home | Main Index | Thread Index | Old Index