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.
|
2018-01-01 00:32:25 +00:00
|
|
|
* Copyright (C) 2001-2018 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
|
2012-02-09 23:18:22 +00:00
|
|
|
* along with this program; if not, see <http://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 */
|
|
|
|
/* atan2Mp */
|
|
|
|
/* signArctan2 */
|
|
|
|
/* normalized */
|
|
|
|
/* */
|
|
|
|
/* FILES NEEDED: dla.h endian.h mpa.h mydefs.h atnat2.h */
|
|
|
|
/* mpatan.c mpatan2.c mpsqrt.c */
|
|
|
|
/* uatan.tbl */
|
|
|
|
/* */
|
|
|
|
/* An ultimate atan2() routine. Given two IEEE double machine numbers y,*/
|
|
|
|
/* x it computes the correctly rounded (to nearest) value of atan2(y,x).*/
|
|
|
|
/* */
|
|
|
|
/* Assumption: Machine arithmetic operations are performed in */
|
|
|
|
/* round to nearest mode of IEEE 754 standard. */
|
|
|
|
/* */
|
|
|
|
/************************************************************************/
|
|
|
|
|
2011-10-23 16:50:28 +00:00
|
|
|
#include <dla.h>
|
2001-03-12 00:04:52 +00:00
|
|
|
#include "mpa.h"
|
|
|
|
#include "MathLib.h"
|
|
|
|
#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>
|
2012-03-09 19:29:16 +00:00
|
|
|
#include <math_private.h>
|
2013-10-11 17:07:53 +00:00
|
|
|
#include <stap-probe.h>
|
2001-05-12 14:32:12 +00:00
|
|
|
|
2011-10-25 04:56:33 +00:00
|
|
|
#ifndef SECTION
|
|
|
|
# define SECTION
|
|
|
|
#endif
|
|
|
|
|
2001-03-12 00:04:52 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* An ultimate atan2 routine. Given two IEEE double machine numbers y,x */
|
|
|
|
/* it computes the correctly rounded (to nearest) value of atan2(y,x). */
|
|
|
|
/* Assumption: Machine arithmetic operations are performed in */
|
|
|
|
/* round to nearest mode of IEEE 754 standard. */
|
|
|
|
/************************************************************************/
|
2013-03-28 05:26:06 +00:00
|
|
|
static double atan2Mp (double, double, const int[]);
|
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
|
|
|
{
|
2013-03-28 05:26:06 +00:00
|
|
|
return __copysign (z, y);
|
2011-10-25 00:19:17 +00:00
|
|
|
}
|
2013-03-28 05:26:06 +00:00
|
|
|
|
|
|
|
static double normalized (double, double, double, double);
|
|
|
|
void __mpatan2 (mp_no *, mp_no *, mp_no *, int);
|
2001-03-12 00:04:52 +00:00
|
|
|
|
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;
|
|
|
|
static const int pr[MM] = { 6, 8, 10, 20, 32 };
|
|
|
|
double ax, ay, u, du, u9, ua, v, vv, dv, t1, t2, t3, t7, t8,
|
2013-10-17 14:03:24 +00:00
|
|
|
z, zz, cor, s1, ss1, s2, ss2;
|
2011-10-24 18:21:18 +00:00
|
|
|
#ifndef DLA_FMS
|
2013-03-28 05:26:06 +00:00
|
|
|
double t4, t5, t6;
|
2001-03-12 07:57:09 +00:00
|
|
|
#endif
|
2001-03-12 00:04:52 +00:00
|
|
|
number num;
|
|
|
|
|
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;
|
2013-03-28 05:26:06 +00:00
|
|
|
if ((z = ay / ax) < TWOM1022)
|
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
|
|
|
ret = normalized (ax, ay, y, z);
|
2013-03-28 05:26:06 +00:00
|
|
|
else
|
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
|
|
|
ret = signArctan2 (y, z);
|
|
|
|
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;
|
|
|
|
EMULV (ax, u, v, vv, t1, t2, t3, t4, t5);
|
|
|
|
du = ((ay - v) - vv) / ax;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
u = ax / ay;
|
|
|
|
EMULV (ay, u, v, vv, t1, t2, t3, t4, t5);
|
|
|
|
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)))));
|
|
|
|
|
|
|
|
if ((z = u + (zz - u1.d * u)) == u + (zz + u1.d * u))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
|
|
|
|
MUL2 (u, du, u, du, v, vv, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
s1 = v * (f11.d + v * (f13.d
|
|
|
|
+ v * (f15.d + v * (f17.d + v * f19.d))));
|
2013-03-29 11:07:26 +00:00
|
|
|
ADD2 (f9.d, ff9.d, s1, 0, s2, ss2, t1, t2);
|
2013-03-28 05:26:06 +00:00
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f7.d, ff7.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f5.d, ff5.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f3.d, ff3.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
MUL2 (u, du, s1, ss1, s2, ss2, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (u, du, s2, ss2, s1, ss1, t1, t2);
|
|
|
|
|
|
|
|
if ((z = s1 + (ss1 - u5.d * s1)) == s1 + (ss1 + u5.d * s1))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
|
|
|
|
return atan2Mp (x, y, pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = (TWO52 + TWO8 * u) - TWO52;
|
|
|
|
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))));
|
|
|
|
if (i < 112)
|
|
|
|
{
|
|
|
|
if (i < 48)
|
2013-10-17 14:03:24 +00:00
|
|
|
u9 = u91.d; /* u < 1/4 */
|
2013-03-28 05:26:06 +00:00
|
|
|
else
|
|
|
|
u9 = u92.d;
|
2013-10-17 14:03:24 +00:00
|
|
|
} /* 1/4 <= u < 1/2 */
|
2013-03-28 05:26:06 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (i < 176)
|
2013-10-17 14:03:24 +00:00
|
|
|
u9 = u93.d; /* 1/2 <= u < 3/4 */
|
2013-03-28 05:26:06 +00:00
|
|
|
else
|
|
|
|
u9 = u94.d;
|
2013-10-17 14:03:24 +00:00
|
|
|
} /* 3/4 <= u <= 1 */
|
2013-03-28 05:26:06 +00:00
|
|
|
if ((z = t1 + (zz - u9 * t1)) == t1 + (zz + u9 * t1))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
|
|
|
|
t1 = u - hij[i][0].d;
|
|
|
|
EADD (t1, du, v, vv);
|
|
|
|
s1 = v * (hij[i][11].d
|
|
|
|
+ v * (hij[i][12].d
|
2013-10-17 14:03:24 +00:00
|
|
|
+ v * (hij[i][13].d
|
|
|
|
+ v * (hij[i][14].d
|
|
|
|
+ v * hij[i][15].d))));
|
2013-03-29 11:07:26 +00:00
|
|
|
ADD2 (hij[i][9].d, hij[i][10].d, s1, 0, s2, ss2, t1, t2);
|
2013-03-28 05:26:06 +00:00
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][7].d, hij[i][8].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][5].d, hij[i][6].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][3].d, hij[i][4].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][1].d, hij[i][2].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
|
|
|
|
if ((z = s2 + (ss2 - ub.d * s2)) == s2 + (ss2 + ub.d * s2))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
return atan2Mp (x, y, pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (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;
|
|
|
|
if ((z = t2 + (t3 - u2.d)) == t2 + (t3 + u2.d))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
|
|
|
|
MUL2 (u, du, u, du, v, vv, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
s1 = v * (f11.d
|
|
|
|
+ v * (f13.d
|
|
|
|
+ v * (f15.d + v * (f17.d + v * f19.d))));
|
2013-03-29 11:07:26 +00:00
|
|
|
ADD2 (f9.d, ff9.d, s1, 0, s2, ss2, t1, t2);
|
2013-03-28 05:26:06 +00:00
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f7.d, ff7.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f5.d, ff5.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f3.d, ff3.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
MUL2 (u, du, s1, ss1, s2, ss2, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (u, du, s2, ss2, s1, ss1, t1, t2);
|
|
|
|
SUB2 (hpi.d, hpi1.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
|
|
|
|
if ((z = s2 + (ss2 - u6.d)) == s2 + (ss2 + u6.d))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
return atan2Mp (x, y, pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = (TWO52 + TWO8 * u) - TWO52;
|
|
|
|
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;
|
|
|
|
if (i < 112)
|
|
|
|
ua = ua1.d; /* w < 1/2 */
|
|
|
|
else
|
|
|
|
ua = ua2.d; /* w >= 1/2 */
|
|
|
|
if ((z = t1 + (zz - ua)) == t1 + (zz + ua))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
|
|
|
|
t1 = u - hij[i][0].d;
|
|
|
|
EADD (t1, du, v, vv);
|
|
|
|
|
|
|
|
s1 = v * (hij[i][11].d
|
|
|
|
+ v * (hij[i][12].d
|
|
|
|
+ v * (hij[i][13].d
|
|
|
|
+ v * (hij[i][14].d
|
|
|
|
+ v * hij[i][15].d))));
|
|
|
|
|
2013-03-29 11:07:26 +00:00
|
|
|
ADD2 (hij[i][9].d, hij[i][10].d, s1, 0, s2, ss2, t1, t2);
|
2013-03-28 05:26:06 +00:00
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][7].d, hij[i][8].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][5].d, hij[i][6].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][3].d, hij[i][4].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][1].d, hij[i][2].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
SUB2 (hpi.d, hpi1.d, s2, ss2, s1, ss1, t1, t2);
|
|
|
|
|
|
|
|
if ((z = s1 + (ss1 - uc.d)) == s1 + (ss1 + uc.d))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
return atan2Mp (x, y, pr);
|
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;
|
|
|
|
if ((z = t2 + (t3 - u3.d)) == t2 + (t3 + u3.d))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
|
|
|
|
MUL2 (u, du, u, du, v, vv, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
s1 = v * (f11.d
|
|
|
|
+ v * (f13.d + v * (f15.d + v * (f17.d + v * f19.d))));
|
2013-03-29 11:07:26 +00:00
|
|
|
ADD2 (f9.d, ff9.d, s1, 0, s2, ss2, t1, t2);
|
2013-03-28 05:26:06 +00:00
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f7.d, ff7.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f5.d, ff5.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f3.d, ff3.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
MUL2 (u, du, s1, ss1, s2, ss2, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (u, du, s2, ss2, s1, ss1, t1, t2);
|
|
|
|
ADD2 (hpi.d, hpi1.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
|
|
|
|
if ((z = s2 + (ss2 - u7.d)) == s2 + (ss2 + u7.d))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
return atan2Mp (x, y, pr);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = (TWO52 + TWO8 * u) - TWO52;
|
|
|
|
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;
|
|
|
|
if (i < 112)
|
|
|
|
ua = ua1.d; /* w < 1/2 */
|
|
|
|
else
|
|
|
|
ua = ua2.d; /* w >= 1/2 */
|
|
|
|
if ((z = t1 + (zz - ua)) == t1 + (zz + ua))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
|
|
|
|
t1 = u - hij[i][0].d;
|
|
|
|
EADD (t1, du, v, vv);
|
|
|
|
s1 = v * (hij[i][11].d
|
|
|
|
+ v * (hij[i][12].d
|
|
|
|
+ v * (hij[i][13].d
|
|
|
|
+ v * (hij[i][14].d
|
|
|
|
+ v * hij[i][15].d))));
|
2013-03-29 11:07:26 +00:00
|
|
|
ADD2 (hij[i][9].d, hij[i][10].d, s1, 0, s2, ss2, t1, t2);
|
2013-03-28 05:26:06 +00:00
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][7].d, hij[i][8].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][5].d, hij[i][6].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][3].d, hij[i][4].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][1].d, hij[i][2].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
ADD2 (hpi.d, hpi1.d, s2, ss2, s1, ss1, t1, t2);
|
|
|
|
|
|
|
|
if ((z = s1 + (ss1 - uc.d)) == s1 + (ss1 + uc.d))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
return atan2Mp (x, y, pr);
|
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;
|
|
|
|
if ((z = t2 + (t3 - u4.d)) == t2 + (t3 + u4.d))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
|
|
|
|
MUL2 (u, du, u, du, v, vv, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
s1 = v * (f11.d + v * (f13.d + v * (f15.d + v * (f17.d + v * f19.d))));
|
2013-03-29 11:07:26 +00:00
|
|
|
ADD2 (f9.d, ff9.d, s1, 0, s2, ss2, t1, t2);
|
2013-03-28 05:26:06 +00:00
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f7.d, ff7.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f5.d, ff5.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (f3.d, ff3.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
MUL2 (u, du, s1, ss1, s2, ss2, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (u, du, s2, ss2, s1, ss1, t1, t2);
|
|
|
|
SUB2 (opi.d, opi1.d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
|
|
|
|
if ((z = s2 + (ss2 - u8.d)) == s2 + (ss2 + u8.d))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
return atan2Mp (x, y, pr);
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|
2013-03-28 05:26:06 +00:00
|
|
|
|
|
|
|
i = (TWO52 + TWO8 * u) - TWO52;
|
|
|
|
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;
|
|
|
|
if (i < 112)
|
|
|
|
ua = ua1.d; /* w < 1/2 */
|
|
|
|
else
|
|
|
|
ua = ua2.d; /* w >= 1/2 */
|
|
|
|
if ((z = t1 + (zz - ua)) == t1 + (zz + ua))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
|
|
|
|
t1 = u - hij[i][0].d;
|
|
|
|
|
|
|
|
EADD (t1, du, v, vv);
|
|
|
|
|
|
|
|
s1 = v * (hij[i][11].d
|
|
|
|
+ v * (hij[i][12].d
|
|
|
|
+ v * (hij[i][13].d
|
|
|
|
+ v * (hij[i][14].d + v * hij[i][15].d))));
|
|
|
|
|
2013-03-29 11:07:26 +00:00
|
|
|
ADD2 (hij[i][9].d, hij[i][10].d, s1, 0, s2, ss2, t1, t2);
|
2013-03-28 05:26:06 +00:00
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][7].d, hij[i][8].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][5].d, hij[i][6].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][3].d, hij[i][4].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
MUL2 (v, vv, s2, ss2, s1, ss1, t1, t2, t3, t4, t5, t6, t7, t8);
|
|
|
|
ADD2 (hij[i][1].d, hij[i][2].d, s1, ss1, s2, ss2, t1, t2);
|
|
|
|
SUB2 (opi.d, opi1.d, s2, ss2, s1, ss1, t1, t2);
|
|
|
|
|
|
|
|
if ((z = s1 + (ss1 - uc.d)) == s1 + (ss1 + uc.d))
|
|
|
|
return signArctan2 (y, z);
|
|
|
|
return atan2Mp (x, y, pr);
|
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
|
2011-10-12 15:27:51 +00:00
|
|
|
strong_alias (__ieee754_atan2, __atan2_finite)
|
2011-10-25 00:19:17 +00:00
|
|
|
#endif
|
2011-10-12 15:27:51 +00:00
|
|
|
|
2013-03-28 05:26:06 +00:00
|
|
|
/* Treat the Denormalized case */
|
2011-10-25 04:56:33 +00:00
|
|
|
static double
|
|
|
|
SECTION
|
2013-03-28 05:26:06 +00:00
|
|
|
normalized (double ax, double ay, double y, double z)
|
|
|
|
{
|
|
|
|
int p;
|
|
|
|
mp_no mpx, mpy, mpz, mperr, mpz2, mpt1;
|
|
|
|
p = 6;
|
|
|
|
__dbl_mp (ax, &mpx, p);
|
|
|
|
__dbl_mp (ay, &mpy, p);
|
|
|
|
__dvd (&mpy, &mpx, &mpz, p);
|
|
|
|
__dbl_mp (ue.d, &mpt1, p);
|
|
|
|
__mul (&mpz, &mpt1, &mperr, p);
|
|
|
|
__sub (&mpz, &mperr, &mpz2, p);
|
|
|
|
__mp_dbl (&mpz2, &z, p);
|
|
|
|
return signArctan2 (y, z);
|
2001-03-12 00:04:52 +00:00
|
|
|
}
|
2013-03-28 05:26:06 +00:00
|
|
|
|
|
|
|
/* Stage 3: Perform a multi-Precision computation */
|
2011-10-25 04:56:33 +00:00
|
|
|
static double
|
|
|
|
SECTION
|
2013-03-28 05:26:06 +00:00
|
|
|
atan2Mp (double x, double y, const int pr[])
|
2001-03-12 00:04:52 +00:00
|
|
|
{
|
2013-03-28 05:26:06 +00:00
|
|
|
double z1, z2;
|
|
|
|
int i, p;
|
|
|
|
mp_no mpx, mpy, mpz, mpz1, mpz2, mperr, mpt1;
|
|
|
|
for (i = 0; i < MM; i++)
|
|
|
|
{
|
|
|
|
p = pr[i];
|
|
|
|
__dbl_mp (x, &mpx, p);
|
|
|
|
__dbl_mp (y, &mpy, p);
|
|
|
|
__mpatan2 (&mpy, &mpx, &mpz, p);
|
|
|
|
__dbl_mp (ud[i].d, &mpt1, p);
|
|
|
|
__mul (&mpz, &mpt1, &mperr, p);
|
|
|
|
__add (&mpz, &mperr, &mpz1, p);
|
|
|
|
__sub (&mpz, &mperr, &mpz2, p);
|
|
|
|
__mp_dbl (&mpz1, &z1, p);
|
|
|
|
__mp_dbl (&mpz2, &z2, p);
|
|
|
|
if (z1 == z2)
|
2013-10-11 17:07:53 +00:00
|
|
|
{
|
|
|
|
LIBC_PROBE (slowatan2, 4, &p, &x, &y, &z1);
|
|
|
|
return z1;
|
|
|
|
}
|
2013-03-28 05:26:06 +00:00
|
|
|
}
|
2013-10-11 17:07:53 +00:00
|
|
|
LIBC_PROBE (slowatan2_inexact, 4, &p, &x, &y, &z1);
|
2013-03-28 05:26:06 +00:00
|
|
|
return z1; /*if impossible to do exact computing */
|
1996-03-05 21:41:30 +00:00
|
|
|
}
|