summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2005-01-11 23:13:36 +0000
committerdas <das@FreeBSD.org>2005-01-11 23:13:36 +0000
commite71d4333110f962b9c9f793836045d984c6080ff (patch)
tree42a2c8903fd3515159ee0af8a7dce5ee26e7ca09 /tools
parent75bc489b6d03d2c16b15aaef653ed2c8c6a75694 (diff)
downloadFreeBSD-src-e71d4333110f962b9c9f793836045d984c6080ff.zip
FreeBSD-src-e71d4333110f962b9c9f793836045d984c6080ff.tar.gz
Regression tests for [l]lrint[f]() and [l]lround[f]().
Diffstat (limited to 'tools')
-rw-r--r--tools/regression/lib/msun/Makefile2
-rw-r--r--tools/regression/lib/msun/test-lrint.c127
-rw-r--r--tools/regression/lib/msun/test-lrint.t10
-rw-r--r--tools/regression/lib/msun/test-lround.c110
-rw-r--r--tools/regression/lib/msun/test-lround.t10
5 files changed, 258 insertions, 1 deletions
diff --git a/tools/regression/lib/msun/Makefile b/tools/regression/lib/msun/Makefile
index dbe44f6..d016986 100644
--- a/tools/regression/lib/msun/Makefile
+++ b/tools/regression/lib/msun/Makefile
@@ -1,6 +1,6 @@
# $FreeBSD$
-TESTS= test-fenv test-ilogb
+TESTS= test-fenv test-ilogb test-lrint test-lround
CFLAGS+= -O0 -lm
ARCH!= uname -m
.if ${ARCH} == "alpha"
diff --git a/tools/regression/lib/msun/test-lrint.c b/tools/regression/lib/msun/test-lrint.c
new file mode 100644
index 0000000..44bcee7
--- /dev/null
+++ b/tools/regression/lib/msun/test-lrint.c
@@ -0,0 +1,127 @@
+/*-
+ * Copyright (c) 2005 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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 AUTHOR 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 AUTHOR 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 for lrint(), lrintf(), llrint(), and llrintf().
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <assert.h>
+#include <fenv.h>
+#include <limits.h>
+#include <math.h>
+#include <stdio.h>
+
+#define test(func, x, result, excepts) do { \
+ assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
+ assert((func)(x) == (result) || fetestexcept(FE_INVALID)); \
+ assert(fetestexcept(FE_ALL_EXCEPT) == (excepts)); \
+} while (0)
+
+#define testall(x, result, excepts) do { \
+ test(lrint, x, result, excepts); \
+ test(lrintf, x, result, excepts); \
+ test(llrint, x, result, excepts); \
+ test(llrintf, x, result, excepts); \
+} while (0)
+
+#define IGNORE 0
+
+#pragma STDC FENV_ACCESS ON
+
+int
+main(int argc, char *argv[])
+{
+
+ printf("1..1\n");
+
+ assert(fesetround(FE_DOWNWARD) == 0);
+ testall(0.75, 0, FE_INEXACT);
+ testall(-0.5, -1, FE_INEXACT);
+
+ assert(fesetround(FE_TONEAREST) == 0);
+ testall(0.0, 0, 0);
+ testall(0.25, 0, FE_INEXACT);
+ testall(0.5, 0, FE_INEXACT);
+ testall(-2.5, -2, FE_INEXACT);
+ testall(1.0, 1, 0);
+ testall(0x12345000p0, 0x12345000, 0);
+ testall(0x1234.fp0, 0x1235, FE_INEXACT);
+ testall(INFINITY, IGNORE, FE_INVALID);
+ testall(NAN, IGNORE, FE_INVALID);
+
+#if (LONG_MAX == 0x7fffffffl)
+ assert(fesetround(FE_UPWARD) == 0);
+ test(lrint, 0x7fffffff.8p0, IGNORE, FE_INVALID);
+ test(lrint, -0x80000000.4p0, -0x80000000l, FE_INEXACT);
+
+ assert(fesetround(FE_DOWNWARD) == 0);
+ test(lrint, -0x80000000.8p0, IGNORE, FE_INVALID);
+ test(lrint, 0x80000000.0p0, IGNORE, FE_INVALID);
+ test(lrint, 0x7fffffff.4p0, 0x7fffffffl, FE_INEXACT);
+ test(lrintf, 0x80000000.0p0f, IGNORE, FE_INVALID);
+ test(lrintf, 0x7fffff80.0p0f, 0x7fffff80l, 0);
+
+ assert(fesetround(FE_TOWARDZERO) == 0);
+ test(lrint, 0x7fffffff.8p0, 0x7fffffffl, FE_INEXACT);
+ test(lrint, -0x80000000.8p0, -0x80000000l, FE_INEXACT);
+ test(lrint, 0x80000000.0p0, IGNORE, FE_INVALID);
+ test(lrintf, 0x80000000.0p0f, IGNORE, FE_INVALID);
+ test(lrintf, 0x7fffff80.0p0f, 0x7fffff80l, 0);
+#elif (LONG_MAX == 0x7fffffffffffffffll)
+ assert(fesetround(FE_TONEAREST) == 0);
+ test(lrint, 0x8000000000000000.0p0, IGNORE, FE_INVALID);
+ test(lrintf, 0x8000000000000000.0p0f, IGNORE, FE_INVALID);
+ test(lrint, 0x7ffffffffffffc00.0p0, 0x7ffffffffffffc00l, 0);
+ test(lrintf, 0x7fffff8000000000.0p0f, 0x7fffff8000000000l, 0);
+ test(lrint, -0x8000000000000800.0p0, IGNORE, FE_INVALID);
+ test(lrintf, -0x8000010000000000.0p0f, IGNORE, FE_INVALID);
+ test(lrint, -0x8000000000000000.0p0, -0x8000000000000000l, 0);
+ test(lrintf, -0x8000000000000000.0p0f, -0x8000000000000000l, 0);
+#else
+#error "Unsupported long size"
+#endif
+
+#if (LLONG_MAX == 0x7fffffffffffffffLL)
+ assert(fesetround(FE_TONEAREST) == 0);
+ test(llrint, 0x8000000000000000.0p0, IGNORE, FE_INVALID);
+ test(llrintf, 0x8000000000000000.0p0f, IGNORE, FE_INVALID);
+ test(llrint, 0x7ffffffffffffc00.0p0, 0x7ffffffffffffc00ll, 0);
+ test(llrintf, 0x7fffff8000000000.0p0f, 0x7fffff8000000000ll, 0);
+ test(llrint, -0x8000000000000800.0p0, IGNORE, FE_INVALID);
+ test(llrintf, -0x8000010000000000.0p0f, IGNORE, FE_INVALID);
+ test(llrint, -0x8000000000000000.0p0, -0x8000000000000000ll, 0);
+ test(llrintf, -0x8000000000000000.0p0f, -0x8000000000000000ll, 0);
+#else
+#error "Unsupported long long size"
+#endif
+
+ printf("ok 1 - lrint\n");
+
+ return (0);
+}
diff --git a/tools/regression/lib/msun/test-lrint.t b/tools/regression/lib/msun/test-lrint.t
new file mode 100644
index 0000000..8bdfd03
--- /dev/null
+++ b/tools/regression/lib/msun/test-lrint.t
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD$
+
+cd `dirname $0`
+
+executable=`basename $0 .t`
+
+make $executable 2>&1 > /dev/null
+
+exec ./$executable
diff --git a/tools/regression/lib/msun/test-lround.c b/tools/regression/lib/msun/test-lround.c
new file mode 100644
index 0000000..4904abe
--- /dev/null
+++ b/tools/regression/lib/msun/test-lround.c
@@ -0,0 +1,110 @@
+/*-
+ * Copyright (c) 2005 David Schultz <das@FreeBSD.org>
+ * All rights reserved.
+ *
+ * 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 AUTHOR 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 AUTHOR 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 for lround(), lroundf(), llround(), and llroundf().
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <assert.h>
+#include <fenv.h>
+#include <limits.h>
+#include <math.h>
+#include <stdio.h>
+
+#define test(func, x, result, excepts) do { \
+ assert(feclearexcept(FE_ALL_EXCEPT) == 0); \
+ assert((func)(x) == (result) || fetestexcept(FE_INVALID)); \
+ assert(fetestexcept(FE_ALL_EXCEPT) == (excepts)); \
+} while (0)
+
+#define testall(x, result, excepts) do { \
+ test(lround, x, result, excepts); \
+ test(lroundf, x, result, excepts); \
+ test(llround, x, result, excepts); \
+ test(llroundf, x, result, excepts); \
+} while (0)
+
+#define IGNORE 0
+
+#pragma STDC FENV_ACCESS ON
+
+int
+main(int argc, char *argv[])
+{
+
+ printf("1..1\n");
+
+ testall(0.0, 0, 0);
+ testall(0.25, 0, FE_INEXACT);
+ testall(0.5, 1, FE_INEXACT);
+ testall(-0.5, -1, FE_INEXACT);
+ testall(1.0, 1, 0);
+ testall(0x12345000p0, 0x12345000, 0);
+ testall(0x1234.fp0, 0x1235, FE_INEXACT);
+ testall(INFINITY, IGNORE, FE_INVALID);
+ testall(NAN, IGNORE, FE_INVALID);
+
+#if (LONG_MAX == 0x7fffffffl)
+ test(lround, 0x7fffffff.8p0, IGNORE, FE_INVALID);
+ test(lround, -0x80000000.8p0, IGNORE, FE_INVALID);
+ test(lround, 0x80000000.0p0, IGNORE, FE_INVALID);
+ test(lround, 0x7fffffff.4p0, 0x7fffffffl, FE_INEXACT);
+ test(lround, -0x80000000.4p0, -0x80000000l, FE_INEXACT);
+ test(lroundf, 0x80000000.0p0f, IGNORE, FE_INVALID);
+ test(lroundf, 0x7fffff80.0p0f, 0x7fffff80l, 0);
+#elif (LONG_MAX == 0x7fffffffffffffffll)
+ test(lround, 0x8000000000000000.0p0, IGNORE, FE_INVALID);
+ test(lroundf, 0x8000000000000000.0p0f, IGNORE, FE_INVALID);
+ test(lround, 0x7ffffffffffffc00.0p0, 0x7ffffffffffffc00l, 0);
+ test(lroundf, 0x7fffff8000000000.0p0f, 0x7fffff8000000000l, 0);
+ test(lround, -0x8000000000000800.0p0, IGNORE, FE_INVALID);
+ test(lroundf, -0x8000010000000000.0p0f, IGNORE, FE_INVALID);
+ test(lround, -0x8000000000000000.0p0, -0x8000000000000000l, 0);
+ test(lroundf, -0x8000000000000000.0p0f, -0x8000000000000000l, 0);
+#else
+#error "Unsupported long size"
+#endif
+
+#if (LLONG_MAX == 0x7fffffffffffffffLL)
+ test(llround, 0x8000000000000000.0p0, IGNORE, FE_INVALID);
+ test(llroundf, 0x8000000000000000.0p0f, IGNORE, FE_INVALID);
+ test(llround, 0x7ffffffffffffc00.0p0, 0x7ffffffffffffc00ll, 0);
+ test(llroundf, 0x7fffff8000000000.0p0f, 0x7fffff8000000000ll, 0);
+ test(llround, -0x8000000000000800.0p0, IGNORE, FE_INVALID);
+ test(llroundf, -0x8000010000000000.0p0f, IGNORE, FE_INVALID);
+ test(llround, -0x8000000000000000.0p0, -0x8000000000000000ll, 0);
+ test(llroundf, -0x8000000000000000.0p0f, -0x8000000000000000ll, 0);
+#else
+#error "Unsupported long long size"
+#endif
+
+ printf("ok 1 - lround\n");
+
+ return (0);
+}
diff --git a/tools/regression/lib/msun/test-lround.t b/tools/regression/lib/msun/test-lround.t
new file mode 100644
index 0000000..8bdfd03
--- /dev/null
+++ b/tools/regression/lib/msun/test-lround.t
@@ -0,0 +1,10 @@
+#!/bin/sh
+# $FreeBSD$
+
+cd `dirname $0`
+
+executable=`basename $0 .t`
+
+make $executable 2>&1 > /dev/null
+
+exec ./$executable
OpenPOWER on IntegriCloud