Source-Changes-HG archive

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

[src/trunk]: src IEEE checks for the exponential family.



details:   https://anonhg.NetBSD.org/src/rev/a3f223ed8f60
branches:  trunk
changeset: 769680:a3f223ed8f60
user:      jruoho <jruoho%NetBSD.org@localhost>
date:      Sun Sep 18 05:19:18 2011 +0000

description:
IEEE checks for the exponential family.

diffstat:

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

diffs (truncated from 730 to 300 lines):

diff -r c9f7e5ce0ae6 -r a3f223ed8f60 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sun Sep 18 04:49:11 2011 +0000
+++ b/distrib/sets/lists/tests/mi       Sun Sep 18 05:19:18 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.388 2011/09/17 18:08:36 jruoho Exp $
+# $NetBSD: mi,v 1.389 2011/09/18 05:19:18 jruoho Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -552,6 +552,7 @@
 ./usr/libdata/debug/usr/tests/lib/libm/t_ceil.debug                    tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libm/t_cos.debug                     tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libm/t_erf.debug                     tests-lib-debug         debug,atf
+./usr/libdata/debug/usr/tests/lib/libm/t_exp.debug                     tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libm/t_floor.debug                   tests-obsolete          obsolete
 ./usr/libdata/debug/usr/tests/lib/libm/t_infinity.debug                        tests-lib-debug         debug,atf
 ./usr/libdata/debug/usr/tests/lib/libm/t_ldexp.debug                   tests-lib-debug         debug,atf
@@ -2266,6 +2267,7 @@
 ./usr/tests/lib/libm/t_ceil                    tests-lib-tests         atf
 ./usr/tests/lib/libm/t_cos                     tests-lib-tests         atf
 ./usr/tests/lib/libm/t_erf                     tests-lib-tests         atf
+./usr/tests/lib/libm/t_exp                     tests-lib-tests         atf
 ./usr/tests/lib/libm/t_floor                   tests-obsolete          obsolete
 ./usr/tests/lib/libm/t_infinity                        tests-lib-tests         atf
 ./usr/tests/lib/libm/t_ldexp                   tests-lib-tests         atf
diff -r c9f7e5ce0ae6 -r a3f223ed8f60 tests/lib/libm/Makefile
--- a/tests/lib/libm/Makefile   Sun Sep 18 04:49:11 2011 +0000
+++ b/tests/lib/libm/Makefile   Sun Sep 18 05:19:18 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.12 2011/09/17 18:08:35 jruoho Exp $
+# $NetBSD: Makefile,v 1.13 2011/09/18 05:19:18 jruoho Exp $
 
 .include <bsd.own.mk>
 
@@ -10,6 +10,7 @@
 TESTS_C+=      t_ceil
 TESTS_C+=      t_cos
 TESTS_C+=      t_erf
+TESTS_C+=      t_exp
 TESTS_C+=      t_infinity
 TESTS_C+=      t_ldexp
 TESTS_C+=      t_log
