From: miod Date: Sun, 13 Aug 2023 06:57:04 +0000 (+0000) Subject: Extent the modf() tests; from Willemijn Coene. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=73211dcf3295e091f1cdb414422f1d2225b71af9;p=openbsd Extent the modf() tests; from Willemijn Coene. --- diff --git a/regress/lib/libc/modf/modf_test.c b/regress/lib/libc/modf/modf_test.c index f732533635a..b96618e1f0c 100644 --- a/regress/lib/libc/modf/modf_test.c +++ b/regress/lib/libc/modf/modf_test.c @@ -1,35 +1,67 @@ -/* Public domain, 2014, Tobias Ulmer */ - -/* Test for bug introduced in 4.4BSD modf() on sparc */ +/* $OpenBSD: modf_test.c,v 1.2 2023/08/13 06:57:04 miod Exp $ */ +#include #include +/* Test for bug introduced in 4.4BSD modf() on sparc */ +/* Public domain, 2014, Tobias Ulmer */ + #define BIGFLOAT (5e15) /* Number large enough to trigger the "big" case */ -int -main(void) +void +modf_sparc(void) { double f, i; f = modf(BIGFLOAT, &i); - if (i != BIGFLOAT) - return 1; - if (f != 0.0) - return 1; + assert(i == BIGFLOAT); + assert(f == 0.0); /* Repeat, maybe we were lucky */ f = modf(BIGFLOAT, &i); - if (i != BIGFLOAT) - return 1; - if (f != 0.0) - return 1; + assert(i == BIGFLOAT); + assert(f == 0.0); /* With negative number, for good measure */ f = modf(-BIGFLOAT, &i); - if (i != -BIGFLOAT) - return 1; - if (f != 0.0) - return 1; + assert(i == -BIGFLOAT); + assert(f == 0.0); +} - return 0; +/* Test for modf() behaviour on Inf and Nan */ +/* Written by Willemijn Coene. Public domain */ + +void +modf_infnan(void) +{ + double f, i; + + f = modf(__builtin_inf(), &i); + assert(isinf(i)); + assert(signbit(i) == 0); + assert(f == 0.0); + + f = modf(-__builtin_inf(), &i); + assert(isinf(i)); + assert(signbit(i) != 0); + assert(f == -0.0); + + f = modf(NAN, &i); + assert(isnan(i)); + assert(signbit(i) == 0); + assert(isnan(f)); + assert(signbit(f) == 0); + + f = modf(-NAN, &i); + assert(isnan(i)); + assert(signbit(i) != 0); + assert(isnan(f)); + assert(signbit(f) != 0); +} + +int +main(void) +{ + modf_sparc(); + modf_infnan(); }