Add modff()/modfl() inf/nan tests; from Willemijn Coene.
authormiod <miod@openbsd.org>
Sun, 13 Aug 2023 07:02:36 +0000 (07:02 +0000)
committermiod <miod@openbsd.org>
Sun, 13 Aug 2023 07:02:36 +0000 (07:02 +0000)
regress/lib/libm/Makefile
regress/lib/libm/modf/Makefile [new file with mode: 0644]
regress/lib/libm/modf/modf_test.c [new file with mode: 0644]

index feac435..c826d86 100644 (file)
@@ -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 (file)
index 0000000..aa6e5fd
--- /dev/null
@@ -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 (file)
index 0000000..7deb745
--- /dev/null
@@ -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();
+}