Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libm Add test cases for nextafter() and nexttoward...



details:   https://anonhg.NetBSD.org/src/rev/a444f105baf7
branches:  trunk
changeset: 355858:a444f105baf7
user:      he <he%NetBSD.org@localhost>
date:      Thu Aug 17 09:14:28 2017 +0000

description:
Add test cases for nextafter() and nexttoward().  At the moment no
corner cases are tested, and the test cases are little more than a
verification that the functions are present in the implementation.

diffstat:

 tests/lib/libm/t_fe_round.c |  91 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 90 insertions(+), 1 deletions(-)

diffs (125 lines):

diff -r 0361796d29d4 -r a444f105baf7 tests/lib/libm/t_fe_round.c
--- a/tests/lib/libm/t_fe_round.c       Thu Aug 17 09:11:04 2017 +0000
+++ b/tests/lib/libm/t_fe_round.c       Thu Aug 17 09:14:28 2017 +0000
@@ -122,11 +122,74 @@
        }
 }
 
+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);
+       }
+}
+
+ATF_TC(fe_nexttoward);
+ATF_TC_HEAD(fe_nexttoward, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checking IEEE 754 rounding using nexttoward()");
+}
+
+ATF_TC_BODY(fe_nexttoward, tc)
+{
+       double received;
+       int res;
+
+       for (unsigned int i = 0; i < __arraycount(values2); i++) {
+               received = nexttoward(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),
+                       "nexttoward() 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);
+       }
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
        ATF_TP_ADD_TC(tp, fe_round);
        ATF_TP_ADD_TC(tp, fe_nearbyint);
+       ATF_TP_ADD_TC(tp, fe_nextafter);
+       ATF_TP_ADD_TC(tp, fe_nexttoward);
 
        return atf_no_error();
 }
@@ -139,7 +202,6 @@
            "dummy test case - no fenv.h support");
 }
 
-
 ATF_TC_BODY(t_nofe_round, tc)
 {
        atf_tc_skip("no fenv.h support on this architecture");
@@ -158,11 +220,38 @@
        atf_tc_skip("no fenv.h support on this architecture");
 }
 
+ATF_TC(t_nofe_nextafter);
+
+ATF_TC_HEAD(t_nofe_nextafter, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "dummy test case - no fenv.h support");
+}
+
+ATF_TC_BODY(t_nofe_nextafter, tc)
+{
+       atf_tc_skip("no fenv.h support on this architecture");
+}
+
+ATF_TC(t_nofe_nexttoward);
+
+ATF_TC_HEAD(t_nofe_nexttoward, tc)
+{
+       atf_tc_set_md_var(tc, "descr",
+           "dummy test case - no fenv.h support");
+}
+
+ATF_TC_BODY(t_nofe_nexttoward, tc)
+{
+       atf_tc_skip("no fenv.h support on this architecture");
+}
 
 ATF_TP_ADD_TCS(tp)
 {
        ATF_TP_ADD_TC(tp, t_nofe_round);
        ATF_TP_ADD_TC(tp, t_nofe_nearbyint);
+       ATF_TP_ADD_TC(tp, t_nofe_nextafter);
+       ATF_TP_ADD_TC(tp, t_nofe_nexttoward);
        return atf_no_error();
 }
 



Home | Main Index | Thread Index | Old Index