diff -r c9f7e5ce0ae6 -r a3f223ed8f60 tests/lib/libm/t_exp.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/lib/libm/t_exp.c    Sun Sep 18 05:19:18 2011 +0000
@@ -0,0 +1,684 @@
+/* $NetBSD: t_exp.c,v 1.1 2011/09/18 05:19:18 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 <atf-c.h>
+#include <math.h>
+
+/*
+ * exp2(3)
+ */
+ATF_TC(exp2_nan);
+ATF_TC_HEAD(exp2_nan, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2(NaN) == NaN");
+}
+
+ATF_TC_BODY(exp2_nan, tc)
+{
+#ifndef __vax__
+       const double x = 0.0L / 0.0L;
+
+       if (isnan(exp2(x)) == 0)
+               atf_tc_fail_nonfatal("exp2(NaN) != NaN");
+#endif
+}
+
+ATF_TC(exp2_inf_neg);
+ATF_TC_HEAD(exp2_inf_neg, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2(-Inf) == +0.0");
+}
+
+ATF_TC_BODY(exp2_inf_neg, tc)
+{
+#ifndef __vax__
+       const double x = -1.0L / 0.0L;
+       double y = exp2(x);
+
+       if (fabs(y) > 0.0 || signbit(y) != 0)
+               atf_tc_fail_nonfatal("exp2(-Inf) != +0.0");
+#endif
+}
+
+ATF_TC(exp2_inf_pos);
+ATF_TC_HEAD(exp2_inf_pos, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2(+Inf) == +Inf");
+}
+
+ATF_TC_BODY(exp2_inf_pos, tc)
+{
+#ifndef __vax__
+       const double x = 1.0L / 0.0L;
+       double y = exp2(x);
+
+       if (isinf(y) == 0 || signbit(y) != 0)
+               atf_tc_fail_nonfatal("exp2(+Inf) != +Inf");
+#endif
+}
+
+ATF_TC(exp2_product);
+ATF_TC_HEAD(exp2_product, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2(x + y) == exp2(x) * exp2(y)");
+}
+
+ATF_TC_BODY(exp2_product, tc)
+{
+#ifndef __vax__
+       const double x[] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 };
+       const double y[] = { 8.8, 7.7, 6.6, 5.5, 4.4, 3.3, 2.2, 1.1, 0.0 };
+       const double eps = 1.0e-11;
+       size_t i;
+
+       for (i = 0; i < __arraycount(x); i++) {
+
+               if (fabs(exp2(x[i] + y[i]) - (exp2(x[i]) * exp2(y[i]))) > eps)
+                       atf_tc_fail_nonfatal("exp2(%0.01f + %0.01f) != exp2("
+                           "%0.01f) * exp2(%0.01f)", x[i], y[i], x[i], y[i]);
+       }
+#endif
+}
+
+ATF_TC(exp2_zero_neg);
+ATF_TC_HEAD(exp2_zero_neg, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2(-0.0) == 1.0");
+}
+
+ATF_TC_BODY(exp2_zero_neg, tc)
+{
+#ifndef __vax__
+       const double x = -0.0L;
+
+       if (fabs(exp2(x) - 1.0) > 0.0)
+               atf_tc_fail_nonfatal("exp2(-0.0) != 1.0");
+#endif
+}
+
+ATF_TC(exp2_zero_pos);
+ATF_TC_HEAD(exp2_zero_pos, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2(+0.0) == 1.0");
+}
+
+ATF_TC_BODY(exp2_zero_pos, tc)
+{
+#ifndef __vax__
+       const double x = 0.0L;
+
+       if (fabs(exp2(x) - 1.0) > 0.0)
+               atf_tc_fail_nonfatal("exp2(+0.0) != 1.0");
+#endif
+}
+
+/*
+ * exp2f(3)
+ */
+ATF_TC(exp2f_nan);
+ATF_TC_HEAD(exp2f_nan, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2f(NaN) == NaN");
+}
+
+ATF_TC_BODY(exp2f_nan, tc)
+{
+#ifndef __vax__
+       const float x = 0.0L / 0.0L;
+
+       if (isnan(exp2f(x)) == 0)
+               atf_tc_fail_nonfatal("exp2f(NaN) != NaN");
+#endif
+}
+
+ATF_TC(exp2f_inf_neg);
+ATF_TC_HEAD(exp2f_inf_neg, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2f(-Inf) == +0.0");
+}
+
+ATF_TC_BODY(exp2f_inf_neg, tc)
+{
+#ifndef __vax__
+       const float x = -1.0L / 0.0L;
+       float y = exp2f(x);
+
+       if (fabsf(y) > 0.0 || signbit(y) != 0)
+               atf_tc_fail_nonfatal("exp2f(-Inf) != +0.0");
+#endif
+}
+
+ATF_TC(exp2f_inf_pos);
+ATF_TC_HEAD(exp2f_inf_pos, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2f(+Inf) == +Inf");
+}
+
+ATF_TC_BODY(exp2f_inf_pos, tc)
+{
+#ifndef __vax__
+       const float x = 1.0L / 0.0L;
+       float y = exp2f(x);
+
+       if (isinf(y) == 0 || signbit(y) != 0)
+               atf_tc_fail_nonfatal("exp2f(+Inf) != +Inf");
+#endif
+}
+
+ATF_TC(exp2f_product);
+ATF_TC_HEAD(exp2f_product, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2f(x+y) == exp2f(x) * exp2f(y)");
+}
+
+ATF_TC_BODY(exp2f_product, tc)
+{
+#ifndef __vax__
+       const float x[] = { 0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8 };
+       const float y[] = { 8.8, 7.7, 6.6, 5.5, 4.4, 3.3, 2.2, 1.1, 0.0 };
+       const float eps = 1.0e-2;
+       size_t i;
+
+       for (i = 0; i < __arraycount(x); i++) {
+
+               if (fabsf(exp2f(x[i] + y[i]) -
+                       (exp2f(x[i]) * exp2f(y[i]))) > eps)
+                       atf_tc_fail_nonfatal("exp2f(%0.01f + %0.01f) != exp2f("
+                           "%0.01f) * exp2f(%0.01f)", x[i], y[i], x[i], y[i]);
+       }
+#endif
+}
+
+ATF_TC(exp2f_zero_neg);
+ATF_TC_HEAD(exp2f_zero_neg, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2f(-0.0) == 1.0");
+}
+
+ATF_TC_BODY(exp2f_zero_neg, tc)
+{
+#ifndef __vax__
+       const float x = -0.0L;
+
+       if (fabsf(exp2f(x) - 1.0) > 0.0)
+               atf_tc_fail_nonfatal("exp2f(-0.0) != 1.0");
+#endif
+}
+
+ATF_TC(exp2f_zero_pos);
+ATF_TC_HEAD(exp2f_zero_pos, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test exp2f(+0.0) == 1.0");
+}
+
+ATF_TC_BODY(exp2f_zero_pos, tc)
+{
+#ifndef __vax__
+       const float x = 0.0L;
+
+       if (fabsf(exp2f(x) - 1.0) > 0.0)
+               atf_tc_fail_nonfatal("exp2f(+0.0) != 1.0");
+#endif
+}
+
+/*
+ * exp(3)
+ */



Home | Main Index | Thread Index | Old Index