summaryrefslogtreecommitdiffstats
path: root/tools/regression/lib/msun/test-nearbyint.c
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2013-06-02 04:30:03 +0000
committerdas <das@FreeBSD.org>2013-06-02 04:30:03 +0000
commitc13ee16ab4b2ed670be4b050ae59d428dab4196f (patch)
tree9dcbcaa240ab78a1929ca23098781c6fb4b09726 /tools/regression/lib/msun/test-nearbyint.c
parent44ec97062dafc83b639c425da20387c8c7fb2d8b (diff)
downloadFreeBSD-src-c13ee16ab4b2ed670be4b050ae59d428dab4196f.zip
FreeBSD-src-c13ee16ab4b2ed670be4b050ae59d428dab4196f.tar.gz
Factor out some common code from the libm tests. This is a bit messy
because different tests have different ideas about what it means to be "close enough" to the right answer, depending on the properties of the function being tested. In the process, I fixed some warnings and added a few more 'volatile' hacks, which are sufficient to make all the tests pass at -O2 with clang.
Diffstat (limited to 'tools/regression/lib/msun/test-nearbyint.c')
-rw-r--r--tools/regression/lib/msun/test-nearbyint.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/tools/regression/lib/msun/test-nearbyint.c b/tools/regression/lib/msun/test-nearbyint.c
index 7251acb..602ea2a 100644
--- a/tools/regression/lib/msun/test-nearbyint.c
+++ b/tools/regression/lib/msun/test-nearbyint.c
@@ -40,8 +40,7 @@ __FBSDID("$FreeBSD$");
#include <math.h>
#include <stdio.h>
-#define ALL_STD_EXCEPT (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | \
- FE_OVERFLOW | FE_UNDERFLOW)
+#include "test-utils.h"
static int testnum;
@@ -49,6 +48,14 @@ static const int rmodes[] = {
FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO,
};
+/* Make sure we're testing the library, not some broken compiler built-ins. */
+double (*libnearbyint)(double) = nearbyint;
+float (*libnearbyintf)(float) = nearbyintf;
+long double (*libnearbyintl)(long double) = nearbyintl;
+#define nearbyintf libnearbyintf
+#define nearbyint libnearbyint
+#define nearbyintl libnearbyintl
+
static const struct {
float in;
float out[3]; /* one answer per rounding mode except towardzero */
@@ -64,19 +71,6 @@ static const struct {
static const int ntests = sizeof(tests) / sizeof(tests[0]);
-/*
- * Compare d1 and d2 using special rules: NaN == NaN and +0 != -0.
- * Fail an assertion if they differ.
- */
-static int
-fpequal(long double d1, long double d2)
-{
-
- if (d1 != d2)
- return (isnan(d1) && isnan(d2));
- return (copysignl(1.0, d1) == copysignl(1.0, d2));
-}
-
/* Get the appropriate result for the current rounding mode. */
static float
get_output(int testindex, int rmodeindex, int negative)
@@ -107,7 +101,7 @@ test_nearby(int testindex)
in = tests[testindex].in;
out = get_output(testindex, i, 0);
- assert(fpequal(out, nearbyintf(in)));
+ assert(fpequal(out, libnearbyintf(in)));
assert(fpequal(out, nearbyint(in)));
assert(fpequal(out, nearbyintl(in)));
assert(fetestexcept(ALL_STD_EXCEPT) == 0);
OpenPOWER on IntegriCloud