summaryrefslogtreecommitdiff
path: root/regress/lib
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2023-08-13 07:02:37 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2023-08-13 07:02:37 +0000
commit28e8306c08ef6ffecf74fe9178061c9993a882d0 (patch)
tree1e915c3adb82e05e60ced7c540a57dcfcb0ccf03 /regress/lib
parent630fe93b056f640d3551bfae2640a5ceebd28751 (diff)
Add modff()/modfl() inf/nan tests; from Willemijn Coene.
Diffstat (limited to 'regress/lib')
-rw-r--r--regress/lib/libm/Makefile4
-rw-r--r--regress/lib/libm/modf/Makefile5
-rw-r--r--regress/lib/libm/modf/modf_test.c71
3 files changed, 78 insertions, 2 deletions
diff --git a/regress/lib/libm/Makefile b/regress/lib/libm/Makefile
index feac435a8ba..c826d8638bd 100644
--- a/regress/lib/libm/Makefile
+++ b/regress/lib/libm/Makefile
@@ -1,6 +1,6 @@
-# $OpenBSD: Makefile,v 1.15 2019/02/21 16:14:45 bluhm Exp $
+# $OpenBSD: Makefile,v 1.16 2023/08/13 07:02:36 miod Exp $
-SUBDIR+= exp fenv floor fpaccuracy lgamma nextafter msun rint round \
+SUBDIR+= exp fenv floor fpaccuracy lgamma modf msun nextafter rint round \
tgamma toint trivial1
.if defined(REGRESS_FULL) || make(clean) || make(cleandir) || make(obj)
diff --git a/regress/lib/libm/modf/Makefile b/regress/lib/libm/modf/Makefile
new file mode 100644
index 00000000000..aa6e5fd5560
--- /dev/null
+++ b/regress/lib/libm/modf/Makefile
@@ -0,0 +1,5 @@
+PROG=modf_test
+LDADD+= -lm
+DPADD+= ${LIBM}
+
+.include <bsd.regress.mk>
diff --git a/regress/lib/libm/modf/modf_test.c b/regress/lib/libm/modf/modf_test.c
new file mode 100644
index 00000000000..7deb7458401
--- /dev/null
+++ b/regress/lib/libm/modf/modf_test.c
@@ -0,0 +1,71 @@
+/* $OpenBSD: modf_test.c,v 1.1 2023/08/13 07:02:36 miod Exp $ */
+
+/*
+ * Written by Willemijn Coene. Public domain
+ */
+
+#include <assert.h>
+#include <math.h>
+
+void
+modff_infnan(void)
+{
+ float f, i;
+
+ f = modff(__builtin_inff(), &i);
+ assert(isinf(i));
+ assert(signbit(i) == 0);
+ assert(f == 0.0f);
+
+ f = modff(-__builtin_inff(), &i);
+ assert(isinf(i));
+ assert(signbit(i) != 0);
+ assert(f == -0.0f);
+
+ f = modff(NAN, &i);
+ assert(isnan(i));
+ assert(signbit(i) == 0);
+ assert(isnan(f));
+ assert(signbit(f) == 0);
+
+ f = modff(-NAN, &i);
+ assert(isnan(i));
+ assert(signbit(i) != 0);
+ assert(isnan(f));
+ assert(signbit(f) != 0);
+}
+
+void
+modfl_infnan(void)
+{
+ long double f, i;
+
+ f = modfl(__builtin_infl(), &i);
+ assert(isinf(i));
+ assert(signbit(i) == 0);
+ assert(f == 0.0L);
+
+ f = modfl(-__builtin_infl(), &i);
+ assert(isinf(i));
+ assert(signbit(i) != 0);
+ assert(f == -0.0L);
+
+ f = modfl(NAN, &i);
+ assert(isnan(i));
+ assert(signbit(i) == 0);
+ assert(isnan(f));
+ assert(signbit(f) == 0);
+
+ f = modfl(-NAN, &i);
+ assert(isnan(i));
+ assert(signbit(i) != 0);
+ assert(isnan(f));
+ assert(signbit(f) != 0);
+}
+
+int
+main(void)
+{
+ modff_infnan();
+ modfl_infnan();
+}