The branch stable/13 has been updated by arichardson:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=f6742fbfb5f6d1651d88ce0952b0ec58c5a735a1

commit f6742fbfb5f6d1651d88ce0952b0ec58c5a735a1
Author:     Alex Richardson <[email protected]>
AuthorDate: 2021-02-22 17:19:06 +0000
Commit:     Alex Richardson <[email protected]>
CommitDate: 2021-04-22 09:41:45 +0000

    Update libm tests from NetBSD
    
    I did this without a full vendor update since that would cause too many
    conflicts. Since these files now almost match the NetBSD sources the
    next git subtree merge should work just fine.
    
    Reviewed By:    lwhsu
    Differential Revision: https://reviews.freebsd.org/D28797
    
    (cherry picked from commit 1ec3feb64826d2a43d41e74684690985bf20e71c)
---
 contrib/netbsd-tests/lib/libm/t_acos.c     |   4 +-
 contrib/netbsd-tests/lib/libm/t_asin.c     |  35 ++++--
 contrib/netbsd-tests/lib/libm/t_bit.c      | 102 +++++++++++++++
 contrib/netbsd-tests/lib/libm/t_cabsl.cxx  |  66 ++++++++++
 contrib/netbsd-tests/lib/libm/t_cbrt.c     |  95 +++++++++-----
 contrib/netbsd-tests/lib/libm/t_cos.c      | 196 ++++++++++++++++++++++++-----
 contrib/netbsd-tests/lib/libm/t_cosh.c     |  58 +++++----
 contrib/netbsd-tests/lib/libm/t_exp.c      |  52 ++++----
 contrib/netbsd-tests/lib/libm/t_fe_round.c | 138 +++++++++++++++++++-
 contrib/netbsd-tests/lib/libm/t_fenv.c     |  12 +-
 contrib/netbsd-tests/lib/libm/t_fmod.c     |   8 +-
 contrib/netbsd-tests/lib/libm/t_ilogb.c    |   8 +-
 contrib/netbsd-tests/lib/libm/t_ldexp.c    |  37 +++---
 contrib/netbsd-tests/lib/libm/t_libm.h     |   6 +-
 contrib/netbsd-tests/lib/libm/t_log.c      |  18 +--
 contrib/netbsd-tests/lib/libm/t_round.c    |  55 +++++++-
 contrib/netbsd-tests/lib/libm/t_scalbn.c   |  58 ++++++---
 contrib/netbsd-tests/lib/libm/t_sin.c      |  91 +++++++++-----
 contrib/netbsd-tests/lib/libm/t_sinh.c     |  56 ++++-----
 contrib/netbsd-tests/lib/libm/t_sqrt.c     |  84 ++++++++-----
 contrib/netbsd-tests/lib/libm/t_tan.c      |  86 +++++++++----
 lib/msun/tests/Makefile                    |   2 +
 22 files changed, 946 insertions(+), 321 deletions(-)

diff --git a/contrib/netbsd-tests/lib/libm/t_acos.c 
b/contrib/netbsd-tests/lib/libm/t_acos.c
index f051fb64df42..973f0245cdab 100644
--- a/contrib/netbsd-tests/lib/libm/t_acos.c
+++ b/contrib/netbsd-tests/lib/libm/t_acos.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_acos.c,v 1.10 2014/03/05 20:14:46 dsl Exp $ */
+/* $NetBSD: t_acos.c,v 1.11 2018/11/07 03:59:36 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -72,7 +72,7 @@ ATF_LIBM_TEST(acos_inrange, "Test acos/acosf(x) for some 
valid values")
                {  0,    M_PI / 2,          },
                {  0.1,  1.470628905633337, },
                {  0.5,  1.047197551196598, },
-               {  0.99, 0.141539473324427, },
+               {  0.99, 0.1415394733244273, },
        };
        unsigned int i;
 
diff --git a/contrib/netbsd-tests/lib/libm/t_asin.c 
b/contrib/netbsd-tests/lib/libm/t_asin.c
index 06de85216429..213b1f875439 100644
--- a/contrib/netbsd-tests/lib/libm/t_asin.c
+++ b/contrib/netbsd-tests/lib/libm/t_asin.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_asin.c,v 1.3 2014/03/03 10:39:08 martin Exp $ */
+/* $NetBSD: t_asin.c,v 1.4 2018/11/07 03:59:36 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -30,6 +30,7 @@
  */
 
 #include <atf-c.h>
