>From e32e13caaef5f0cf9d6fc47a042251832746b7b7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Wed, 17 Apr 2024 11:03:53 +0200 Subject: [PATCH 4/6] getpayloadf: Add tests. * tests/test-getpayloadf.c: New file. * modules/getpayloadf-tests: New file. --- ChangeLog | 4 ++ modules/getpayloadf-tests | 18 ++++++ tests/test-getpayloadf.c | 112 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 modules/getpayloadf-tests create mode 100644 tests/test-getpayloadf.c diff --git a/ChangeLog b/ChangeLog index 6f97325216..863442a263 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2024-04-17 Bruno Haible + getpayloadf: Add tests. + * tests/test-getpayloadf.c: New file. + * modules/getpayloadf-tests: New file. + getpayloadf: New module. * lib/math.in.h (getpayloadf): New declaration. * lib/getpayloadf.c: New file. diff --git a/modules/getpayloadf-tests b/modules/getpayloadf-tests new file mode 100644 index 0000000000..1901fc43f9 --- /dev/null +++ b/modules/getpayloadf-tests @@ -0,0 +1,18 @@ +Files: +tests/test-getpayloadf.c +tests/minus-zero.h +tests/infinity.h +tests/signature.h +tests/macros.h + +Depends-on: +setpayloadf +setpayloadsigf +signed-snan + +configure.ac: + +Makefile.am: +TESTS += test-getpayloadf +check_PROGRAMS += test-getpayloadf +test_getpayloadf_LDADD = $(LDADD) @GETPAYLOADF_LIBM@ $(SETPAYLOADF_LIBM) $(SETPAYLOADSIGF_LIBM) diff --git a/tests/test-getpayloadf.c b/tests/test-getpayloadf.c new file mode 100644 index 0000000000..f0ec047235 --- /dev/null +++ b/tests/test-getpayloadf.c @@ -0,0 +1,112 @@ +/* Test getpayloadf. + 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 (getpayloadf, float, (const float *)); + +#include "minus-zero.h" +#include "infinity.h" +#include "signed-snan.h" +#include "macros.h" + +#define PAYLOAD_BITS (24 - 2) /* = (FLT_MANT_DIG - 2) */ + +int +main () +{ + float arg; + float ret; + + /* Test non-NaN arguments. */ + + arg = 2.718281828459045f; + ret = getpayloadf (&arg); + ASSERT (ret == -1.0f); + + arg = -3.141592653589793f; + ret = getpayloadf (&arg); + ASSERT (ret == -1.0f); + + arg = 0.0f; + ret = getpayloadf (&arg); + ASSERT (ret == -1.0f); + + arg = minus_zerof; + ret = getpayloadf (&arg); + ASSERT (ret == -1.0f); + + arg = Infinityf (); + ret = getpayloadf (&arg); + ASSERT (ret == -1.0f); + + arg = - Infinityf (); + ret = getpayloadf (&arg); + ASSERT (ret == -1.0f); + + /* Test quiet NaNs. */ + { + int i; + float p; + + for (i = 0, p = 1.0f; i < PAYLOAD_BITS; i++, p *= 2.0f) + { + ASSERT (setpayloadf (&arg, p) == 0); + ret = getpayloadf (&arg); + ASSERT (ret == p); + /* Test quiet NaNs with sign bit == 1. */ + arg = - arg; + ret = getpayloadf (&arg); + ASSERT (ret == p); + } + + p = 2300902.0f; + ASSERT (setpayloadf (&arg, p) == 0); + ret = getpayloadf (&arg); + ASSERT (ret == p); + } + + /* Test signalling NaNs. */ + { + int i; + float p; + + for (i = 0, p = 1.0f; i < PAYLOAD_BITS; i++, p *= 2.0f) + { + ASSERT (setpayloadsigf (&arg, p) == 0); + ret = getpayloadf (&arg); + ASSERT (ret == p); + } + + p = 2300902.0f; + ASSERT (setpayloadsigf (&arg, p) == 0); + ret = getpayloadf (&arg); + ASSERT (ret == p); + + /* Test signalling NaNs with sign bit == 1. */ + memory_float pos_arg = memory_positive_SNaNf (); + memory_float neg_arg = memory_negative_SNaNf (); + float pos_ret = getpayloadf (&pos_arg.value); + float neg_ret = getpayloadf (&neg_arg.value); + ASSERT (neg_ret == pos_ret); + } + + return 0; +} -- 2.34.1