1 /* e_atan2l.c -- long double version of e_atan2.c.
2 * Conversion to long double by Ulrich Drepper,
3 * Cygnus Support, drepper@cygnus.com.
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
14 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid
[] = "$NetBSD: $";
21 /* __ieee754_atan2l(y,x)
23 * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
24 * 2. Reduce x to positive by (if x and y are unexceptional):
25 * ARG (x+iy) = arctan(y/x) ... if x > 0,
26 * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,
30 * ATAN2((anything), NaN ) is NaN;
31 * ATAN2(NAN , (anything) ) is NaN;
32 * ATAN2(+-0, +(anything but NaN)) is +-0 ;
33 * ATAN2(+-0, -(anything but NaN)) is +-pi ;
34 * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
35 * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
36 * ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
37 * ATAN2(+-INF,+INF ) is +-pi/4 ;
38 * ATAN2(+-INF,-INF ) is +-3pi/4;
39 * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
42 * The hexadecimal values are the intended ones for the following
43 * constants. The decimal values may be used, provided that the
44 * compiler will convert from decimal to binary accurately enough
45 * to produce the hexadecimal values shown.
49 #include "math_private.h"
52 static const long double
58 pi_o_4
= 7.85398163397448309628202E-01L, /* 0x3FFE, 0xC90FDAA2, 0x2168C235 */
59 pi_o_2
= 1.5707963267948966192564E+00L, /* 0x3FFF, 0xC90FDAA2, 0x2168C235 */
60 pi
= 3.14159265358979323851281E+00L, /* 0x4000, 0xC90FDAA2, 0x2168C235 */
61 pi_lo
= -5.01655761266833202345176e-20L;/* 0xBFBE, 0xECE675D1, 0xFC8F8CBB */
64 long double __ieee754_atan2l(long double y
, long double x
)
66 long double __ieee754_atan2l(y
,x
)
71 int32_t k
,m
,hx
,hy
,ix
,iy
;
72 u_int32_t sx
,sy
,lx
,ly
;
74 GET_LDOUBLE_WORDS(sx
,hx
,lx
,x
);
76 lx
|= hx
& 0x7fffffff;
77 GET_LDOUBLE_WORDS(sy
,hy
,ly
,y
);
79 ly
|= hy
& 0x7fffffff;
80 if(((2*ix
|((lx
|-lx
)>>31))>0xfffe)||
81 ((2*iy
|((ly
|-ly
)>>31))>0xfffe)) /* x or y is NaN */
83 if((sx
-0x3fff|lx
)==0) return __atanl(y
); /* x=1.0 */
84 m
= ((sy
>>15)&1)|((sx
>>14)&2); /* 2*sign(x)+sign(y) */
90 case 1: return y
; /* atan(+-0,+anything)=+-0 */
91 case 2: return pi
+tiny
;/* atan(+0,-anything) = pi */
92 case 3: return -pi
-tiny
;/* atan(-0,-anything) =-pi */
96 if((ix
|lx
)==0) return (sy
>=0x8000)? -pi_o_2
-tiny
: pi_o_2
+tiny
;
102 case 0: return pi_o_4
+tiny
;/* atan(+INF,+INF) */
103 case 1: return -pi_o_4
-tiny
;/* atan(-INF,+INF) */
104 case 2: return 3.0*pi_o_4
+tiny
;/*atan(+INF,-INF)*/
105 case 3: return -3.0*pi_o_4
-tiny
;/*atan(-INF,-INF)*/
109 case 0: return zero
; /* atan(+...,+INF) */
110 case 1: return -zero
; /* atan(-...,+INF) */
111 case 2: return pi
+tiny
; /* atan(+...,-INF) */
112 case 3: return -pi
-tiny
; /* atan(-...,-INF) */
117 if(iy
==0x7fff) return (sy
>=0x8000)? -pi_o_2
-tiny
: pi_o_2
+tiny
;
121 if(k
> 70) z
=pi_o_2
+0.5*pi_lo
; /* |y/x| > 2**70 */
122 else if(sx
>=0x8000&&k
<-70) z
=0.0; /* |y|/x < -2**70 */
123 else z
=__atanl(fabsl(y
/x
)); /* safe to do y/x */
125 case 0: return z
; /* atan(+,+) */
128 GET_LDOUBLE_EXP(sz
,z
);
129 SET_LDOUBLE_EXP(z
,sz
^ 0x8000);
131 return z
; /* atan(-,+) */
132 case 2: return pi
-(z
-pi_lo
);/* atan(+,-) */
133 default: /* case 3 */
134 return (z
-pi_lo
)-pi
;/* atan(-,-) */