+#include <float.h>
 #include <math.h>
 
 static const struct {
@@ -117,13 +118,14 @@ ATF_TC_HEAD(asin_inrange, tc)
 
 ATF_TC_BODY(asin_inrange, tc)
 {
-       const double eps = 1.0e-15;
-       double y;
+       const double eps = DBL_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(values); i++) {
-               y = asin(values[i].x);
-               if (fabs(y - values[i].y) > eps)
+               double x = values[i].x;
+               double y = values[i].y;
+
+               if (!(fabs((asin(x) - y)/y) <= eps))
                        atf_tc_fail_nonfatal("asin(%g) != %g",
                                values[i].x, values[i].y);
        }
@@ -230,16 +232,25 @@ ATF_TC_HEAD(asinf_inrange, tc)
 
 ATF_TC_BODY(asinf_inrange, tc)
 {
-       const float eps = 1.0e-6;
-       float x;
-       float y;
+       const float eps = FLT_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(values); i++) {
-               x = values[i].x;
-               y = values[i].y;
-               if (fabs(asinf(x) - y) > eps)
-                       atf_tc_fail_nonfatal("asinf(%g) != %g", x, y);
+               float x = values[i].x;
+               float y = values[i].y;
+
+#ifdef __NetBSD__
+               if (fabs(x) == 0.5)
+                       atf_tc_expect_fail("asinf is busted,"
+                           " gives ~2ulp error");
+#endif
+               if (!(fabsf((asinf(x) - y)/y) <= eps)) {
+                       atf_tc_fail_nonfatal("asinf(%.8g) = %.8g != %.8g,"
+                           " error=~%.1fulp",
+                           x, asinf(x), y, fabsf(((asinf(x) - y)/y)/eps));
+               }
+               if (fabs(x) == 0.5)
+                       atf_tc_expect_pass();
        }
 }
 
