1996-03-05 21:41:30 +00:00
|
|
|
/*
|
2001-03-12 00:04:52 +00:00
|
|
|
* IBM Accurate Mathematical Library
|
2002-07-06 06:36:39 +00:00
|
|
|
* written by International Business Machines Corp.
|
2024-01-01 18:12:26 +00:00
|
|
|
* Copyright (C) 2001-2024 Free Software Foundation, Inc.
|
1996-03-05 21:41:30 +00:00
|
|
|
*
|
2001-03-12 00:04:52 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
2002-08-26 22:40:48 +00:00
|
|
|
* the Free Software Foundation; either version 2.1 of the License, or
|
2001-03-12 00:04:52 +00:00
|
|
|
* (at your option) any later version.
|
1996-03-05 21:41:30 +00:00
|
|
|
*
|
2001-03-12 00:04:52 +00:00
|
|
|
* 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
|
2002-08-20 21:51:55 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
1996-03-05 21:41:30 +00:00
|
|
|
*
|
2001-03-12 00:04:52 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
1996-03-05 21:41:30 +00:00
|
|
|
*/
|
2001-03-12 00:04:52 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* MODULE_NAME: atnat2.c */
|
|
|
|
/* */
|
|
|
|
/* FUNCTIONS: uatan2 */
|
|
|
|
/* signArctan2 */
|
|
|
|
/* */
|
2021-03-10 12:41:20 +00:00
|
|
|
/* FILES NEEDED: dla.h endian.h mydefs.h atnat2.h */
|
2001-03-12 00:04:52 +00:00
|
|
|
/* uatan.tbl */
|
|
|
|
/* */
|
|
|
|
/************************************************************************/
|
|
|
|
|
2011-10-23 16:50:28 +00:00
|
|
|
#include <dla.h>
|
2021-03-10 12:40:26 +00:00
|
|
|
#include "mydefs.h"
|
2001-03-12 00:04:52 +00:00
|
|
|
#include "uatan.tbl"
|
|
|
|
#include "atnat2.h"
|
2015-04-08 17:32:17 +00:00
|
|
|
#include <fenv.h>
|
Fix atan / atan2 missing underflows (bug 15319).
This patch fixes bug 15319, missing underflows from atan / atan2 when
the result of atan is very close to its small argument (or that of
atan2 is very close to the ratio of its arguments, which may be an
exact division).
The usual approach of doing an underflowing computation if the
computed result is subnormal is followed. For 32-bit x86, there are
extra complications: the inline __ieee754_atan2 in bits/mathinline.h
needs to be disabled for float and double because other libm functions
using it generally rely on getting proper underflow exceptions from
it, while the out-of-line functions have to remove excess range and
precision from the underflowing result so as to return an exact 0 in
the case where errno should be set for underflow to 0. (The failures
I saw without that are similar to those Carlos reported for other
functions, where I haven't seen a response to
<https://sourceware.org/ml/libc-alpha/2015-01/msg00485.html>
confirming if my diagnosis is correct. Arguably all libm functions
with float and double returns should remove excess range and
precision, but that's a separate matter.)
The x86_64 long double case reported in a comment in bug 15319 is not
a bug (it's an argument of LDBL_MIN, and x86_64 is an after-rounding
architecture so the correct IEEE result is not to raise underflow in
the given rounding mode, in addition to treating the result as an
exact LDBL_MIN being within the newly clarified documentation of
accuracy goals). I'm presuming that the fpatan instruction can be
trusted to raise appropriate exceptions when the (long double) result
underflows (after rounding) and so no changes are needed for x86 /
x86_64 long double functions here; empirically this is the case for
the cases covered in the testsuite, on my system.
Tested for x86_64, x86, powerpc and mips64. Only 32-bit x86 needs
ulps updates (for the changes to inlines meaning some functions no
longer get excess precision from their __ieee754_atan2* calls).
[BZ #15319]
* sysdeps/i386/fpu/e_atan2.S (dbl_min): New object.
(MO): New macro.
(__ieee754_atan2): For results with small absolute value, force
underflow exception and remove excess range and precision from
return value.
* sysdeps/i386/fpu/e_atan2f.S (flt_min): New object.
(MO): New macro.
(__ieee754_atan2f): For results with small absolute value, force
underflow exception and remove excess range and precision from
return value.
* sysdeps/i386/fpu/s_atan.S (dbl_min): New object.
(MO): New macro.
(__atan): For results with small absolute value, force underflow
exception and remove excess range and precision from return value.
* sysdeps/i386/fpu/s_atanf.S (flt_min): New object.
(MO): New macro.
(__atanf): For results with small absolute value, force underflow
exception and remove excess range and precision from return value.
* sysdeps/ieee754/dbl-64/e_atan2.c: Include <float.h> and
<math.h>.
(__ieee754_atan2): Force underflow exception for results with
small absolute value.
* sysdeps/ieee754/dbl-64/s_atan.c: Include <float.h> and
<math_private.h>.
(atan): Force underflow exception for results with small absolute
value.
* sysdeps/ieee754/flt-32/s_atanf.c: Include <float.h>.
(__atanf): Force underflow exception for results with small
absolute value.
* sysdeps/ieee754/ldbl-128/s_atanl.c: Include <float.h> and
<math.h>.
(__atanl): Force underflow exception for results with small
absolute value.
* sysdeps/ieee754/ldbl-128ibm/s_atanl.c: Include <float.h>.
(__atanl): Force underflow exception for results with small
absolute value.
* sysdeps/x86/fpu/bits/mathinline.h
[!__SSE2_MATH__ && !__x86_64__ && __LIBC_INTERNAL_MATH_INLINES]
(__ieee754_atan2): Only define inline for long double.
* sysdeps/x86_64/fpu/multiarch/e_atan2.c
[HAVE_FMA4_SUPPORT || HAVE_AVX_SUPPORT]: Include <math.h>.
* math/auto-libm-test-in: Do not mark underflow exceptions as
possibly missing for bug 15319. Add more tests of atan2.
* math/auto-libm-test-out: Regenerated.
* math/libm-test.inc (casin_test_data): Do not mark underflow
exceptions as possibly missing for bug 15319.
(casinh_test_data): Likewise.
* sysdeps/i386/fpu/libm-test-ulps: Update.
2015-02-18 21:10:49 +00:00
|
|
|
#include <float.h>
|
|
|
|
#include <math.h>
|
2018-05-11 15:11:38 +00:00
|
|
|
#include <math-barriers.h>
|
2012-03-09 19:29:16 +00:00
|
|
|
#include <math_private.h>
|
Do not include fenv_private.h in math_private.h.
Continuing the clean-up related to the catch-all math_private.h
header, this patch stops math_private.h from including fenv_private.h.
Instead, fenv_private.h is included directly from those users of
math_private.h that also used interfaces from fenv_private.h. No
attempt is made to remove unused includes of math_private.h, but that
is a natural followup.
(However, since math_private.h sometimes defines optimized versions of
math.h interfaces or __* variants thereof, as well as defining its own
interfaces, I think it might make sense to get all those optimized
versions included from include/math.h, not requiring a separate header
at all, before eliminating unused math_private.h includes - that
avoids a file quietly becoming less-optimized if someone adds a call
to one of those interfaces without restoring a math_private.h include
to that file.)
There is still a pitfall that if code uses plain fe* and __fe*
interfaces, but only includes fenv.h and not fenv_private.h or (before
this patch) math_private.h, it will compile on platforms with
exceptions and rounding modes but not get the optimized versions (and
possibly not compile) on platforms without exception and rounding mode
support, so making it easy to break the build for such platforms
accidentally.
I think it would be most natural to move the inlines / macros for fe*
and __fe* in the case of no exceptions and rounding modes into
include/fenv.h, so that all code including fenv.h with _ISOMAC not
defined automatically gets them. Then fenv_private.h would be purely
the header for the libc_fe*, SET_RESTORE_ROUND etc. internal
interfaces and the risk of breaking the build on other platforms than
the one you tested on because of a missing fenv_private.h include
would be much reduced (and there would be some unused fenv_private.h
includes to remove along with unused math_private.h includes).
Tested for x86_64 and x86, and tested with build-many-glibcs.py that
installed stripped shared libraries are unchanged by this patch.
* sysdeps/generic/math_private.h: Do not include <fenv_private.h>.
* math/fromfp.h: Include <fenv_private.h>.
* math/math-narrow.h: Likewise.
* math/s_cexp_template.c: Likewise.
* math/s_csin_template.c: Likewise.
* math/s_csinh_template.c: Likewise.
* math/s_ctan_template.c: Likewise.
* math/s_ctanh_template.c: Likewise.
* math/s_iseqsig_template.c: Likewise.
* math/w_acos_compat.c: Likewise.
* math/w_acosf_compat.c: Likewise.
* math/w_acosl_compat.c: Likewise.
* math/w_asin_compat.c: Likewise.
* math/w_asinf_compat.c: Likewise.
* math/w_asinl_compat.c: Likewise.
* math/w_ilogb_template.c: Likewise.
* math/w_j0_compat.c: Likewise.
* math/w_j0f_compat.c: Likewise.
* math/w_j0l_compat.c: Likewise.
* math/w_j1_compat.c: Likewise.
* math/w_j1f_compat.c: Likewise.
* math/w_j1l_compat.c: Likewise.
* math/w_jn_compat.c: Likewise.
* math/w_jnf_compat.c: Likewise.
* math/w_llogb_template.c: Likewise.
* math/w_log10_compat.c: Likewise.
* math/w_log10f_compat.c: Likewise.
* math/w_log10l_compat.c: Likewise.
* math/w_log2_compat.c: Likewise.
* math/w_log2f_compat.c: Likewise.
* math/w_log2l_compat.c: Likewise.
* math/w_log_compat.c: Likewise.
* math/w_logf_compat.c: Likewise.
* math/w_logl_compat.c: Likewise.
* sysdeps/aarch64/fpu/feholdexcpt.c: Likewise.
* sysdeps/aarch64/fpu/fesetround.c: Likewise.
* sysdeps/aarch64/fpu/fgetexcptflg.c: Likewise.
* sysdeps/aarch64/fpu/ftestexcept.c: Likewise.
* sysdeps/ieee754/dbl-64/e_atan2.c: Likewise.
* sysdeps/ieee754/dbl-64/e_exp.c: Likewise.
* sysdeps/ieee754/dbl-64/e_exp2.c: Likewise.
* sysdeps/ieee754/dbl-64/e_gamma_r.c: Likewise.
* sysdeps/ieee754/dbl-64/e_jn.c: Likewise.
* sysdeps/ieee754/dbl-64/e_pow.c: Likewise.
* sysdeps/ieee754/dbl-64/e_remainder.c: Likewise.
* sysdeps/ieee754/dbl-64/e_sqrt.c: Likewise.
* sysdeps/ieee754/dbl-64/gamma_product.c: Likewise.
* sysdeps/ieee754/dbl-64/lgamma_neg.c: Likewise.
* sysdeps/ieee754/dbl-64/s_atan.c: Likewise.
* sysdeps/ieee754/dbl-64/s_fma.c: Likewise.
* sysdeps/ieee754/dbl-64/s_fmaf.c: Likewise.
* sysdeps/ieee754/dbl-64/s_llrint.c: Likewise.
* sysdeps/ieee754/dbl-64/s_llround.c: Likewise.
* sysdeps/ieee754/dbl-64/s_lrint.c: Likewise.
* sysdeps/ieee754/dbl-64/s_lround.c: Likewise.
* sysdeps/ieee754/dbl-64/s_nearbyint.c: Likewise.
* sysdeps/ieee754/dbl-64/s_sin.c: Likewise.
* sysdeps/ieee754/dbl-64/s_sincos.c: Likewise.
* sysdeps/ieee754/dbl-64/s_tan.c: Likewise.
* sysdeps/ieee754/dbl-64/wordsize-64/s_lround.c: Likewise.
* sysdeps/ieee754/dbl-64/wordsize-64/s_nearbyint.c: Likewise.
* sysdeps/ieee754/dbl-64/x2y2m1.c: Likewise.
* sysdeps/ieee754/float128/float128_private.h: Likewise.
* sysdeps/ieee754/flt-32/e_gammaf_r.c: Likewise.
* sysdeps/ieee754/flt-32/e_j1f.c: Likewise.
* sysdeps/ieee754/flt-32/e_jnf.c: Likewise.
* sysdeps/ieee754/flt-32/lgamma_negf.c: Likewise.
* sysdeps/ieee754/flt-32/s_llrintf.c: Likewise.
* sysdeps/ieee754/flt-32/s_llroundf.c: Likewise.
* sysdeps/ieee754/flt-32/s_lrintf.c: Likewise.
* sysdeps/ieee754/flt-32/s_lroundf.c: Likewise.
* sysdeps/ieee754/flt-32/s_nearbyintf.c: Likewise.
* sysdeps/ieee754/k_standardl.c: Likewise.
* sysdeps/ieee754/ldbl-128/e_expl.c: Likewise.
* sysdeps/ieee754/ldbl-128/e_gammal_r.c: Likewise.
* sysdeps/ieee754/ldbl-128/e_j1l.c: Likewise.
* sysdeps/ieee754/ldbl-128/e_jnl.c: Likewise.
* sysdeps/ieee754/ldbl-128/gamma_productl.c: Likewise.
* sysdeps/ieee754/ldbl-128/lgamma_negl.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_fmal.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_llrintl.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_llroundl.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_lrintl.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_lroundl.c: Likewise.
* sysdeps/ieee754/ldbl-128/s_nearbyintl.c: Likewise.
* sysdeps/ieee754/ldbl-128/x2y2m1l.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/e_expl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/e_gammal_r.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/e_j1l.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/e_jnl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/lgamma_negl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_fmal.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_llrintl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_llroundl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_lrintl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_lroundl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/s_rintl.c: Likewise.
* sysdeps/ieee754/ldbl-128ibm/x2y2m1l.c: Likewise.
* sysdeps/ieee754/ldbl-96/e_gammal_r.c: Likewise.
* sysdeps/ieee754/ldbl-96/e_jnl.c: Likewise.
* sysdeps/ieee754/ldbl-96/gamma_productl.c: Likewise.
* sysdeps/ieee754/ldbl-96/lgamma_negl.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_fma.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_fmal.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_llrintl.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_llroundl.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_lrintl.c: Likewise.
* sysdeps/ieee754/ldbl-96/s_lroundl.c: Likewise.
* sysdeps/ieee754/ldbl-96/x2y2m1l.c: Likewise.
* sysdeps/powerpc/fpu/e_sqrt.c: Likewise.
* sysdeps/powerpc/fpu/e_sqrtf.c: Likewise.
* sysdeps/riscv/rv64/rvd/s_ceil.c: Likewise.
* sysdeps/riscv/rv64/rvd/s_floor.c: Likewise.
* sysdeps/riscv/rv64/rvd/s_nearbyint.c: Likewise.
* sysdeps/riscv/rv64/rvd/s_round.c: Likewise.
* sysdeps/riscv/rv64/rvd/s_roundeven.c: Likewise.
* sysdeps/riscv/rv64/rvd/s_trunc.c: Likewise.
* sysdeps/riscv/rvd/s_finite.c: Likewise.
* sysdeps/riscv/rvd/s_fmax.c: Likewise.
* sysdeps/riscv/rvd/s_fmin.c: Likewise.
* sysdeps/riscv/rvd/s_fpclassify.c: Likewise.
* sysdeps/riscv/rvd/s_isinf.c: Likewise.
* sysdeps/riscv/rvd/s_isnan.c: Likewise.
* sysdeps/riscv/rvd/s_issignaling.c: Likewise.
* sysdeps/riscv/rvf/fegetround.c: Likewise.
* sysdeps/riscv/rvf/feholdexcpt.c: Likewise.
* sysdeps/riscv/rvf/fesetenv.c: Likewise.
* sysdeps/riscv/rvf/fesetround.c: Likewise.
* sysdeps/riscv/rvf/feupdateenv.c: Likewise.
* sysdeps/riscv/rvf/fgetexcptflg.c: Likewise.
* sysdeps/riscv/rvf/ftestexcept.c: Likewise.
* sysdeps/riscv/rvf/s_ceilf.c: Likewise.
* sysdeps/riscv/rvf/s_finitef.c: Likewise.
* sysdeps/riscv/rvf/s_floorf.c: Likewise.
* sysdeps/riscv/rvf/s_fmaxf.c: Likewise.
* sysdeps/riscv/rvf/s_fminf.c: Likewise.
* sysdeps/riscv/rvf/s_fpclassifyf.c: Likewise.
* sysdeps/riscv/rvf/s_isinff.c: Likewise.
* sysdeps/riscv/rvf/s_isnanf.c: Likewise.
* sysdeps/riscv/rvf/s_issignalingf.c: Likewise.
* sysdeps/riscv/rvf/s_nearbyintf.c: Likewise.
* sysdeps/riscv/rvf/s_roundevenf.c: Likewise.
* sysdeps/riscv/rvf/s_roundf.c: Likewise.
* sysdeps/riscv/rvf/s_truncf.c: Likewise.
2018-09-03 21:09:04 +00:00
|
|
|
#include <fenv_private.h>
|
2019-07-16 15:17:22 +00:00
|
|
|
#include <libm-alias-finite.h>
|
2001-05-12 14:32:12 +00:00
|
|
|
|
2011-10-25 04:56:33 +00:00
|
|
|
#ifndef SECTION
|
|
|
|
# define SECTION
|
|
|
|
#endif
|
|
|
|
|
2021-03-10 12:41:20 +00:00
|
|
|
#define TWO52 0x1.0p52
|
|
|
|
#define TWOM1022 0x1.0p-1022
|
|
|
|
|
2011-10-25 00:19:17 +00:00
|
|
|
/* Fix the sign and return after stage 1 or stage 2 */
|
2013-03-28 05:26:06 +00:00
|
|
|
static double
|
|
|
|
signArctan2 (double y, double z)
|
2011-10-25 00:19:17 +00:00
|
|
|
{
|
2018-09-27 20:04:48 +00:00
|
|
|
return copysign (z, y);
|
2011-10-25 00:19:17 +00:00
|
|
|
}
|
2013-03-28 05:26:06 +00:00
|
|
|
|
2021-03-10 12:41:20 +00:00
|
|
|
/* atan2 with max ULP of ~0.524 based on random sampling. */
|
2011-10-25 04:56:33 +00:00
|
|
|
double
|
|
|
|
SECTION
|
2013-03-28 05:26:06 +00:00
|
|
|
__ieee754_atan2 (double y, double x)
|
|
|
|
{
|
|
|
|
int i, de, ux, dx, uy, dy;
|
2021-03-10 12:41:20 +00:00
|
|
|
double ax, ay, u, du, v, vv, dv, t1, t2, t3,
|
|
|
|
z, zz, cor;
|
|
|
|
mynumber num;
|
2001-03-12 00:04:52 +00:00
|
|
|
|
2013-10-17 14:03:24 +00:00
|
|
|
static const int ep = 59768832, /* 57*16**5 */
|
|
|
|
em = -59768832; /* -57*16**5 */
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* x=NaN or y=NaN */
|
2013-03-28 05:26:06 +00:00
|
|
|
num.d = x;
|
|
|
|
ux = num.i[HIGH_HALF];
|
|
|
|
dx = num.i[LOW_HALF];
|
|
|
|
if ((ux & 0x7ff00000) == 0x7ff00000)
|
|
|
|
{
|
|
|
|
if (((ux & 0x000fffff) | dx) != 0x00000000)
|
2016-06-13 21:43:22 +00:00
|
|
|
return x + y;
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
|
|
|
num.d = y;
|
|
|
|
uy = num.i[HIGH_HALF];
|
|
|
|
dy = num.i[LOW_HALF];
|
|
|
|
if ((uy & 0x7ff00000) == 0x7ff00000)
|
|
|
|
{
|
|
|
|
if (((uy & 0x000fffff) | dy) != 0x00000000)
|
|
|
|
return y + y;
|
|
|
|
}
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* y=+-0 */
|
2013-03-28 05:26:06 +00:00
|
|
|
if (uy == 0x00000000)
|
|
|
|
{
|
|
|
|
if (dy == 0x00000000)
|
|
|
|
{
|
|
|
|
if ((ux & 0x80000000) == 0x00000000)
|
2013-03-29 11:07:26 +00:00
|
|
|
return 0;
|
2013-03-28 05:26:06 +00:00
|
|
|
else
|
|
|
|
return opi.d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (uy == 0x80000000)
|
|
|
|
{
|
|
|
|
if (dy == 0x00000000)
|
|
|
|
{
|
|
|
|
if ((ux & 0x80000000) == 0x00000000)
|
2013-03-29 11:07:26 +00:00
|
|
|
return -0.0;
|
2013-03-28 05:26:06 +00:00
|
|
|
else
|
|
|
|
return mopi.d;
|
|
|
|
}
|
|
|
|
}
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* x=+-0 */
|
2013-03-29 11:07:26 +00:00
|
|
|
if (x == 0)
|
2013-03-28 05:26:06 +00:00
|
|
|
{
|
|
|
|
if ((uy & 0x80000000) == 0x00000000)
|
|
|
|
return hpi.d;
|
|
|
|
else
|
|
|
|
return mhpi.d;
|
|
|
|
}
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* x=+-INF */
|
2013-03-28 05:26:06 +00:00
|
|
|
if (ux == 0x7ff00000)
|
|
|
|
{
|
|
|
|
if (dx == 0x00000000)
|
|
|
|
{
|
|
|
|
if (uy == 0x7ff00000)
|
|
|
|
{
|
|
|
|
if (dy == 0x00000000)
|
|
|
|
return qpi.d;
|
|
|
|
}
|
|
|
|
else if (uy == 0xfff00000)
|
|
|
|
{
|
|
|
|
if (dy == 0x00000000)
|
|
|
|
return mqpi.d;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((uy & 0x80000000) == 0x00000000)
|
2013-03-29 11:07:26 +00:00
|
|
|
return 0;
|
2013-03-28 05:26:06 +00:00
|
|
|
else
|
2013-03-29 11:07:26 +00:00
|
|
|
return -0.0;
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|
2013-03-28 05:26:06 +00:00
|
|
|
else if (ux == 0xfff00000)
|
|
|
|
{
|
|
|
|
if (dx == 0x00000000)
|
|
|
|
{
|
|
|
|
if (uy == 0x7ff00000)
|
|
|
|
{
|
|
|
|
if (dy == 0x00000000)
|
|
|
|
return tqpi.d;
|
|
|
|
}
|
|
|
|
else if (uy == 0xfff00000)
|
|
|
|
{
|
|
|
|
if (dy == 0x00000000)
|
|
|
|
return mtqpi.d;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ((uy & 0x80000000) == 0x00000000)
|
|
|
|
return opi.d;
|
|
|
|
else
|
|
|
|
return mopi.d;
|
|
|
|
}
|
|
|
|
}
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* y=+-INF */
|
2013-03-28 05:26:06 +00:00
|
|
|
if (uy == 0x7ff00000)
|
|
|
|
{
|
|
|
|
if (dy == 0x00000000)
|
|
|
|
return hpi.d;
|
|
|
|
}
|
|
|
|
else if (uy == 0xfff00000)
|
|
|
|
{
|
|
|
|
if (dy == 0x00000000)
|
|
|
|
return mhpi.d;
|
|
|
|
}
|
2001-03-12 00:04:52 +00:00
|
|
|
|
2015-04-08 17:32:17 +00:00
|
|
|
SET_RESTORE_ROUND (FE_TONEAREST);
|
2001-03-12 00:04:52 +00:00
|
|
|
/* either x/y or y/x is very close to zero */
|
2013-03-29 11:07:26 +00:00
|
|
|
ax = (x < 0) ? -x : x;
|
|
|
|
ay = (y < 0) ? -y : y;
|
2001-03-12 00:04:52 +00:00
|
|
|
de = (uy & 0x7ff00000) - (ux & 0x7ff00000);
|
2013-03-28 05:26:06 +00:00
|
|
|
if (de >= ep)
|
|
|
|
{
|
2013-03-29 11:07:26 +00:00
|
|
|
return ((y > 0) ? hpi.d : mhpi.d);
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
|
|
|
else if (de <= em)
|
|
|
|
{
|
2013-03-29 11:07:26 +00:00
|
|
|
if (x > 0)
|
2013-03-28 05:26:06 +00:00
|
|
|
{
|
Fix atan / atan2 missing underflows (bug 15319).
This patch fixes bug 15319, missing underflows from atan / atan2 when
the result of atan is very close to its small argument (or that of
atan2 is very close to the ratio of its arguments, which may be an
exact division).
The usual approach of doing an underflowing computation if the
computed result is subnormal is followed. For 32-bit x86, there are
extra complications: the inline __ieee754_atan2 in bits/mathinline.h
needs to be disabled for float and double because other libm functions
using it generally rely on getting proper underflow exceptions from
it, while the out-of-line functions have to remove excess range and
precision from the underflowing result so as to return an exact 0 in
the case where errno should be set for underflow to 0. (The failures
I saw without that are similar to those Carlos reported for other
functions, where I haven't seen a response to
<https://sourceware.org/ml/libc-alpha/2015-01/msg00485.html>
confirming if my diagnosis is correct. Arguably all libm functions
with float and double returns should remove excess range and
precision, but that's a separate matter.)
The x86_64 long double case reported in a comment in bug 15319 is not
a bug (it's an argument of LDBL_MIN, and x86_64 is an after-rounding
architecture so the correct IEEE result is not to raise underflow in
the given rounding mode, in addition to treating the result as an
exact LDBL_MIN being within the newly clarified documentation of
accuracy goals). I'm presuming that the fpatan instruction can be
trusted to raise appropriate exceptions when the (long double) result
underflows (after rounding) and so no changes are needed for x86 /
x86_64 long double functions here; empirically this is the case for
the cases covered in the testsuite, on my system.
Tested for x86_64, x86, powerpc and mips64. Only 32-bit x86 needs
ulps updates (for the changes to inlines meaning some functions no
longer get excess precision from their __ieee754_atan2* calls).
[BZ #15319]
* sysdeps/i386/fpu/e_atan2.S (dbl_min): New object.
(MO): New macro.
(__ieee754_atan2): For results with small absolute value, force
underflow exception and remove excess range and precision from
return value.
* sysdeps/i386/fpu/e_atan2f.S (flt_min): New object.
(MO): New macro.
(__ieee754_atan2f): For results with small absolute value, force
underflow exception and remove excess range and precision from
return value.
* sysdeps/i386/fpu/s_atan.S (dbl_min): New object.
(MO): New macro.
(__atan): For results with small absolute value, force underflow
exception and remove excess range and precision from return value.
* sysdeps/i386/fpu/s_atanf.S (flt_min): New object.
(MO): New macro.
(__atanf): For results with small absolute value, force underflow
exception and remove excess range and precision from return value.
* sysdeps/ieee754/dbl-64/e_atan2.c: Include <float.h> and
<math.h>.
(__ieee754_atan2): Force underflow exception for results with
small absolute value.
* sysdeps/ieee754/dbl-64/s_atan.c: Include <float.h> and
<math_private.h>.
(atan): Force underflow exception for results with small absolute
value.
* sysdeps/ieee754/flt-32/s_atanf.c: Include <float.h>.
(__atanf): Force underflow exception for results with small
absolute value.
* sysdeps/ieee754/ldbl-128/s_atanl.c: Include <float.h> and
<math.h>.
(__atanl): Force underflow exception for results with small
absolute value.
* sysdeps/ieee754/ldbl-128ibm/s_atanl.c: Include <float.h>.
(__atanl): Force underflow exception for results with small
absolute value.
* sysdeps/x86/fpu/bits/mathinline.h
[!__SSE2_MATH__ && !__x86_64__ && __LIBC_INTERNAL_MATH_INLINES]
(__ieee754_atan2): Only define inline for long double.
* sysdeps/x86_64/fpu/multiarch/e_atan2.c
[HAVE_FMA4_SUPPORT || HAVE_AVX_SUPPORT]: Include <math.h>.
* math/auto-libm-test-in: Do not mark underflow exceptions as
possibly missing for bug 15319. Add more tests of atan2.
* math/auto-libm-test-out: Regenerated.
* math/libm-test.inc (casin_test_data): Do not mark underflow
exceptions as possibly missing for bug 15319.
(casinh_test_data): Likewise.
* sysdeps/i386/fpu/libm-test-ulps: Update.
2015-02-18 21:10:49 +00:00
|
|
|
double ret;
|
2021-03-10 12:41:20 +00:00
|
|
|
z = ay / ax;
|
|
|
|
ret = signArctan2 (y, z);
|
Fix atan / atan2 missing underflows (bug 15319).
This patch fixes bug 15319, missing underflows from atan / atan2 when
the result of atan is very close to its small argument (or that of
atan2 is very close to the ratio of its arguments, which may be an
exact division).
The usual approach of doing an underflowing computation if the
computed result is subnormal is followed. For 32-bit x86, there are
extra complications: the inline __ieee754_atan2 in bits/mathinline.h
needs to be disabled for float and double because other libm functions
using it generally rely on getting proper underflow exceptions from
it, while the out-of-line functions have to remove excess range and
precision from the underflowing result so as to return an exact 0 in
the case where errno should be set for underflow to 0. (The failures
I saw without that are similar to those Carlos reported for other
functions, where I haven't seen a response to
<https://sourceware.org/ml/libc-alpha/2015-01/msg00485.html>
confirming if my diagnosis is correct. Arguably all libm functions
with float and double returns should remove excess range and
precision, but that's a separate matter.)
The x86_64 long double case reported in a comment in bug 15319 is not
a bug (it's an argument of LDBL_MIN, and x86_64 is an after-rounding
architecture so the correct IEEE result is not to raise underflow in
the given rounding mode, in addition to treating the result as an
exact LDBL_MIN being within the newly clarified documentation of
accuracy goals). I'm presuming that the fpatan instruction can be
trusted to raise appropriate exceptions when the (long double) result
underflows (after rounding) and so no changes are needed for x86 /
x86_64 long double functions here; empirically this is the case for
the cases covered in the testsuite, on my system.
Tested for x86_64, x86, powerpc and mips64. Only 32-bit x86 needs
ulps updates (for the changes to inlines meaning some functions no
longer get excess precision from their __ieee754_atan2* calls).
[BZ #15319]
* sysdeps/i386/fpu/e_atan2.S (dbl_min): New object.
(MO): New macro.
(__ieee754_atan2): For results with small absolute value, force
underflow exception and remove excess range and precision from
return value.
* sysdeps/i386/fpu/e_atan2f.S (flt_min): New object.
(MO): New macro.
(__ieee754_atan2f): For results with small absolute value, force
underflow exception and remove excess range and precision from
return value.
* sysdeps/i386/fpu/s_atan.S (dbl_min): New object.
(MO): New macro.
(__atan): For results with small absolute value, force underflow
exception and remove excess range and precision from return value.
* sysdeps/i386/fpu/s_atanf.S (flt_min): New object.
(MO): New macro.
(__atanf): For results with small absolute value, force underflow
exception and remove excess range and precision from return value.
* sysdeps/ieee754/dbl-64/e_atan2.c: Include <float.h> and
<math.h>.
(__ieee754_atan2): Force underflow exception for results with
small absolute value.
* sysdeps/ieee754/dbl-64/s_atan.c: Include <float.h> and
<math_private.h>.
(atan): Force underflow exception for results with small absolute
value.
* sysdeps/ieee754/flt-32/s_atanf.c: Include <float.h>.
(__atanf): Force underflow exception for results with small
absolute value.
* sysdeps/ieee754/ldbl-128/s_atanl.c: Include <float.h> and
<math.h>.
(__atanl): Force underflow exception for results with small
absolute value.
* sysdeps/ieee754/ldbl-128ibm/s_atanl.c: Include <float.h>.
(__atanl): Force underflow exception for results with small
absolute value.
* sysdeps/x86/fpu/bits/mathinline.h
[!__SSE2_MATH__ && !__x86_64__ && __LIBC_INTERNAL_MATH_INLINES]
(__ieee754_atan2): Only define inline for long double.
* sysdeps/x86_64/fpu/multiarch/e_atan2.c
[HAVE_FMA4_SUPPORT || HAVE_AVX_SUPPORT]: Include <math.h>.
* math/auto-libm-test-in: Do not mark underflow exceptions as
possibly missing for bug 15319. Add more tests of atan2.
* math/auto-libm-test-out: Regenerated.
* math/libm-test.inc (casin_test_data): Do not mark underflow
exceptions as possibly missing for bug 15319.
(casinh_test_data): Likewise.
* sysdeps/i386/fpu/libm-test-ulps: Update.
2015-02-18 21:10:49 +00:00
|
|
|
if (fabs (ret) < DBL_MIN)
|
|
|
|
{
|
|
|
|
double vret = ret ? ret : DBL_MIN;
|
|
|
|
double force_underflow = vret * vret;
|
|
|
|
math_force_eval (force_underflow);
|
|
|
|
}
|
|
|
|
return ret;
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-29 11:07:26 +00:00
|
|
|
return ((y > 0) ? opi.d : mopi.d);
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-12 00:04:52 +00:00
|
|
|
|
|
|
|
/* if either x or y is extremely close to zero, scale abs(x), abs(y). */
|
2013-03-28 05:26:06 +00:00
|
|
|
if (ax < twom500.d || ay < twom500.d)
|
|
|
|
{
|
|
|
|
ax *= two500.d;
|
|
|
|
ay *= two500.d;
|
|
|
|
}
|
2001-03-12 00:04:52 +00:00
|
|
|
|
2012-03-19 20:11:09 +00:00
|
|
|
/* Likewise for large x and y. */
|
|
|
|
if (ax > two500.d || ay > two500.d)
|
|
|
|
{
|
|
|
|
ax *= twom500.d;
|
|
|
|
ay *= twom500.d;
|
|
|
|
}
|
|
|
|
|
2001-03-12 00:04:52 +00:00
|
|
|
/* x,y which are neither special nor extreme */
|
2013-03-28 05:26:06 +00:00
|
|
|
if (ay < ax)
|
|
|
|
{
|
|
|
|
u = ay / ax;
|
ieee754/dbl-64: Reduce the scope of temporary storage variables
This came to light when adding hard-flaot support to ARC glibc port
without hardware sqrt support causing glibc build to fail:
| ../sysdeps/ieee754/dbl-64/e_sqrt.c: In function '__ieee754_sqrt':
| ../sysdeps/ieee754/dbl-64/e_sqrt.c:58:54: error: unused variable 'ty' [-Werror=unused-variable]
| double y, t, del, res, res1, hy, z, zz, p, hx, tx, ty, s;
The reason being EMULV() macro uses the hardware provided
__builtin_fma() variant, leaving temporary variables 'p, hx, tx, hy, ty'
unused hence compiler warning and ensuing error.
The intent of the patch was to fix that error, but EMULV is pervasive
and used fair bit indirectly via othe rmacros, hence this patch.
Functionally it should not result in code gen changes and if at all
those would be better since the scope of those temporaries is greatly
reduced now
Built tested with aarch64-linux-gnu arm-linux-gnueabi arm-linux-gnueabihf hppa-linux-gnu x86_64-linux-gnu arm-linux-gnueabihf riscv64-linux-gnu-rv64imac-lp64 riscv64-linux-gnu-rv64imafdc-lp64 powerpc-linux-gnu microblaze-linux-gnu nios2-linux-gnu hppa-linux-gnu
Also as suggested by Joseph [1] used --strip and compared the libs with
and w/o patch and they are byte-for-byte unchanged (with gcc 9).
| for i in `find . -name libm-2.31.9000.so`;
| do
| echo $i; diff $i /SCRATCH/vgupta/gnu2/install/glibcs/$i ; echo $?;
| done
| ./aarch64-linux-gnu/lib64/libm-2.31.9000.so
| 0
| ./arm-linux-gnueabi/lib/libm-2.31.9000.so
| 0
| ./x86_64-linux-gnu/lib64/libm-2.31.9000.so
| 0
| ./arm-linux-gnueabihf/lib/libm-2.31.9000.so
| 0
| ./riscv64-linux-gnu-rv64imac-lp64/lib64/lp64/libm-2.31.9000.so
| 0
| ./riscv64-linux-gnu-rv64imafdc-lp64/lib64/lp64/libm-2.31.9000.so
| 0
| ./powerpc-linux-gnu/lib/libm-2.31.9000.so
| 0
| ./microblaze-linux-gnu/lib/libm-2.31.9000.so
| 0
| ./nios2-linux-gnu/lib/libm-2.31.9000.so
| 0
| ./hppa-linux-gnu/lib/libm-2.31.9000.so
| 0
| ./s390x-linux-gnu/lib64/libm-2.31.9000.so
[1] https://sourceware.org/pipermail/libc-alpha/2019-November/108267.html
2019-11-08 19:32:00 +00:00
|
|
|
EMULV (ax, u, v, vv);
|
2013-03-28 05:26:06 +00:00
|
|
|
du = ((ay - v) - vv) / ax;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u = ax / ay;
|
ieee754/dbl-64: Reduce the scope of temporary storage variables
This came to light when adding hard-flaot support to ARC glibc port
without hardware sqrt support causing glibc build to fail:
| ../sysdeps/ieee754/dbl-64/e_sqrt.c: In function '__ieee754_sqrt':
| ../sysdeps/ieee754/dbl-64/e_sqrt.c:58:54: error: unused variable 'ty' [-Werror=unused-variable]
| double y, t, del, res, res1, hy, z, zz, p, hx, tx, ty, s;
The reason being EMULV() macro uses the hardware provided
__builtin_fma() variant, leaving temporary variables 'p, hx, tx, hy, ty'
unused hence compiler warning and ensuing error.
The intent of the patch was to fix that error, but EMULV is pervasive
and used fair bit indirectly via othe rmacros, hence this patch.
Functionally it should not result in code gen changes and if at all
those would be better since the scope of those temporaries is greatly
reduced now
Built tested with aarch64-linux-gnu arm-linux-gnueabi arm-linux-gnueabihf hppa-linux-gnu x86_64-linux-gnu arm-linux-gnueabihf riscv64-linux-gnu-rv64imac-lp64 riscv64-linux-gnu-rv64imafdc-lp64 powerpc-linux-gnu microblaze-linux-gnu nios2-linux-gnu hppa-linux-gnu
Also as suggested by Joseph [1] used --strip and compared the libs with
and w/o patch and they are byte-for-byte unchanged (with gcc 9).
| for i in `find . -name libm-2.31.9000.so`;
| do
| echo $i; diff $i /SCRATCH/vgupta/gnu2/install/glibcs/$i ; echo $?;
| done
| ./aarch64-linux-gnu/lib64/libm-2.31.9000.so
| 0
| ./arm-linux-gnueabi/lib/libm-2.31.9000.so
| 0
| ./x86_64-linux-gnu/lib64/libm-2.31.9000.so
| 0
| ./arm-linux-gnueabihf/lib/libm-2.31.9000.so
| 0
| ./riscv64-linux-gnu-rv64imac-lp64/lib64/lp64/libm-2.31.9000.so
| 0
| ./riscv64-linux-gnu-rv64imafdc-lp64/lib64/lp64/libm-2.31.9000.so
| 0
| ./powerpc-linux-gnu/lib/libm-2.31.9000.so
| 0
| ./microblaze-linux-gnu/lib/libm-2.31.9000.so
| 0
| ./nios2-linux-gnu/lib/libm-2.31.9000.so
| 0
| ./hppa-linux-gnu/lib/libm-2.31.9000.so
| 0
| ./s390x-linux-gnu/lib64/libm-2.31.9000.so
[1] https://sourceware.org/pipermail/libc-alpha/2019-November/108267.html
2019-11-08 19:32:00 +00:00
|
|
|
EMULV (ay, u, v, vv);
|
2013-03-28 05:26:06 +00:00
|
|
|
du = ((ax - v) - vv) / ay;
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|
|
|
|
|
2013-03-29 11:07:26 +00:00
|
|
|
if (x > 0)
|
2013-03-28 05:26:06 +00:00
|
|
|
{
|
|
|
|
/* (i) x>0, abs(y)< abs(x): atan(ay/ax) */
|
|
|
|
if (ay < ax)
|
|
|
|
{
|
|
|
|
if (u < inv16.d)
|
|
|
|
{
|
|
|
|
v = u * u;
|
|
|
|
|
|
|
|
zz = du + u * v * (d3.d
|
|
|
|
+ v * (d5.d
|
|
|
|
+ v * (d7.d
|
|
|
|
+ v * (d9.d
|
|
|
|
+ v * (d11.d
|
|
|
|
+ v * d13.d)))));
|
|
|
|
|
2021-03-10 12:41:20 +00:00
|
|
|
z = u + zz;
|
|
|
|
/* Max ULP is 0.504. */
|
|
|
|
return signArctan2 (y, z);
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 12:41:20 +00:00
|
|
|
i = (TWO52 + 256 * u) - TWO52;
|
2013-03-28 05:26:06 +00:00
|
|
|
i -= 16;
|
|
|
|
t3 = u - cij[i][0].d;
|
|
|
|
EADD (t3, du, v, dv);
|
|
|
|
t1 = cij[i][1].d;
|
|
|
|
t2 = cij[i][2].d;
|
|
|
|
zz = v * t2 + (dv * t2
|
|
|
|
+ v * v * (cij[i][3].d
|
|
|
|
+ v * (cij[i][4].d
|
|
|
|
+ v * (cij[i][5].d
|
|
|
|
+ v * cij[i][6].d))));
|
2021-03-10 12:41:20 +00:00
|
|
|
z = t1 + zz;
|
|
|
|
/* Max ULP is 0.56. */
|
|
|
|
return signArctan2 (y, z);
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* (ii) x>0, abs(x)<=abs(y): pi/2-atan(ax/ay) */
|
|
|
|
if (u < inv16.d)
|
|
|
|
{
|
|
|
|
v = u * u;
|
|
|
|
zz = u * v * (d3.d
|
|
|
|
+ v * (d5.d
|
|
|
|
+ v * (d7.d
|
|
|
|
+ v * (d9.d
|
|
|
|
+ v * (d11.d
|
|
|
|
+ v * d13.d)))));
|
|
|
|
ESUB (hpi.d, u, t2, cor);
|
|
|
|
t3 = ((hpi1.d + cor) - du) - zz;
|
2021-03-10 12:41:20 +00:00
|
|
|
z = t2 + t3;
|
|
|
|
/* Max ULP is 0.501. */
|
|
|
|
return signArctan2 (y, z);
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 12:41:20 +00:00
|
|
|
i = (TWO52 + 256 * u) - TWO52;
|
2013-03-28 05:26:06 +00:00
|
|
|
i -= 16;
|
|
|
|
v = (u - cij[i][0].d) + du;
|
|
|
|
|
|
|
|
zz = hpi1.d - v * (cij[i][2].d
|
|
|
|
+ v * (cij[i][3].d
|
|
|
|
+ v * (cij[i][4].d
|
|
|
|
+ v * (cij[i][5].d
|
|
|
|
+ v * cij[i][6].d))));
|
|
|
|
t1 = hpi.d - cij[i][1].d;
|
2021-03-10 12:41:20 +00:00
|
|
|
z = t1 + zz;
|
|
|
|
/* Max ULP is 0.503. */
|
|
|
|
return signArctan2 (y, z);
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|
2013-03-28 05:26:06 +00:00
|
|
|
|
|
|
|
/* (iii) x<0, abs(x)< abs(y): pi/2+atan(ax/ay) */
|
|
|
|
if (ax < ay)
|
|
|
|
{
|
|
|
|
if (u < inv16.d)
|
|
|
|
{
|
|
|
|
v = u * u;
|
|
|
|
zz = u * v * (d3.d
|
|
|
|
+ v * (d5.d
|
|
|
|
+ v * (d7.d
|
|
|
|
+ v * (d9.d
|
|
|
|
+ v * (d11.d + v * d13.d)))));
|
|
|
|
EADD (hpi.d, u, t2, cor);
|
|
|
|
t3 = ((hpi1.d + cor) + du) + zz;
|
2021-03-10 12:41:20 +00:00
|
|
|
z = t2 + t3;
|
|
|
|
/* Max ULP is 0.501. */
|
|
|
|
return signArctan2 (y, z);
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
|
|
|
|
2021-03-10 12:41:20 +00:00
|
|
|
i = (TWO52 + 256 * u) - TWO52;
|
2013-03-28 05:26:06 +00:00
|
|
|
i -= 16;
|
|
|
|
v = (u - cij[i][0].d) + du;
|
|
|
|
zz = hpi1.d + v * (cij[i][2].d
|
|
|
|
+ v * (cij[i][3].d
|
|
|
|
+ v * (cij[i][4].d
|
|
|
|
+ v * (cij[i][5].d
|
|
|
|
+ v * cij[i][6].d))));
|
|
|
|
t1 = hpi.d + cij[i][1].d;
|
2021-03-10 12:41:20 +00:00
|
|
|
z = t1 + zz;
|
|
|
|
/* Max ULP is 0.503. */
|
|
|
|
return signArctan2 (y, z);
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|
|
|
|
|
2013-03-28 05:26:06 +00:00
|
|
|
/* (iv) x<0, abs(y)<=abs(x): pi-atan(ax/ay) */
|
|
|
|
if (u < inv16.d)
|
|
|
|
{
|
|
|
|
v = u * u;
|
|
|
|
zz = u * v * (d3.d
|
|
|
|
+ v * (d5.d
|
|
|
|
+ v * (d7.d
|
|
|
|
+ v * (d9.d + v * (d11.d + v * d13.d)))));
|
|
|
|
ESUB (opi.d, u, t2, cor);
|
|
|
|
t3 = ((opi1.d + cor) - du) - zz;
|
2021-03-10 12:41:20 +00:00
|
|
|
z = t2 + t3;
|
|
|
|
/* Max ULP is 0.501. */
|
|
|
|
return signArctan2 (y, z);
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|
2013-03-28 05:26:06 +00:00
|
|
|
|
2021-03-10 12:41:20 +00:00
|
|
|
i = (TWO52 + 256 * u) - TWO52;
|
2013-03-28 05:26:06 +00:00
|
|
|
i -= 16;
|
|
|
|
v = (u - cij[i][0].d) + du;
|
|
|
|
zz = opi1.d - v * (cij[i][2].d
|
|
|
|
+ v * (cij[i][3].d
|
|
|
|
+ v * (cij[i][4].d
|
|
|
|
+ v * (cij[i][5].d + v * cij[i][6].d))));
|
|
|
|
t1 = opi.d - cij[i][1].d;
|
2021-03-10 12:41:20 +00:00
|
|
|
z = t1 + zz;
|
|
|
|
/* Max ULP is 0.502. */
|
|
|
|
return signArctan2 (y, z);
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|
2013-03-28 05:26:06 +00:00
|
|
|
|
2011-10-25 00:19:17 +00:00
|
|
|
#ifndef __ieee754_atan2
|
2019-07-16 15:17:22 +00:00
|
|
|
libm_alias_finite (__ieee754_atan2, __atan2)
|
2011-10-25 00:19:17 +00:00
|
|
|
#endif
|