Module Name:    src
Committed By:   riastradh
Date:           Thu May  9 12:18:28 UTC 2024

Modified Files:
        src/tests/lib/libm: t_fe_round.c

Log Message:
tests/lib/libm/t_fe_round.c: Tidy.

nextafter/nexttoward tests didn't make much sense, and are now
supplanted by t_next.

PR misc/58054


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/tests/lib/libm/t_fe_round.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/lib/libm/t_fe_round.c
diff -u src/tests/lib/libm/t_fe_round.c:1.18 src/tests/lib/libm/t_fe_round.c:1.19
--- src/tests/lib/libm/t_fe_round.c:1.18	Wed May  8 22:59:07 2024
+++ src/tests/lib/libm/t_fe_round.c	Thu May  9 12:18:28 2024
@@ -1,3 +1,5 @@
+/*	$NetBSD: t_fe_round.c,v 1.19 2024/05/09 12:18:28 riastradh Exp $	*/
+
 /*
  * Written by Maya Rashish <m...@netbsd.org>
  * Public domain.
@@ -5,20 +7,22 @@
  * Testing IEEE-754 rounding modes (and lrint)
  */
 
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_fe_round.c,v 1.19 2024/05/09 12:18:28 riastradh Exp $");
+
 #include <atf-c.h>
 #include <fenv.h>
-#ifdef __HAVE_FENV
 #include <math.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 
+#ifdef __HAVE_FENV
+
 /*#pragma STDC FENV_ACCESS ON gcc?? */
 
 #define INT 9223L
 
-#define EPSILON 0.001
-
 static const char *
 rmname(int rm)
 {
@@ -36,6 +40,13 @@ rmname(int rm)
 	}
 }
 
+/*
+ * Examples are chosen to fit within the smallest single-precision
+ * format any NetBSD port uses, so that we can write the examples once
+ * in type double, and convert to single without raising inexact-result
+ * exceptions when we're trying to test whether the integer-rounding
+ * functions raise them.
+ */
 static const struct {
 	int round_mode;
 	double input;
@@ -44,15 +55,13 @@ static const struct {
 	{ FE_DOWNWARD,		3.75,		3},
 	{ FE_DOWNWARD,		-3.75,		-4},
 	{ FE_DOWNWARD,		+0.,		0},
+	{ FE_DOWNWARD,		-0.,		0},
 	{ FE_DOWNWARD,		-INT-0.0625,	-INT-1},
 	{ FE_DOWNWARD,		+INT-0.0625,	INT-1},
 	{ FE_DOWNWARD,		-INT+0.0625,	-INT},
 	{ FE_DOWNWARD,		+INT+0.0625,	INT},
-#if 0 /* cpu bugs? */
-	{ FE_DOWNWARD,		-0.,		-1},
 
-	{ FE_UPWARD,		+0.,		1},
-#endif
+	{ FE_UPWARD,		+0.,		0},
 	{ FE_UPWARD,		-0.,		0},
 	{ FE_UPWARD,		-123.75,	-123},
 	{ FE_UPWARD,		123.75,		124},
@@ -432,68 +441,7 @@ ATF_TC_BODY(fe_nearbyintl_rintl, tc)
 	}
 }
 
-#endif
-
-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);
-	}
-}
+#endif	/* __HAVE_LONG_DOUBLE */
 
 ATF_TP_ADD_TCS(tp)
 {
@@ -503,71 +451,19 @@ ATF_TP_ADD_TCS(tp)
 #ifdef __HAVE_LONG_DOUBLE
 	ATF_TP_ADD_TC(tp, fe_nearbyintl_rintl);
 #endif
-	ATF_TP_ADD_TC(tp, fe_nextafter);
-	ATF_TP_ADD_TC(tp, fe_nexttoward);
 
 	return atf_no_error();
 }
-#else
-ATF_TC(t_nofe_round);
 
-ATF_TC_HEAD(t_nofe_round, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	    "dummy test case - no fenv.h support");
-}
-
-ATF_TC_BODY(t_nofe_round, tc)
-{
-	atf_tc_skip("no fenv.h support on this architecture");
-}
-
-ATF_TC(t_nofe_nearbyint);
-
-ATF_TC_HEAD(t_nofe_nearbyint, tc)
-{
-	atf_tc_set_md_var(tc, "descr",
-	    "dummy test case - no fenv.h support");
-}
-
-ATF_TC_BODY(t_nofe_nearbyint, tc)
-{
-	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");
-}
+#else  /* !__HAVE_FENV */
 
 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);
+
+	/*
+	 * No fenv, no fesetround to test.
+	 */
 	return atf_no_error();
 }
 
-#endif
+#endif	/* __HAVE_FENV */

Reply via email to