summaryrefslogtreecommitdiffstats
path: root/regress/lib/libm
diff options
context:
space:
mode:
authormartynas <martynas@openbsd.org>2011-04-17 10:33:09 +0000
committermartynas <martynas@openbsd.org>2011-04-17 10:33:09 +0000
commit5e239dd5c58ae2eae84993937bd74f1f3f2b543b (patch)
tree277b87dcb830406c57cc1750a1fd98cb5cc2056d /regress/lib/libm
parentTweak the behaviour of boot(8) on hppa. Normal boots now will give you a (diff)
downloadwireguard-openbsd-5e239dd5c58ae2eae84993937bd74f1f3f2b543b.tar.xz
wireguard-openbsd-5e239dd5c58ae2eae84993937bd74f1f3f2b543b.zip
Add tests for {,l,ll}round{,f}. Same tests as for {,l,ll}rint{,f},
except doesn't test rounding modes. Fix pending. Build it with -fno-builtin if you want to test the library functionality--otherwise GCC4 will decide to use its builtins on some platforms.
Diffstat (limited to 'regress/lib/libm')
-rw-r--r--regress/lib/libm/round/Makefile7
-rw-r--r--regress/lib/libm/round/round.c60
2 files changed, 67 insertions, 0 deletions
diff --git a/regress/lib/libm/round/Makefile b/regress/lib/libm/round/Makefile
new file mode 100644
index 00000000000..c2913456f16
--- /dev/null
+++ b/regress/lib/libm/round/Makefile
@@ -0,0 +1,7 @@
+# $OpenBSD: Makefile,v 1.1 2011/04/17 10:33:09 martynas Exp $
+
+PROG=round
+LDADD=-lm
+DPADD=${LIBM}
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libm/round/round.c b/regress/lib/libm/round/round.c
new file mode 100644
index 00000000000..ebc6f9311ee
--- /dev/null
+++ b/regress/lib/libm/round/round.c
@@ -0,0 +1,60 @@
+/* $OpenBSD: round.c,v 1.1 2011/04/17 10:33:09 martynas Exp $ */
+
+/* Written by Michael Shalayeff, 2003, Public domain. */
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <unistd.h>
+#include <math.h>
+#include <ieeefp.h>
+
+static void
+sigfpe(int sig, siginfo_t *si, void *v)
+{
+ char buf[132];
+
+ if (si) {
+ snprintf(buf, sizeof(buf), "sigfpe: addr=%p, code=%d\n",
+ si->si_addr, si->si_code);
+ write(1, buf, strlen(buf));
+ }
+ _exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ struct sigaction sa;
+
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_sigaction = sigfpe;
+ sa.sa_flags = SA_SIGINFO;
+ sigaction(SIGFPE, &sa, NULL);
+
+ assert(round(8.6) == 9.);
+ assert(roundf(8.6F) == 9);
+ assert(lround(8.6) == 9L);
+ assert(lroundf(8.6F) == 9L);
+ assert(llround(8.6) == 9LL);
+ assert(llroundf(8.6F) == 9LL);
+
+ assert(lround(0.0) == 0L);
+ assert(lroundf(0.0) == 0L);
+ assert(lround(-0.0) == 0L);
+ assert(lroundf(-0.0) == 0L);
+
+ assert(llround(4503599627370496.0) == 4503599627370496LL);
+ assert(llroundf(4503599627370496.0F) == 4503599627370496LL);
+ assert(llround(-4503599627370496.0) == -4503599627370496LL);
+ assert(llroundf(-4503599627370496.0F) == -4503599627370496LL);
+
+ assert(llround(0x7ffffffffffffc00.0p0) == 0x7ffffffffffffc00LL);
+ assert(llroundf(0x7fffff8000000000.0p0F) == 0x7fffff8000000000LL);
+ assert(llround(-0x8000000000000000.0p0) == -0x8000000000000000LL);
+ assert(llroundf(-0x8000000000000000.0p0F) == -0x8000000000000000LL);
+
+ exit(0);
+}