diff --git a/contrib/netbsd-tests/lib/libm/t_bit.c 
b/contrib/netbsd-tests/lib/libm/t_bit.c
new file mode 100644
index 000000000000..b6e0218f601c
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libm/t_bit.c
@@ -0,0 +1,102 @@
+/* $NetBSD: t_bit.c,v 1.1 2019/04/26 08:52:16 maya Exp $ */
+
+/*
+ * Written by Maya Rashish <[email protected]>
+ * Public domain.
+ *
+ * Testing signbit{,f,l} function correctly
+ */
+
+#include <atf-c.h>
+#include <float.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdbool.h>
+
+static const struct {
+       double input;
+       bool is_negative;
+} values[] = {
+       { -1,           true},
+       { -123,         true},
+       { -123E6,       true},
+#ifdef INFINITY
+       { -INFINITY,    true},
+       { INFINITY,     false},
+#endif
+       { 123E6,        false},
+       { 0,            false},
+       { -FLT_MIN,     true},
+       { FLT_MIN,      false},
+       /* 
+        * Cannot be accurately represented as float,
+        * but sign should be preserved
+        */
+       { DBL_MAX,      false},
+       { -DBL_MAX,     true},
+};
+
+#ifdef __HAVE_LONG_DOUBLE
+static const struct {
+       long double input;
+       bool is_negative;
+} ldbl_values[] = {
+       { -LDBL_MIN,    true},
+       { LDBL_MIN,     false},
+       { LDBL_MAX,     false},
+       { -LDBL_MAX,    true},
+};
+#endif
+
+ATF_TC(signbit);
+ATF_TC_HEAD(signbit, tc)
+{
+       atf_tc_set_md_var(tc, "descr","Check that signbit functions correctly");
+}
+
+ATF_TC_BODY(signbit, tc)
+{
+       double iterator_d;
+       float iterator_f;
+
+       for (unsigned int i = 0; i < __arraycount(values); i++) {
+               iterator_d = values[i].input;
+               iterator_f = (float) values[i].input;
+               if (signbit(iterator_f) != values[i].is_negative)
+                       atf_tc_fail("%s:%d iteration %d signbitf is wrong"
+                                       " about the sign of %f", __func__,
+                                       __LINE__, i, iterator_f);
+               if (signbit(iterator_d) != values[i].is_negative)
+                       atf_tc_fail("%s:%d iteration %d signbit is wrong"
+                                       "about the sign of %f", __func__,
+                                       __LINE__,i, iterator_d);
+
+#ifdef __HAVE_LONG_DOUBLE
+               long double iterator_l = values[i].input;
+               if (signbit(iterator_l) != values[i].is_negative)
+                       atf_tc_fail("%s:%d iteration %d signbitl is wrong"
+                                       " about the sign of %Lf", __func__,
+                                       __LINE__, i, iterator_l);
+#endif
+       }
+
+#ifdef __HAVE_LONG_DOUBLE
+       for (unsigned int i = 0; i < __arraycount(ldbl_values); i++) {
+               if (signbit(ldbl_values[i].input) != ldbl_values[i].is_negative)
+                       atf_tc_fail("%s:%d iteration %d signbitl is"
+                                       "wrong about the sign of %Lf",
+                                       __func__, __LINE__, i,
+                                       ldbl_values[i].input);
+       }
+#endif
+
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+       ATF_TP_ADD_TC(tp, signbit);
+
+       return atf_no_error();
+}
diff --git a/contrib/netbsd-tests/lib/libm/t_cabsl.cxx 
b/contrib/netbsd-tests/lib/libm/t_cabsl.cxx
new file mode 100644
index 000000000000..7dd119b1da3b
--- /dev/null
+++ b/contrib/netbsd-tests/lib/libm/t_cabsl.cxx
@@ -0,0 +1,66 @@
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Maya Rashish
+ *
+ * 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.
+ */
+
+/*
+ * Test that C++ "cabsl" is usable. PR lib/50646
+ */
+
+#include <atf-c++.hpp>
+#include <complex>
+
+ATF_TEST_CASE(cabsl);
+ATF_TEST_CASE_HEAD(cabsl)
+{
+       set_md_var("descr", "Check that cabsl is usable from C++");
+}
+ATF_TEST_CASE_BODY(cabsl)
+{
+       int sum = 0;
+
+#ifdef __HAVE_LONG_DOUBLE
+       std::complex<long double> cld(3.0,4.0);
+       sum += std::abs(cld);
+#endif
+       std::complex<double> cd(3.0,4.0);
+       sum += std::abs(cd);
+
+       std::complex<float> cf(3.0,4.0);
+       sum += std::abs(cf);
+
+#ifdef __HAVE_LONG_DOUBLE
+       ATF_REQUIRE_EQ(sum, 3*5);
+#else
+       ATF_REQUIRE_EQ(sum, 2*5);
+#endif
+}
+
+ATF_INIT_TEST_CASES(tcs)
+{
+       ATF_ADD_TEST_CASE(tcs, cabsl);
+}
diff --git a/contrib/netbsd-tests/lib/libm/t_cbrt.c 
b/contrib/netbsd-tests/lib/libm/t_cbrt.c
index 08e9faeb145c..639bc7e06517 100644
--- a/contrib/netbsd-tests/lib/libm/t_cbrt.c
+++ b/contrib/netbsd-tests/lib/libm/t_cbrt.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cbrt.c,v 1.3 2014/03/03 10:39:08 martin Exp $ */
+/* $NetBSD: t_cbrt.c,v 1.5 2018/11/15 05:14:20 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,9 +29,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_cbrt.c,v 1.3 2014/03/03 10:39:08 martin Exp $");
+__RCSID("$NetBSD: t_cbrt.c,v 1.5 2018/11/15 05:14:20 riastradh Exp $");
 
 #include <atf-c.h>
+#include <float.h>
 #include <math.h>
 #include <stdio.h>
 
@@ -61,18 +62,26 @@ ATF_TC_HEAD(cbrt_pow, tc)
 ATF_TC_BODY(cbrt_pow, tc)
 {
        const double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
-       const double eps = 1.0e-14;
-       double y, z;
+       /* Neither cbrt nor pow is required to be correctly rounded.  */
+       const double eps = 2*DBL_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(x); i++) {
-
-               y = cbrt(x[i]);
-               z = pow(x[i], 1.0 / 3.0);
-
-               if (fabs(y - z) > eps)
-                       atf_tc_fail_nonfatal("cbrt(%0.03f) != "
-                           "pow(%0.03f, 1/3)\n", x[i], x[i]);
+               double x_cbrt = cbrt(x[i]);
+               double x_pow13 = pow(x[i], 1.0 / 3.0);
+               bool ok;
+
+               if (x[i] == 0) {
+                       ok = (x_cbrt == x_pow13);
+               } else {
+                       ok = (fabs((x_cbrt - x_pow13)/x_cbrt) <= eps);
+               }
+
+               if (!ok) {
+                       atf_tc_fail_nonfatal("cbrt(%.17g) = %.17g != "
+                           "pow(%.17g, 1/3) = %.17g\n",
+                           x[i], x_cbrt, x[i], x_pow13);
+               }
        }
 }
 
