Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libm Include the subtest number in any error output.



details:   https://anonhg.NetBSD.org/src/rev/4cedd3d76c14
branches:  trunk
changeset: 327244:4cedd3d76c14
user:      dsl <dsl%NetBSD.org@localhost>
date:      Sun Mar 02 22:40:45 2014 +0000

description:
Include the subtest number in any error output.
Also temporarily print the rounding mode.
I think that acos(-1) is ending up with the wrong sign because the test
  is being run with 'round towards -ve infinity' set.
I think it getting set somewhere and causing this test to fail.
The acos() code probably needs fixing - it shouldn't depend on the
round mode like this. But first I want to know if this if the error.

diffstat:

 tests/lib/libm/t_acos.c |  31 +++++++++++++++++--------------
 1 files changed, 17 insertions(+), 14 deletions(-)

diffs (82 lines):

diff -r b060b0d1cf96 -r 4cedd3d76c14 tests/lib/libm/t_acos.c
--- a/tests/lib/libm/t_acos.c   Sun Mar 02 22:22:05 2014 +0000
+++ b/tests/lib/libm/t_acos.c   Sun Mar 02 22:40:45 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_acos.c,v 1.5 2014/03/01 21:08:39 dsl Exp $ */
+/* $NetBSD: t_acos.c,v 1.6 2014/03/02 22:40:45 dsl Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -31,29 +31,32 @@
 
 #include <atf-c.h>
 #include <math.h>
+#include <fenv.h>
 
 /*
  * Check result of fn(arg) is correct within the bounds.
  * Should be ok to do the checks using 'double' for 'float' functions.
  */
-#define T_LIBM_CHECK(fn, arg, expect, epsilon) do { \
+#define T_LIBM_CHECK(subtest, fn, arg, expect, epsilon) do { \
        double r = fn(arg); \
        double e = fabs(r - expect); \
        if (e > epsilon) \
-               atf_tc_fail_nonfatal(#fn "(%g) is %g not %g (error %g > %g)", \
-                       arg, r, expect, e, epsilon); \
+               atf_tc_fail_nonfatal( \
+                   "subtest %zu: " #fn "(%g) is %g not %g (error %g > %g), roundmode %x", \
+                   subtest, arg, r, expect, e, epsilon, fegetround()); \
     } while (0)
 
 /* Check that the result of fn(arg) is NaN */
 #ifndef __vax__
-#define T_LIBM_CHECK_NAN(fn, arg) do { \
+#define T_LIBM_CHECK_NAN(subtest, fn, arg) do { \
        double r = fn(arg); \
        if (!isnan(r)) \
-               atf_tc_fail_nonfatal(#fn "(%g) is %g not NaN", arg, r); \
+               atf_tc_fail_nonfatal("subtest %zu: " #fn "(%g) is %g not NaN", \
+                   subtest, arg, r); \
     } while (0)
 #else
 /* vax doesn't support NaN */
-#define T_LIBM_CHECK_NAN(fn, arg) (void)(arg)
+#define T_LIBM_CHECK_NAN(subtest, fn, arg) (void)(arg)
 #endif
 
 #define AFT_LIBM_TEST(name, description) \
@@ -78,11 +81,11 @@
        size_t i;
 
        for (i = 0; i < __arraycount(x); i++) {
-               T_LIBM_CHECK_NAN(acos, x[i]);
+               T_LIBM_CHECK_NAN(i, acos, x[i]);
                if (i < 2)
                        /* Values are too small for float */
                        continue;
-               T_LIBM_CHECK_NAN(acosf, x[i]);
+               T_LIBM_CHECK_NAN(i, acosf, x[i]);
        }
 }
 
@@ -104,14 +107,14 @@
        size_t i;
 
        /*
-        * Note that acos(x) might be calcualted as atan((1-x*x)/x).
-        * This means that acos(-1) is atan(-0.0), if the sign is lost
-        * the value will be 0 (atan(+0)) not M_PI.
+        * Note that acos(x) might be calculated as atan2(sqrt(1-x*x),x).
+        * This means that acos(-1) is atan2(+0,-1), if the sign is wrong
+        * the value will be -M_PI (atan2(-0,-1)) not M_PI.
         */
 
        for (i = 0; i < __arraycount(values); i++) {
-               T_LIBM_CHECK(acos, values[i].x, values[i].y, 1.0e-15);
-               T_LIBM_CHECK(acosf, values[i].x, values[i].y, 1.0e-5);
+               T_LIBM_CHECK(i, acos, values[i].x, values[i].y, 1.0e-15);
+               T_LIBM_CHECK(i, acosf, values[i].x, values[i].y, 1.0e-5);
        }
 }
 



Home | Main Index | Thread Index | Old Index