1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-05 19:35:52 +03:00
Files
glibc/math/libm-test-compoundn.inc
Joseph Myers ae31254432 Implement C23 compoundn
C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the compoundn functions, which compute (1+X) to the
power Y for integer Y (and X at least -1).  The integer exponent has
type long long int in C23; it was intmax_t in TS 18661-4, and as with
other interfaces changed after their initial appearance in the TS, I
don't think we need to support the original version of the interface.

Note that these functions are "compoundn" with a trailing "n", *not*
"compound" (CORE-MATH has the wrong name, for example).

As with pown, I strongly encourage searching for worst cases for ulps
error for these implementations (necessarily non-exhaustively, given
the size of the input space).  I also expect a custom implementation
for a given format could be much faster as well as more accurate (I
haven't tested or benchmarked the CORE-MATH implementation for
binary32); this is one of the more complicated and less efficient
functions to implement in a type-generic way.

As with exp2m1 and exp10m1, this showed up places where the
powerpc64le IFUNC setup is not as self-contained as one might hope (in
this case, without the changes specific to powerpc64le, there were
undefined references to __GI___expf128).

Tested for x86_64 and x86, and with build-many-glibcs.py.
2025-05-09 15:17:27 +00:00

108 lines
5.7 KiB
SQL

/* Test compoundn.
Copyright (C) 2025 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#include "libm-test-driver.c"
static const struct test_fL_f_data compoundn_test_data[] =
{
TEST_fL_f (compoundn, qnan_value, 0, 1, ERRNO_UNCHANGED),
TEST_fL_f (compoundn, -qnan_value, 0, 1, ERRNO_UNCHANGED),
TEST_fL_f (compoundn, snan_value, 0, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -snan_value, 0, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, plus_infty, 0, 1, ERRNO_UNCHANGED),
TEST_fL_f (compoundn, qnan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, -qnan_value, 1, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, snan_value, 1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -snan_value, 1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, qnan_value, -1, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, -qnan_value, -1, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, snan_value, -1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -snan_value, -1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, qnan_value, 3, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, -qnan_value, 3, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, qnan_value, -3, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, -qnan_value, -3, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, snan_value, 3, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -snan_value, 3, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, snan_value, -3, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -snan_value, -3, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, qnan_value, LLONG_MAX, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, -qnan_value, LLONG_MAX, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, snan_value, LLONG_MAX, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -snan_value, LLONG_MAX, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, qnan_value, LLONG_MIN, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, -qnan_value, LLONG_MIN, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_fL_f (compoundn, snan_value, LLONG_MIN, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -snan_value, LLONG_MIN, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -1.001, 0, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -1.001, 1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -1.001, -1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -1.001, 2, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -1.001, -2, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -1.001, LLONG_MAX, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -1.001, LLONG_MIN, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -max_value, 0, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -max_value, 1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -max_value, -1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -max_value, 2, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -max_value, -2, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -max_value, LLONG_MAX, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -max_value, LLONG_MIN, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, minus_infty, 0, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, minus_infty, 1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, minus_infty, -1, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, minus_infty, 2, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, minus_infty, -2, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, minus_infty, LLONG_MAX, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, minus_infty, LLONG_MIN, qnan_value, INVALID_EXCEPTION),
TEST_fL_f (compoundn, -1.0, -1, plus_infty, DIVIDE_BY_ZERO_EXCEPTION|ERRNO_ERANGE),
TEST_fL_f (compoundn, -1.0, -2, plus_infty, DIVIDE_BY_ZERO_EXCEPTION|ERRNO_ERANGE),
TEST_fL_f (compoundn, -1.0, LLONG_MIN, plus_infty, DIVIDE_BY_ZERO_EXCEPTION|ERRNO_ERANGE),
TEST_fL_f (compoundn, plus_infty, 1, plus_infty, ERRNO_UNCHANGED),
TEST_fL_f (compoundn, plus_infty, 2, plus_infty, ERRNO_UNCHANGED),
TEST_fL_f (compoundn, plus_infty, LLONG_MAX, plus_infty, ERRNO_UNCHANGED),
TEST_fL_f (compoundn, plus_infty, -1, plus_zero, ERRNO_UNCHANGED),
TEST_fL_f (compoundn, plus_infty, -2, plus_zero, ERRNO_UNCHANGED),
TEST_fL_f (compoundn, plus_infty, LLONG_MIN, plus_zero, ERRNO_UNCHANGED),
AUTO_TESTS_fL_f (compoundn),
};
static void
compoundn_test (void)
{
ALL_RM_TEST (compoundn, 0, compoundn_test_data, RUN_TEST_LOOP_fL_f, END);
}
static void
do_test (void)
{
compoundn_test ();
}
/*
* Local Variables:
* mode:c
* End:
*/