@@ -162,18 +171,27 @@ ATF_TC_HEAD(cbrtf_powf, tc)
 ATF_TC_BODY(cbrtf_powf, tc)
 {
        const float x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
-       const float eps = 1.0e-5;
-       float y, z;
+       /* Neither cbrt nor pow is required to be correctly rounded.  */
+       const float eps = 2*FLT_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(x); i++) {
-
-               y = cbrtf(x[i]);
-               z = powf(x[i], 1.0 / 3.0);
-
-               if (fabsf(y - z) > eps)
-                       atf_tc_fail_nonfatal("cbrtf(%0.03f) != "
-                           "powf(%0.03f, 1/3)\n", x[i], x[i]);
+               float x_cbrt = cbrtf(x[i]);
+               float x_pow13 = powf(x[i], 1.0 / 3.0);
+               bool ok;
+
+               if (x[i] == 0) {
+                       ok = (x_cbrt == x_pow13);
+               } else {
+                       ok = (fabsf((x_cbrt - x_pow13)/x_cbrt) <= eps);
+               }
+
+               if (!ok) {
+                       atf_tc_fail_nonfatal("cbrtf(%.9g) = %.9g. != "
+                           "powf(%.9g, 1/3) = %.9g\n",
+                           (double)x[i], (double)x_cbrt,
+                           (double)x[i], (double)x_pow13);
+               }
        }
 }
 
@@ -264,27 +282,42 @@ ATF_TC_HEAD(cbrtl_powl, tc)
 ATF_TC_BODY(cbrtl_powl, tc)
 {
        const long double x[] = { 0.0, 0.005, 1.0, 99.0, 123.123, 9999.0 };
-       const long double eps = 1.0e-15;
-       long double y, z;
+       /* Neither cbrt nor pow is required to be correctly rounded.  */
+       const long double eps = 2*LDBL_EPSILON;
        size_t i;
 
 #if defined(__amd64__) && defined(__clang__) && __clang_major__ >= 7 && \
     __clang_major__ < 10 && __FreeBSD_cc_version < 1300002
        atf_tc_expect_fail("test fails with clang 7-9 - bug 234040");
 #endif
-
        for (i = 0; i < __arraycount(x); i++) {
-
-               y = cbrtl(x[i]);
+               long double x_cbrt = cbrtl(x[i]);
 #ifdef __FreeBSD__
-               z = powl(x[i], (long double)1.0 / 3.0);
+               /*
+                * NetBSD doesn't have a real powl/cbrtl implementation, they
+                * just call the double version. On FreeBSD we have a real
+                * powl implementation so we have to cast the second argument
+                * to long double before dividing to get a more precise
+                * approximation of 1/3.
+                * TODO: upstream this diff.
+                */
+               long double x_pow13 = powl(x[i], (long double)1.0 / 3.0);
 #else
-               z = powl(x[i], 1.0 / 3.0);
+               long double x_pow13 = powl(x[i], 1.0 / 3.0);
 #endif
-
-               if (fabsl(y - z) > eps * fabsl(1 + x[i]))
-                       atf_tc_fail_nonfatal("cbrtl(%0.03Lf) != "
-                           "powl(%0.03Lf, 1/3)\n", x[i], x[i]);
+               bool ok;
+
+               if (x[i] == 0) {
+                       ok = (x_cbrt == x_pow13);
+               } else {
+                       ok = (fabsl((x_cbrt - x_pow13)/x_cbrt) <= eps);
+               }
+
+               if (!ok) {
+                       atf_tc_fail_nonfatal("cbrtl(%.35Lg) = %.35Lg != "
+                           "powl(%.35Lg, 1/3) = %.35Lg\n",
+                           x[i], x_cbrt, x[i], x_pow13);
+               }
        }
 }
 
