From: miod Date: Sun, 13 Aug 2023 07:02:36 +0000 (+0000) Subject: Add modff()/modfl() inf/nan tests; from Willemijn Coene. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=3a33360ffe34d766df55e0225e9706e366c93e3a;p=openbsd Add modff()/modfl() inf/nan tests; from Willemijn Coene. --- 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 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 +#include + +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(); +}