1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

Implement C23 atanpi

C23 adds various <math.h> function families originally defined in TS
18661-4.  Add the atanpi functions (atan(x)/pi).

Tested for x86_64 and x86, and with build-many-glibcs.py.
This commit is contained in:
Joseph Myers
2024-12-11 21:51:49 +00:00
parent aec85b2557
commit ffe79c446c
51 changed files with 1832 additions and 2 deletions

View File

@@ -95,6 +95,7 @@ gen-libm-calls = \
k_casinhF \
s_acospiF \
s_asinpiF \
s_atanpiF \
s_cacosF \
s_cacoshF \
s_canonicalizeF \
@@ -626,6 +627,7 @@ libm-test-funcs-auto = \
atan \
atan2 \
atanh \
atanpi \
cabs \
cacos \
cacosh \
@@ -936,6 +938,7 @@ tgmath3-macros = \
atan \
atan2 \
atanh \
atanpi \
carg \
cbrt \
ceil \
@@ -1320,6 +1323,7 @@ CFLAGS-s_asinpi.c += -fno-builtin-asinpil
CFLAGS-s_atan.c += -fno-builtin-atanl
CFLAGS-w_atan2.c += -fno-builtin-atan2l
CFLAGS-w_atanh.c += -fno-builtin-atanhl
CFLAGS-s_atanpi.c += -fno-builtin-atanpil
CFLAGS-s_cabs.c += -fno-builtin-cabsl
CFLAGS-s_cacos.c += -fno-builtin-cacosl
CFLAGS-s_cacosh.c += -fno-builtin-cacoshl
@@ -1463,6 +1467,7 @@ CFLAGS-s_asinpi.c += -fno-builtin-asinpif32x -fno-builtin-asinpif64
CFLAGS-s_atan.c += -fno-builtin-atanf32x -fno-builtin-atanf64
CFLAGS-w_atan2.c += -fno-builtin-atan2f32x -fno-builtin-atan2f64
CFLAGS-w_atanh.c += -fno-builtin-atanhf32x -fno-builtin-atanhf64
CFLAGS-s_atanpi.c += -fno-builtin-atanpif32x -fno-builtin-atanpif64
CFLAGS-s_cabs.c += -fno-builtin-cabsf32x -fno-builtin-cabsf64
CFLAGS-s_cacos.c += -fno-builtin-cacosf32x -fno-builtin-cacosf64
CFLAGS-s_cacosh.c += -fno-builtin-cacoshf32x -fno-builtin-cacoshf64
@@ -1592,6 +1597,7 @@ CFLAGS-s_asinpif.c += -fno-builtin-asinpif32
CFLAGS-s_atanf.c += -fno-builtin-atanf32
CFLAGS-w_atan2f.c += -fno-builtin-atan2f32
CFLAGS-w_atanhf.c += -fno-builtin-atanhf32
CFLAGS-s_atanpif.c += -fno-builtin-atanpif32
CFLAGS-s_cabsf.c += -fno-builtin-cabsf32
CFLAGS-s_cacosf.c += -fno-builtin-cacosf32
CFLAGS-s_cacoshf.c += -fno-builtin-cacoshf32

View File