diff --git a/contrib/netbsd-tests/lib/libm/t_cos.c 
b/contrib/netbsd-tests/lib/libm/t_cos.c
index d99d60810eeb..ca5f0aab7ffa 100644
--- a/contrib/netbsd-tests/lib/libm/t_cos.c
+++ b/contrib/netbsd-tests/lib/libm/t_cos.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cos.c,v 1.4 2014/03/03 10:39:08 martin Exp $ */
+/* $NetBSD: t_cos.c,v 1.9 2019/05/27 00:10:36 maya Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,31 +29,138 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <assert.h>
 #include <atf-c.h>
+#include <float.h>
 #include <math.h>
 
 static const struct {
        int             angle;
        double          x;
        double          y;
+       float           fy;
 } angles[] = {
-       { -180, -3.141592653589793, -1.0000000000000000 },
-       { -135, -2.356194490192345, -0.7071067811865476 },
-       {  -90, -1.570796326794897,  0.0000000000000000 },
-       {  -45, -0.785398163397448,  0.7071067811865476 },
-       {    0,  0.000000000000000,  1.0000000000000000 },
-       {   30,  0.523598775598299,  0.8660254037844386 },
-       {   45,  0.785398163397448,  0.7071067811865476 },
-       {   60,  1.047197551196598,  0.5000000000000000 },
-       {   90,  1.570796326794897,  0.0000000000000000 },
-       {  120,  2.094395102393195, -0.5000000000000000 },
-       {  135,  2.356194490192345, -0.7071067811865476 },
-       {  150,  2.617993877991494, -0.8660254037844386 },
-       {  180,  3.141592653589793, -1.0000000000000000 },
-       {  270,  4.712388980384690,  0.0000000000000000 },
-       {  360,  6.283185307179586,  1.0000000000000000 }
+       { -180, -3.141592653589793, -1.0000000000000000, 999 },
+       { -135, -2.356194490192345, -0.7071067811865476, 999 },
+       {  -90, -1.5707963267948966, 6.123233995736766e-17, -4.3711388e-08 },
+       {  -90, -1.5707963267948968, -1.6081226496766366e-16, -4.3711388e-08 },
+       {  -45, -0.785398163397448,  0.7071067811865478, 999 },
+       {    0,  0.000000000000000,  1.0000000000000000, 999 },
+       {   30,  0.523598775598299,  0.8660254037844386, 999 },
+       {   45,  0.785398163397448,  0.7071067811865478, 999 },
+       {   60,  1.0471975511965976,  0.5000000000000001, 999 },
+       {   60,  1.0471975511965979,  0.4999999999999999, 999 },
+       {   90,  1.570796326794897, -3.8285686989269494e-16, -4.3711388e-08 },
+       {  120,  2.0943951023931953, -0.4999999999999998, 999 },
+       {  120,  2.0943951023931957, -0.5000000000000002, 999 },
+       {  135,  2.356194490192345, -0.7071067811865476, 999 },
+       {  150,  2.617993877991494, -0.8660254037844386, 999 },
+       {  180,  3.141592653589793, -1.0000000000000000, 999 },
+       {  270,  4.712388980384690, -1.8369701987210297e-16, 1.1924881e-08 },
+       {  360,  6.283185307179586,  1.0000000000000000, 999 },
 };
 
+#ifdef __HAVE_LONG_DOUBLE
+/*
+ * cosl(3)
+ */
+ATF_TC(cosl_angles);
+ATF_TC_HEAD(cosl_angles, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test some selected angles");
+}
+
+ATF_TC_BODY(cosl_angles, tc)
+{
+       /*
+        * XXX The given data is for double, so take that
+        * into account and expect less precise results..
+        */
+       const long double eps = DBL_EPSILON;
+       size_t i;
+
+       for (i = 0; i < __arraycount(angles); i++) {
+               int deg = angles[i].angle;
+               long double theta = angles[i].x;
+               long double cos_theta = angles[i].y;
+
+               assert(cos_theta != 0);
+               if (!(fabsl((cosl(theta) - cos_theta)/cos_theta) <= eps)) {
+                       atf_tc_fail_nonfatal("cos(%d deg = %.17Lg) = %.17Lg"
+                           " != %.17Lg",
+                           deg, theta, cosl(theta), cos_theta);
+               }
+       }
+}
+
+ATF_TC(cosl_nan);
+ATF_TC_HEAD(cosl_nan, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test cosl(NaN) == NaN");
+}
+
+ATF_TC_BODY(cosl_nan, tc)
+{
+       const long double x = 0.0L / 0.0L;
+
+       ATF_CHECK(isnan(x) != 0);
+       ATF_CHECK(isnan(cosl(x)) != 0);
+}
+
+ATF_TC(cosl_inf_neg);
+ATF_TC_HEAD(cosl_inf_neg, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test cosl(-Inf) == NaN");
+}
+
+ATF_TC_BODY(cosl_inf_neg, tc)
+{
+       const long double x = -1.0L / 0.0L;
+
+       ATF_CHECK(isnan(cosl(x)) != 0);
+}
+
+ATF_TC(cosl_inf_pos);
+ATF_TC_HEAD(cosl_inf_pos, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test cosl(+Inf) == NaN");
+}
+
+ATF_TC_BODY(cosl_inf_pos, tc)
+{
+       const long double x = 1.0L / 0.0L;
+
+       ATF_CHECK(isnan(cosl(x)) != 0);
+}
+
+
+ATF_TC(cosl_zero_neg);
+ATF_TC_HEAD(cosl_zero_neg, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test cosl(-0.0) == 1.0");
+}
+
+ATF_TC_BODY(cosl_zero_neg, tc)
+{
+       const long double x = -0.0L;
+
+       ATF_CHECK(cosl(x) == 1.0);
+}
+
+ATF_TC(cosl_zero_pos);
+ATF_TC_HEAD(cosl_zero_pos, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test cosl(+0.0) == 1.0");
+}
+
+ATF_TC_BODY(cosl_zero_pos, tc)
+{
+       const long double x = 0.0L;
+
+       ATF_CHECK(cosl(x) == 1.0);
+}
+#endif
+
 /*
  * cos(3)
  */
