Module Name: src Committed By: riastradh Date: Mon May 6 18:41:23 UTC 2024
Modified Files: src/tests/lib/libm: t_bit.c Log Message: tests/lib/libm/t_bit: Expand and tidy. 1. Instead of calling out VAX by name, use #ifdef NAN. 2. Verify signbit works on long double on all architectures, not just those with __HAVE_LONG_DOUBLE which means long double is _larger_ than double. 3. Minor formatting tidying. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/tests/lib/libm/t_bit.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libm/t_bit.c diff -u src/tests/lib/libm/t_bit.c:1.1 src/tests/lib/libm/t_bit.c:1.2 --- src/tests/lib/libm/t_bit.c:1.1 Fri Apr 26 08:52:16 2019 +++ src/tests/lib/libm/t_bit.c Mon May 6 18:41:23 2024 @@ -1,4 +1,4 @@ -/* $NetBSD: t_bit.c,v 1.1 2019/04/26 08:52:16 maya Exp $ */ +/* $NetBSD: t_bit.c,v 1.2 2024/05/06 18:41:23 riastradh Exp $ */ /* * Written by Maya Rashish <m...@netbsd.org> @@ -7,6 +7,9 @@ * Testing signbit{,f,l} function correctly */ +#include <sys/cdefs.h> +__RCSID("$NetBSD: t_bit.c,v 1.2 2024/05/06 18:41:23 riastradh Exp $"); + #include <atf-c.h> #include <float.h> #include <math.h> @@ -18,79 +21,85 @@ static const struct { double input; bool is_negative; } values[] = { - { -1, true}, - { -123, true}, - { -123E6, true}, -#ifdef INFINITY - { -INFINITY, true}, - { INFINITY, false}, -#endif - { 123E6, false}, - { 0, false}, - { -FLT_MIN, true}, - { FLT_MIN, false}, - /* + { -1, true }, + { -123, true }, + { -123E6, true }, + { -INFINITY, true }, + { INFINITY, false }, + { 123E6, false }, + { 0, false }, + { -0., true }, + { -FLT_MIN, true }, + { FLT_MIN, false }, + /* * Cannot be accurately represented as float, * but sign should be preserved */ - { DBL_MAX, false}, - { -DBL_MAX, true}, + { DBL_MAX, false }, + { -DBL_MAX, true }, }; -#ifdef __HAVE_LONG_DOUBLE static const struct { long double input; bool is_negative; } ldbl_values[] = { - { -LDBL_MIN, true}, - { LDBL_MIN, false}, - { LDBL_MAX, false}, - { -LDBL_MAX, true}, + { -LDBL_MIN, true }, + { LDBL_MIN, false }, + { LDBL_MAX, false }, + { -LDBL_MAX, true }, }; -#endif ATF_TC(signbit); ATF_TC_HEAD(signbit, tc) { - atf_tc_set_md_var(tc, "descr","Check that signbit functions correctly"); + atf_tc_set_md_var(tc, "descr", + "Check that signbit functions correctly"); } ATF_TC_BODY(signbit, tc) { - double iterator_d; - float iterator_f; + unsigned i; + + for (i = 0; i < __arraycount(values); i++) { + const float iterator_f = values[i].input; + const double iterator_d = values[i].input; + const long double iterator_l = values[i].input; - for (unsigned int i = 0; i < __arraycount(values); i++) { - iterator_d = values[i].input; - iterator_f = (float) values[i].input; - if (signbit(iterator_f) != values[i].is_negative) + if (signbit(iterator_f) != values[i].is_negative) { atf_tc_fail("%s:%d iteration %d signbitf is wrong" - " about the sign of %f", __func__, - __LINE__, i, iterator_f); - if (signbit(iterator_d) != values[i].is_negative) + " about the sign of %f", __func__, __LINE__, i, + iterator_f); + } + if (signbit(iterator_d) != values[i].is_negative) { atf_tc_fail("%s:%d iteration %d signbit is wrong" - "about the sign of %f", __func__, - __LINE__,i, iterator_d); - -#ifdef __HAVE_LONG_DOUBLE - long double iterator_l = values[i].input; - if (signbit(iterator_l) != values[i].is_negative) + "about the sign of %f", __func__, __LINE__, i, + iterator_d); + } + if (signbit(iterator_l) != values[i].is_negative) { atf_tc_fail("%s:%d iteration %d signbitl is wrong" - " about the sign of %Lf", __func__, - __LINE__, i, iterator_l); -#endif + " about the sign of %Lf", __func__, __LINE__, i, + iterator_l); + } } -#ifdef __HAVE_LONG_DOUBLE - for (unsigned int i = 0; i < __arraycount(ldbl_values); i++) { - if (signbit(ldbl_values[i].input) != ldbl_values[i].is_negative) + for (i = 0; i < __arraycount(ldbl_values); i++) { + if (signbit(ldbl_values[i].input) != + ldbl_values[i].is_negative) { atf_tc_fail("%s:%d iteration %d signbitl is" - "wrong about the sign of %Lf", - __func__, __LINE__, i, - ldbl_values[i].input); + "wrong about the sign of %Lf", + __func__, __LINE__, i, + ldbl_values[i].input); + } } -#endif +#ifdef NAN + ATF_CHECK_EQ(signbit(copysignf(NAN, -1)), true); + ATF_CHECK_EQ(signbit(copysignf(NAN, +1)), false); + ATF_CHECK_EQ(signbit(copysign(NAN, -1)), true); + ATF_CHECK_EQ(signbit(copysign(NAN, +1)), false); + ATF_CHECK_EQ(signbit(copysignl(NAN, -1)), true); + ATF_CHECK_EQ(signbit(copysignl(NAN, +1)), false); +#endif } ATF_TP_ADD_TCS(tp)