]>
Commit | Line | Data |
---|---|---|
0d8733c4 UD |
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. | |
4 | */ | |
5 | ||
6 | /* | |
7 | * ==================================================== | |
8 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | |
9 | * | |
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 | |
13 | * is preserved. | |
14 | * ==================================================== | |
15 | */ | |
16 | ||
0d8733c4 UD |
17 | /* __ieee754_atan2l(y,x) |
18 | * Method : | |
19 | * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). | |
20 | * 2. Reduce x to positive by (if x and y are unexceptional): | |
0ac5ae23 | 21 | * ARG (x+iy) = arctan(y/x) ... if x > 0, |
0d8733c4 UD |
22 | * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, |
23 | * | |
24 | * Special cases: | |
25 | * | |
26 | * ATAN2((anything), NaN ) is NaN; | |
27 | * ATAN2(NAN , (anything) ) is NaN; | |
28 | * ATAN2(+-0, +(anything but NaN)) is +-0 ; | |
29 | * ATAN2(+-0, -(anything but NaN)) is +-pi ; | |
30 | * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2; | |
31 | * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; | |
32 | * ATAN2(+-(anything but INF and NaN), -INF) is +-pi; | |
33 | * ATAN2(+-INF,+INF ) is +-pi/4 ; | |
34 | * ATAN2(+-INF,-INF ) is +-3pi/4; | |
35 | * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; | |
36 | * | |
37 | * Constants: | |
38 | * The hexadecimal values are the intended ones for the following | |
39 | * constants. The decimal values may be used, provided that the | |
40 | * compiler will convert from decimal to binary accurately enough | |
41 | * to produce the hexadecimal values shown. | |
42 | */ | |
43 | ||
44 | #include "math.h" | |
45 | #include "math_private.h" | |
46 | ||
0d8733c4 | 47 | static const long double |
0d8733c4 UD |
48 | tiny = 1.0e-4900L, |
49 | zero = 0.0, | |
50 | pi_o_4 = 7.85398163397448309628202E-01L, /* 0x3FFE, 0xC90FDAA2, 0x2168C235 */ | |
51 | pi_o_2 = 1.5707963267948966192564E+00L, /* 0x3FFF, 0xC90FDAA2, 0x2168C235 */ | |
52 | pi = 3.14159265358979323851281E+00L, /* 0x4000, 0xC90FDAA2, 0x2168C235 */ | |
53 | pi_lo = -5.01655761266833202345176e-20L;/* 0xBFBE, 0xECE675D1, 0xFC8F8CBB */ | |
54 | ||
0ac5ae23 UD |
55 | long double |
56 | __ieee754_atan2l (long double y, long double x) | |
0d8733c4 UD |
57 | { |
58 | long double z; | |
59 | int32_t k,m,hx,hy,ix,iy; | |
60 | u_int32_t sx,sy,lx,ly; | |
61 | ||
cc3fa755 | 62 | GET_LDOUBLE_WORDS(sx,hx,lx,x); |
0d8733c4 | 63 | ix = sx&0x7fff; |
51702635 | 64 | lx |= hx & 0x7fffffff; |
cc3fa755 | 65 | GET_LDOUBLE_WORDS(sy,hy,ly,y); |
0d8733c4 | 66 | iy = sy&0x7fff; |
51702635 | 67 | ly |= hy & 0x7fffffff; |
0d8733c4 UD |
68 | if(((2*ix|((lx|-lx)>>31))>0xfffe)|| |
69 | ((2*iy|((ly|-ly)>>31))>0xfffe)) /* x or y is NaN */ | |
70 | return x+y; | |
e161e6c8 | 71 | if(((sx-0x3fff)|lx)==0) return __atanl(y); /* x=1.0 */ |
0d8733c4 UD |
72 | m = ((sy>>15)&1)|((sx>>14)&2); /* 2*sign(x)+sign(y) */ |
73 | ||
74 | /* when y = 0 */ | |
75 | if((iy|ly)==0) { | |
76 | switch(m) { | |
77 | case 0: | |
0ac5ae23 | 78 | case 1: return y; /* atan(+-0,+anything)=+-0 */ |
0d8733c4 UD |
79 | case 2: return pi+tiny;/* atan(+0,-anything) = pi */ |
80 | case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ | |
81 | } | |
82 | } | |
83 | /* when x = 0 */ | |
84 | if((ix|lx)==0) return (sy>=0x8000)? -pi_o_2-tiny: pi_o_2+tiny; | |
85 | ||
86 | /* when x is INF */ | |
87 | if(ix==0x7fff) { | |
88 | if(iy==0x7fff) { | |
89 | switch(m) { | |
90 | case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */ | |
91 | case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */ | |
92 | case 2: return 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/ | |
93 | case 3: return -3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/ | |
94 | } | |
95 | } else { | |
96 | switch(m) { | |
97 | case 0: return zero ; /* atan(+...,+INF) */ | |
98 | case 1: return -zero ; /* atan(-...,+INF) */ | |
99 | case 2: return pi+tiny ; /* atan(+...,-INF) */ | |
100 | case 3: return -pi-tiny ; /* atan(-...,-INF) */ | |
101 | } | |
102 | } | |
103 | } | |
104 | /* when y is INF */ | |
51702635 | 105 | if(iy==0x7fff) return (sy>=0x8000)? -pi_o_2-tiny: pi_o_2+tiny; |
0d8733c4 UD |
106 | |
107 | /* compute y/x */ | |
108 | k = sy-sx; | |
0ac5ae23 UD |
109 | if(k > 70) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**70 */ |
110 | else if(sx>=0x8000&&k<-70) z=0.0; /* |y|/x < -2**70 */ | |
0d8733c4 UD |
111 | else z=__atanl(fabsl(y/x)); /* safe to do y/x */ |
112 | switch (m) { | |
113 | case 0: return z ; /* atan(+,+) */ | |
114 | case 1: { | |
0ac5ae23 | 115 | u_int32_t sz; |
0d8733c4 | 116 | GET_LDOUBLE_EXP(sz,z); |
3e5f5557 | 117 | SET_LDOUBLE_EXP(z,sz ^ 0x8000); |
0d8733c4 UD |
118 | } |
119 | return z ; /* atan(-,+) */ | |
120 | case 2: return pi-(z-pi_lo);/* atan(+,-) */ | |
121 | default: /* case 3 */ | |
0ac5ae23 | 122 | return (z-pi_lo)-pi;/* atan(-,-) */ |
0d8733c4 UD |
123 | } |
124 | } | |
0ac5ae23 | 125 | strong_alias (__ieee754_atan2l, __atan2l_finite) |