@@ -65,14 +172,20 @@ ATF_TC_HEAD(cos_angles, tc)
 
 ATF_TC_BODY(cos_angles, tc)
 {
-       const double eps = 1.0e-15;
+       const double eps = DBL_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(angles); i++) {
-
-               if (fabs(cos(angles[i].x) - angles[i].y) > eps)
-                       atf_tc_fail_nonfatal("cos(%d deg) != %0.01f",
-                           angles[i].angle, angles[i].y);
+               int deg = angles[i].angle;
+               double theta = angles[i].x;
+               double cos_theta = angles[i].y;
+
+               assert(cos_theta != 0);
+               if (!(fabs((cos(theta) - cos_theta)/cos_theta) <= eps)) {
+                       atf_tc_fail_nonfatal("cos(%d deg = %.17g) = %.17g"
+                           " != %.17g",
+                           deg, theta, cos(theta), cos_theta);
+               }
        }
 }
 
@@ -154,18 +267,33 @@ ATF_TC_HEAD(cosf_angles, tc)
 
 ATF_TC_BODY(cosf_angles, tc)
 {
-       const float eps = 1.0e-7;
-       float x, y;
+       const float eps = FLT_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(angles); i++) {
-
-               x = angles[i].x;
-               y = angles[i].y;
-
-               if (fabsf(cosf(x) - y) > eps)
-                       atf_tc_fail_nonfatal("cosf(%d deg) != %0.01f",
-                           angles[i].angle, angles[i].y);
+               int deg = angles[i].angle;
+               float theta = angles[i].x;
+               float cos_theta = angles[i].fy;
+
+               /*
+                * Force rounding to float even if FLT_EVAL_METHOD=2,
+                * as is the case on i386.
+                *
+                * The volatile should not be necessary, by C99 Sec.
+                * 5.2.4.2.2. para. 8 on p. 24 which specifies that
+                * assignment and cast remove all extra range and precision,
+                * but seems to be needed to work around a compiler bug.
+                */ 
+               volatile float result = cosf(theta);
+
+               if (cos_theta == 999)
+                       cos_theta = angles[i].y;
+
+               assert(cos_theta != 0);
+               if (!(fabsf((result - cos_theta)/cos_theta) <= eps)) {
+                       atf_tc_fail_nonfatal("cosf(%d deg = %.8g) = %.8g"
+                           " != %.8g", deg, theta, result, cos_theta);
+               }
        }
 }
 
