From 7996def3f3aace53c526435fecf37a7bd141e043 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 16 Apr 2024 14:58:57 +0200 Subject: [PATCH] setpayloadl: Add tests. * tests/test-setpayloadl.c: New file. * modules/setpayloadl-tests: New file. --- ChangeLog | 4 ++ modules/setpayloadl-tests | 15 ++++++ tests/test-setpayloadl.c | 97 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 116 insertions(+) create mode 100644 modules/setpayloadl-tests create mode 100644 tests/test-setpayloadl.c diff --git a/ChangeLog b/ChangeLog index baa0043a46..b14171a863 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2024-04-16 Bruno Haible + setpayloadl: Add tests. + * tests/test-setpayloadl.c: New file. + * modules/setpayloadl-tests: New file. + setpayloadl: New module. * lib/math.in.h (setpayloadl): New declaration. * lib/setpayloadl.c: New file. diff --git a/modules/setpayloadl-tests b/modules/setpayloadl-tests new file mode 100644 index 0000000000..3b05d04a53 --- /dev/null +++ b/modules/setpayloadl-tests @@ -0,0 +1,15 @@ +Files: +tests/test-setpayloadl.c +tests/infinity.h +tests/signature.h +tests/macros.h + +Depends-on: +isnanl-nolibm + +configure.ac: + +Makefile.am: +TESTS += test-setpayloadl +check_PROGRAMS += test-setpayloadl +test_setpayloadl_LDADD = $(LDADD) @SETPAYLOADL_LIBM@ diff --git a/tests/test-setpayloadl.c b/tests/test-setpayloadl.c new file mode 100644 index 0000000000..86139a5247 --- /dev/null +++ b/tests/test-setpayloadl.c @@ -0,0 +1,97 @@ +/* Test setpayloadl. + Copyright 2024 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include "signature.h" +SIGNATURE_CHECK (setpayloadl, int, (long double *, long double)); + +#include + +#include "infinity.h" +#include "isnanl-nolibm.h" +#include "macros.h" + +#if defined __powerpc__ && LDBL_MANT_DIG == 106 + /* This is PowerPC "double double", a pair of two doubles. NaN is represented + as the corresponding 64-bit IEEE value in the first double; the second is + irrelevant and therefore does not contain a payload. */ +# define PAYLOAD_BITS (DBL_MANT_DIG - 2) +#else +# define PAYLOAD_BITS (LDBL_MANT_DIG - 2) +#endif + +int +main () +{ + int i; + long double p; + + { + /* Test valid payloads. */ + for (i = 0, p = 1.0L; i < PAYLOAD_BITS; i++, p *= 2.0L) + { + int ret; + long double x; + + ret = setpayloadl (&x, p); + ASSERT (ret == 0); + ASSERT (isnanl (x)); + } + /* Test out-of-range payload. */ + int ret; + long double x; + + ret = setpayloadl (&x, p); + ASSERT (ret != 0); + ASSERT (x == 0.0L); + } + + /* Test infinite payload. */ + { + int ret; + long double x; + + ret = setpayloadl (&x, Infinityl ()); + ASSERT (ret != 0); + ASSERT (x == 0.0L); + } + + /* Test negative payload. */ + { + int ret; + long double x; + + ret = setpayloadl (&x, -1.0L); + ASSERT (ret != 0); + ASSERT (x == 0.0L); + } + + /* Test fractional payload. */ + { + int ret; + long double x; + + ret = setpayloadl (&x, 1.4L); + ASSERT (ret != 0); + ASSERT (x == 0.0L); + } + + return 0; +} -- 2.39.5