|
Packit |
6c4009 |
/* e_atan2l.c -- long double version of e_atan2.c.
|
|
Packit |
6c4009 |
* Conversion to long double by Jakub Jelinek, jj@ultra.linux.cz.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/*
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
Packit |
6c4009 |
* Permission to use, copy, modify, and distribute this
|
|
Packit |
6c4009 |
* software is freely granted, provided that this notice
|
|
Packit |
6c4009 |
* is preserved.
|
|
Packit |
6c4009 |
* ====================================================
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* __ieee754_atan2l(y,x)
|
|
Packit |
6c4009 |
* Method :
|
|
Packit |
6c4009 |
* 1. Reduce y to positive by atan2l(y,x)=-atan2l(-y,x).
|
|
Packit |
6c4009 |
* 2. Reduce x to positive by (if x and y are unexceptional):
|
|
Packit |
6c4009 |
* ARG (x+iy) = arctan(y/x) ... if x > 0,
|
|
Packit |
6c4009 |
* ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Special cases:
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* ATAN2((anything), NaN ) is NaN;
|
|
Packit |
6c4009 |
* ATAN2(NAN , (anything) ) is NaN;
|
|
Packit |
6c4009 |
* ATAN2(+-0, +(anything but NaN)) is +-0 ;
|
|
Packit |
6c4009 |
* ATAN2(+-0, -(anything but NaN)) is +-pi ;
|
|
Packit |
6c4009 |
* ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
|
|
Packit |
6c4009 |
* ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
|
|
Packit |
6c4009 |
* ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
|
|
Packit |
6c4009 |
* ATAN2(+-INF,+INF ) is +-pi/4 ;
|
|
Packit |
6c4009 |
* ATAN2(+-INF,-INF ) is +-3pi/4;
|
|
Packit |
6c4009 |
* ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
|
|
Packit |
6c4009 |
*
|
|
Packit |
6c4009 |
* Constants:
|
|
Packit |
6c4009 |
* The hexadecimal values are the intended ones for the following
|
|
Packit |
6c4009 |
* constants. The decimal values may be used, provided that the
|
|
Packit |
6c4009 |
* compiler will convert from decimal to binary accurately enough
|
|
Packit |
6c4009 |
* to produce the hexadecimal values shown.
|
|
Packit |
6c4009 |
*/
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <math.h>
|
|
Packit |
6c4009 |
#include <math_private.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static const long double
|
|
Packit |
6c4009 |
tiny = 1.0e-300L,
|
|
Packit |
6c4009 |
zero = 0.0,
|
|
Packit |
6c4009 |
pi_o_4 = 7.85398163397448309615660845819875699e-01L, /* 3ffe921fb54442d18469898cc51701b8 */
|
|
Packit |
6c4009 |
pi_o_2 = 1.57079632679489661923132169163975140e+00L, /* 3fff921fb54442d18469898cc51701b8 */
|
|
Packit |
6c4009 |
pi = 3.14159265358979323846264338327950280e+00L, /* 4000921fb54442d18469898cc51701b8 */
|
|
Packit |
6c4009 |
pi_lo = 8.67181013012378102479704402604335225e-35L; /* 3f8dcd129024e088a67cc74020bbea64 */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
long double
|
|
Packit |
6c4009 |
__ieee754_atan2l(long double y, long double x)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
long double z;
|
|
Packit |
6c4009 |
int64_t k,m,hx,hy,ix,iy;
|
|
Packit |
6c4009 |
uint64_t lx;
|
|
Packit |
6c4009 |
double xhi, xlo, yhi;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
ldbl_unpack (x, &xhi, &xlo;;
|
|
Packit |
6c4009 |
EXTRACT_WORDS64 (hx, xhi);
|
|
Packit |
6c4009 |
EXTRACT_WORDS64 (lx, xlo);
|
|
Packit |
6c4009 |
ix = hx&0x7fffffffffffffffLL;
|
|
Packit |
6c4009 |
yhi = ldbl_high (y);
|
|
Packit |
6c4009 |
EXTRACT_WORDS64 (hy, yhi);
|
|
Packit |
6c4009 |
iy = hy&0x7fffffffffffffffLL;
|
|
Packit |
6c4009 |
if(((ix)>0x7ff0000000000000LL)||
|
|
Packit |
6c4009 |
((iy)>0x7ff0000000000000LL)) /* x or y is NaN */
|
|
Packit |
6c4009 |
return x+y;
|
|
Packit |
6c4009 |
if(((hx-0x3ff0000000000000LL))==0
|
|
Packit |
6c4009 |
&& (lx&0x7fffffffffffffff)==0) return __atanl(y); /* x=1.0L */
|
|
Packit |
6c4009 |
m = ((hy>>63)&1)|((hx>>62)&2;; /* 2*sign(x)+sign(y) */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* when y = 0 */
|
|
Packit |
6c4009 |
if(iy==0) {
|
|
Packit |
6c4009 |
switch(m) {
|
|
Packit |
6c4009 |
case 0:
|
|
Packit |
6c4009 |
case 1: return y; /* atan(+-0,+anything)=+-0 */
|
|
Packit |
6c4009 |
case 2: return pi+tiny;/* atan(+0,-anything) = pi */
|
|
Packit |
6c4009 |
case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
/* when x = 0 */
|
|
Packit |
6c4009 |
if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* when x is INF */
|
|
Packit |
6c4009 |
if(ix==0x7ff0000000000000LL) {
|
|
Packit |
6c4009 |
if(iy==0x7ff0000000000000LL) {
|
|
Packit |
6c4009 |
switch(m) {
|
|
Packit |
6c4009 |
case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
|
|
Packit |
6c4009 |
case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
|
|
Packit |
6c4009 |
case 2: return 3.0L*pi_o_4+tiny;/*atan(+INF,-INF)*/
|
|
Packit |
6c4009 |
case 3: return -3.0L*pi_o_4-tiny;/*atan(-INF,-INF)*/
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
} else {
|
|
Packit |
6c4009 |
switch(m) {
|
|
Packit |
6c4009 |
case 0: return zero ; /* atan(+...,+INF) */
|
|
Packit |
6c4009 |
case 1: return -zero ; /* atan(-...,+INF) */
|
|
Packit |
6c4009 |
case 2: return pi+tiny ; /* atan(+...,-INF) */
|
|
Packit |
6c4009 |
case 3: return -pi-tiny ; /* atan(-...,-INF) */
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
/* when y is INF */
|
|
Packit |
6c4009 |
if(iy==0x7ff0000000000000LL) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* compute y/x */
|
|
Packit |
6c4009 |
k = (iy-ix)>>52;
|
|
Packit |
6c4009 |
if(k > 120) z=pi_o_2+0.5L*pi_lo; /* |y/x| > 2**120 */
|
|
Packit |
6c4009 |
else if(hx<0&&k<-120) z=0.0L; /* |y|/x < -2**120 */
|
|
Packit |
6c4009 |
else z=__atanl(fabsl(y/x)); /* safe to do y/x */
|
|
Packit |
6c4009 |
switch (m) {
|
|
Packit |
6c4009 |
case 0: return z ; /* atan(+,+) */
|
|
Packit |
6c4009 |
case 1: return -z ; /* atan(-,+) */
|
|
Packit |
6c4009 |
case 2: return pi-(z-pi_lo);/* atan(+,-) */
|
|
Packit |
6c4009 |
default: /* case 3 */
|
|
Packit |
6c4009 |
return (z-pi_lo)-pi;/* atan(-,-) */
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
strong_alias (__ieee754_atan2l, __atan2l_finite)
|