@@ -657,12 +657,14 @@ libm {
# Functions not involving _Float64x or _Float128, for all configurations.
acospi; acospif; acospil; acospif32; acospif64; acospif32x;
asinpi; asinpif; asinpil; asinpif32; asinpif64; asinpif32x;
atanpi; atanpif; atanpil; atanpif32; atanpif64; atanpif32x;
cospi; cospif; cospil; cospif32; cospif64; cospif32x;
sinpi; sinpif; sinpil; sinpif32; sinpif64; sinpif32x;
tanpi; tanpif; tanpil; tanpif32; tanpif64; tanpif32x;
# Functions involving _Float64x or _Float128, for some configurations.
acospif64x; acospif128;
asinpif64x; asinpif128;
atanpif64x; atanpif128;
cospif64x; cospif128;
sinpif64x; sinpif128;
tanpif64x; tanpif128;

View File

@@ -748,6 +748,46 @@ atanh -min
atanh min_subnorm
atanh -min_subnorm
atanpi 0
atanpi -0
atanpi max
atanpi -max
atanpi 1
atanpi -1
atanpi 0.75
atanpi 0x1p-5
atanpi 0x1p-10
atanpi 0x1p-15
atanpi 0x1p-20
atanpi 0x1p-25
atanpi 0x1p-30
atanpi 0x1p-35
atanpi 0x1p-40
atanpi 0x1p-45
atanpi 0x1p-50
atanpi 0x1p-55
atanpi 0x1p-60
atanpi 2.5
atanpi 10
atanpi 1e6
atanpi 0x1p31
atanpi 0x1p-100
atanpi 0x1p-600
atanpi 0x1p-10000
atanpi -0x3.b02d84p-4
atanpi -0x3.3fb708p-4
atanpi -0x2.3249ap+0
atanpi -0x1.363f46p+0
atanpi -0x1.ad4c0ap+0
atanpi -0x3.eb8e18p+0
atanpi 0x3.53c188p+0
atanpi -0x1.58c83p+0
atanpi 0x1.626772p-1
atanpi min
atanpi -min
atanpi min_subnorm
atanpi -min_subnorm
# cabs (x,y) == cabs (y,x).
cabs 0.75 12.390625
# cabs (x,y) == cabs (-x,y).

File diff suppressed because it is too large Load Diff

View File

@@ -70,6 +70,8 @@ __MATHCALL_VEC (tan,, (_Mdouble_ __x));
__MATHCALL (acospi,, (_Mdouble_ __x));
/* Arc sine of X, divided by pi. */
__MATHCALL (asinpi,, (_Mdouble_ __x));
/* Arc tangent of X, divided by pi. */
__MATHCALL (atanpi,, (_Mdouble_ __x));
/* Cosine of pi * X. */
__MATHCALL (cospi,, (_Mdouble_ __x));

View File

@@ -539,6 +539,7 @@ static test_function test_functions[] =
FUNC_mpfr_f_f ("atan", mpfr_atan, false),
FUNC_mpfr_ff_f ("atan2", mpfr_atan2, false),
FUNC_mpfr_f_f ("atanh", mpfr_atanh, false),
FUNC_mpfr_f_f ("atanpi", mpfr_atanpi, false),
FUNC_mpc_c_f ("cabs", mpc_abs, false),
FUNC_mpc_c_c ("cacos", mpc_acos, false),
FUNC_mpc_c_c ("cacosh", mpc_acosh, false),

View File

@@ -744,6 +744,7 @@ class Tests(object):
# TS 18661-4 functions.
self.add_tests('acospi', 'r', ['r'])
self.add_tests('asinpi', 'r', ['r'])
self.add_tests('atanpi', 'r', ['r'])
self.add_tests('cospi', 'r', ['r'])
self.add_tests('exp10', 'r', ['r'])
self.add_tests('exp2m1', 'r', ['r'])

49
math/libm-test-atanpi.inc Normal file
View File

@@ -0,0 +1,49 @@
/* Test atanpi.
Copyright (C) 2024 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_f_f_data atanpi_test_data[] =
{
TEST_f_f (atanpi, plus_infty, 0.5, ERRNO_UNCHANGED),
TEST_f_f (atanpi, minus_infty, -0.5, ERRNO_UNCHANGED),
TEST_f_f (atanpi, qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_f_f (atanpi, -qnan_value, qnan_value, NO_INEXACT_EXCEPTION|ERRNO_UNCHANGED),
TEST_f_f (atanpi, snan_value, qnan_value, INVALID_EXCEPTION),
TEST_f_f (atanpi, -snan_value, qnan_value, INVALID_EXCEPTION),
AUTO_TESTS_f_f (atanpi),
};
static void
atanpi_test (void)
{
ALL_RM_TEST (atanpi, 0, atanpi_test_data, RUN_TEST_LOOP_f_f, END);
}
static void
do_test (void)
{
atanpi_test ();
}
/*
* Local Variables:
* mode:c
* End:
*/

39
math/s_atanpi_template.c Normal file
View File

@@ -0,0 +1,39 @@
/* Return arc tangent of X, divided by pi.
Copyright (C) 2024 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 <errno.h>
#include <math.h>
#include <math-narrow-eval.h>
#include <math-underflow.h>
FLOAT
M_DECL_FUNC (__atanpi) (FLOAT x)
{
FLOAT ret = math_narrow_eval (M_SUF (__atan) (x) / M_MLIT (M_PI));
if (__glibc_likely (!isnan (x)))
math_check_force_underflow (ret);
if (x != 0 && ret == 0)
__set_errno (ERANGE);
/* Ensure that rounding away from zero for both atan and the
division cannot yield a return value from atanpi with absolute
value greater than 0.5. */
return (isgreater (M_FABS (ret), M_LIT (0.5))
? M_COPYSIGN (M_LIT (0.5), ret)
: ret);
}
declare_mgen_alias (__atanpi, atanpi);

View File

@@ -48,7 +48,7 @@ volatile int count_cdouble;
volatile int count_cfloat;
volatile int count_cldouble;
#define NCALLS 178
#define NCALLS 180
#define NCALLS_INT 4
#define NCCALLS 47
@@ -241,6 +241,7 @@ F(compile_test) (void)
b = asin (asin (a));
a = tan (tan (x));
b = tanpi (tanpi (x));
b = atanpi (atanpi (a));
b = atan (atan (a));
c = atan2 (atan2 (a, c), atan2 (b, x));
a = cosh (cosh (x));
@@ -365,6 +366,7 @@ F(compile_test) (void)
a = tan (y);
a = tanpi (y);
a = atan (y);
a = atanpi (y);
a = atan2 (y, y);
a = cosh (y);
a = acosh (y);
@@ -565,6 +567,14 @@ TYPE
return x + y;
}
TYPE
(F(atanpi)) (TYPE x)
{
++count;
P ();
return x;
}
TYPE
(F(cosh)) (TYPE x)
{

View File

@@ -822,6 +822,8 @@
# define acospi(Val) __TGMATH_UNARY_REAL_ONLY (Val, acospi)
/* Arc sine of X, divided by pi.. */
# define asinpi(Val) __TGMATH_UNARY_REAL_ONLY (Val, asinpi)
/* Arc tangent of X, divided by pi. */
# define atanpi(Val) __TGMATH_UNARY_REAL_ONLY (Val, atanpi)
/* Cosine of pi * X. */
# define cospi(Val) __TGMATH_UNARY_REAL_ONLY (Val, cospi)