@@ -244,6 +372,14 @@ ATF_TC_BODY(cosf_zero_pos, tc)
 
 ATF_TP_ADD_TCS(tp)
 {
+#ifdef __HAVE_LONG_DOUBLE
+       ATF_TP_ADD_TC(tp, cosl_angles);
+       ATF_TP_ADD_TC(tp, cosl_nan);
+       ATF_TP_ADD_TC(tp, cosl_inf_neg);
+       ATF_TP_ADD_TC(tp, cosl_inf_pos);
+       ATF_TP_ADD_TC(tp, cosl_zero_neg);
+       ATF_TP_ADD_TC(tp, cosl_zero_pos);
+#endif
 
        ATF_TP_ADD_TC(tp, cos_angles);
        ATF_TP_ADD_TC(tp, cos_nan);
diff --git a/contrib/netbsd-tests/lib/libm/t_cosh.c 
b/contrib/netbsd-tests/lib/libm/t_cosh.c
index 3f998de761bb..aac3a39b0236 100644
--- a/contrib/netbsd-tests/lib/libm/t_cosh.c
+++ b/contrib/netbsd-tests/lib/libm/t_cosh.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_cosh.c,v 1.6 2014/03/03 10:39:08 martin Exp $ */
+/* $NetBSD: t_cosh.c,v 1.7 2018/11/07 03:59:36 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,28 +29,28 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_cosh.c,v 1.6 2014/03/03 10:39:08 martin Exp $");
+__RCSID("$NetBSD: t_cosh.c,v 1.7 2018/11/07 03:59:36 riastradh Exp $");
 
 #include <atf-c.h>
+#include <float.h>
 #include <math.h>
 #include <stdio.h>
 
 static const struct {
        double x;
        double y;
-       double e;
 } values[] = {
-       { -10,    11013.23292010332, 1e4, },
-       { -2,     3.762195691083631, 1,   },
-       { -1,     1.543080634815244, 1,   },
-       { -0.05,  1.001250260438369, 1,   },
-       { -0.001, 1.000000500000042, 1,   },
-       {  0,     1,                 1,   },
-       {  0.001, 1.000000500000042, 1,   },
-       {  0.05,  1.001250260438369, 1,   },
-       {  1,     1.543080634815244, 1,   },
-       {  2,     3.762195691083631, 1,   },
-       {  10,    11013.23292010332, 1e4, },
+       { -10,    11013.232920103323, },
+       { -2,     3.762195691083631, },
+       { -1,     1.543080634815244, },
+       { -0.05,  1.001250260438369, },
+       { -0.001, 1.0000005000000418, },
+       {  0,     1,                 },
+       {  0.001, 1.0000005000000418, },
+       {  0.05,  1.001250260438369, },
+       {  1,     1.543080634815244, },
+       {  2,     3.762195691083631, },
+       {  10,    11013.232920103323, },
 };
 
 /*
@@ -64,18 +64,17 @@ ATF_TC_HEAD(cosh_inrange, tc)
 
 ATF_TC_BODY(cosh_inrange, tc)
 {
-       double eps;
-       double x;
-       double y;
+       const double eps = DBL_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(values); i++) {
-               x = values[i].x;
-               y = values[i].y;
-               eps = 1e-15 * values[i].e;
+               double x = values[i].x;
+               double cosh_x = values[i].y;
 
-               if (fabs(cosh(x) - y) > eps)
-                       atf_tc_fail_nonfatal("cosh(%g) != %g\n", x, y);
+               if (!(fabs((cosh(x) - cosh_x)/cosh_x) <= eps)) {
+                       atf_tc_fail_nonfatal("cosh(%.17g) = %.17g != %.17g\n",
+                           x, cosh(x), cosh_x);
+               }
        }
 }
 
@@ -162,18 +161,17 @@ ATF_TC_HEAD(coshf_inrange, tc)
 
 ATF_TC_BODY(coshf_inrange, tc)
 {
-       float eps;
-       float x;
-       float y;
+       const float eps = FLT_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(values); i++) {
-               x = values[i].x;
-               y = values[i].y;
-               eps = 1e-6 * values[i].e;
+               float x = values[i].x;
+               float cosh_x = values[i].y;
 
-               if (fabsf(coshf(x) - y) > eps)
-                       atf_tc_fail_nonfatal("coshf(%g) != %g\n", x, y);
+               if (!(fabsf((coshf(x) - cosh_x)/cosh_x) <= eps)) {
+                       atf_tc_fail_nonfatal("coshf(%.17g) = %.17g != %.17g\n",
+                           x, coshf(x), cosh_x);
+               }
        }
 }
 
diff --git a/contrib/netbsd-tests/lib/libm/t_exp.c 
b/contrib/netbsd-tests/lib/libm/t_exp.c
index 0eb6412b566e..acef4c0e91de 100644
--- a/contrib/netbsd-tests/lib/libm/t_exp.c
+++ b/contrib/netbsd-tests/lib/libm/t_exp.c
@@ -1,4 +1,4 @@
-/* $NetBSD: t_exp.c,v 1.8 2014/10/07 16:53:44 gson Exp $ */
+/* $NetBSD: t_exp.c,v 1.9 2018/11/07 03:59:36 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -30,6 +30,7 @@
  */
 
 #include <atf-c.h>
+#include <float.h>
 #include <math.h>
 #include "t_libm.h"
 
@@ -37,17 +38,16 @@
 static const struct {
        double x;
        double y;
-       double e;
 } exp_values[] = {
-       {  -10, 0.4539992976248485e-4, 1e-4, },
-       {   -5, 0.6737946999085467e-2, 1e-2, },
-       {   -1, 0.3678794411714423,    1e-1, },
-       { -0.1, 0.9048374180359595,    1e-1, },
-       {    0, 1.0000000000000000,    1,    },
-       {  0.1, 1.1051709180756477,    1,    },
-       {    1, 2.7182818284590452,    1,    },
-       {    5, 148.41315910257660,    1e2, },
-       {   10, 22026.465794806718,    1e4, },
+       {  -10, 0.4539992976248485e-4, },
+       {   -5, 0.6737946999085467e-2, },
+       {   -1, 0.3678794411714423,    },
+       { -0.1, 0.9048374180359595,    },
+       {    0, 1.0000000000000000,    },
+       {  0.1, 1.1051709180756477,    },
+       {    1, 2.7182818284590452,    },
+       {    5, 148.41315910257660,    },
+       {   10, 22026.465794806718,    },
 };
 
 /*
@@ -238,18 +238,17 @@ ATF_TC_HEAD(exp_product, tc)
 
 ATF_TC_BODY(exp_product, tc)
 {
-       double eps;
-       double x;
-       double y;
+       const double eps = DBL_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(exp_values); i++) {
-               x = exp_values[i].x;
-               y = exp_values[i].y;
-               eps = 1e-15 * exp_values[i].e;
+               double x = exp_values[i].x;
+               double e_x = exp_values[i].y;
 
-               if (fabs(exp(x) - y) > eps)
-                       atf_tc_fail_nonfatal("exp(%0.01f) != %18.18e", x, y);
+               if (!(fabs((exp(x) - e_x)/e_x) <= eps)) {
+                       atf_tc_fail_nonfatal("exp(%.17g) = %.17g != %.17g",
+                           x, exp(x), e_x);
+               }
        }
 }
 
@@ -336,18 +335,17 @@ ATF_TC_HEAD(expf_product, tc)
 
 ATF_TC_BODY(expf_product, tc)
 {
-       float eps;
-       float x;
-       float y;
+       const float eps = FLT_EPSILON;
        size_t i;
 
        for (i = 0; i < __arraycount(exp_values); i++) {
-               x = exp_values[i].x;
-               y = exp_values[i].y;
-               eps = 1e-6 * exp_values[i].e;
+               float x = exp_values[i].x;
+               float e_x = exp_values[i].y;
 
-               if (fabsf(expf(x) - y) > eps)
-                       atf_tc_fail_nonfatal("expf(%0.01f) != %18.18e", x, y);
+               if (!(fabsf((expf(x) - e_x)/e_x) <= eps)) {
+                       atf_tc_fail_nonfatal("expf(%.8g) = %.8g != %.8g",
+                           x, exp(x), e_x);
+               }
        }
 }
 
diff --git a/contrib/netbsd-tests/lib/libm/t_fe_round.c 
b/contrib/netbsd-tests/lib/libm/t_fe_round.c
index fe805b4f86b8..33da289eb156 100644
--- a/contrib/netbsd-tests/lib/libm/t_fe_round.c
+++ b/contrib/netbsd-tests/lib/libm/t_fe_round.c
@@ -89,7 +89,97 @@ ATF_TC_BODY(fe_round, tc)
                    (fegetround() == values[i].round_mode),
                    "Didn't get the same rounding mode out!\n"
                    "(index %d) fed in %d rounding mode, got %d out\n",
-                   i, fegetround(), values[i].round_mode);
+                   i, values[i].round_mode, fegetround());
+       }
+}
+
+ATF_TC(fe_nearbyint);
+ATF_TC_HEAD(fe_nearbyint, tc)
+{
+       atf_tc_set_md_var(tc, "descr","Checking IEEE 754 rounding modes using 
nearbyint");
+}
+
+ATF_TC_BODY(fe_nearbyint, tc)
+{
+       double received;
+
+       for (unsigned int i = 0; i < __arraycount(values); i++) {
+               fesetround(values[i].round_mode);
+
+               received = nearbyint(values[i].input);
+               ATF_CHECK_MSG(
+                   (fabs(received - values[i].expected) < EPSILON),
+                   "nearbyint rounding wrong, difference too large\n"
+                   "input: %f (index %d): got %f, expected %ld\n",
+                   values[i].input, i, received, values[i].expected);
+
+               /* Do we get the same rounding mode out? */
+               ATF_CHECK_MSG(
+                   (fegetround() == values[i].round_mode),
+                   "Didn't get the same rounding mode out!\n"
+                   "(index %d) fed in %d rounding mode, got %d out\n",
+                   i, values[i].round_mode, fegetround());
+       }
+}
+
+static const struct {
+       double input;
+       double toward;
+       double expected;
+} values2[] = {
+       { 10.0, 11.0, 10.0 },
+       { -5.0, -6.0, -5.0 },
+};
+
+ATF_TC(fe_nextafter);
+ATF_TC_HEAD(fe_nextafter, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checking IEEE 754 rounding using 
nextafter()");
+}
+
+ATF_TC_BODY(fe_nextafter, tc)
+{
+       double received;
+       int res;
+
+       for (unsigned int i = 0; i < __arraycount(values2); i++) {
+               received = nextafter(values2[i].input, values2[i].toward);
+               if (values2[i].input < values2[i].toward) {
+                       res = (received > values2[i].input);
+               } else {
+                       res = (received < values2[i].input);
+               }
+               ATF_CHECK_MSG(
+                       res && (fabs(received - values2[i].expected) < EPSILON),
+                       "nextafter() rounding wrong, difference too large\n"
+                       "input: %f (index %d): got %f, expected %f, res %d\n",
+                       values2[i].input, i, received, values2[i].expected, 
res);
+       }
*** 1055 LINES SKIPPED ***
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/dev-commits-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to