1 /* origin: FreeBSD /usr/src/lib/msun/src/e_atan2l.c */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunSoft, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
14 * See comments in atan2.c.
15 * Converted to long double by David Schultz <das@FreeBSD.ORG>.
20 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
21 long double atan2l(long double y
, long double x
)
25 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
26 #include "__invtrigl.h"
28 long double atan2l(long double y
, long double x
)
34 if (isnan(x
) || isnan(y
))
40 ex
= ux
.i
.se
& 0x7fff;
41 ey
= uy
.i
.se
& 0x7fff;
42 m
= 2*(ux
.i
.se
>>15) | uy
.i
.se
>>15;
46 case 1: return y
; /* atan(+-0,+anything)=+-0 */
47 case 2: return 2*pio2_hi
; /* atan(+0,-anything) = pi */
48 case 3: return -2*pio2_hi
; /* atan(-0,-anything) =-pi */
52 return m
&1 ? -pio2_hi
: pio2_hi
;
56 case 0: return pio2_hi
/2; /* atan(+INF,+INF) */
57 case 1: return -pio2_hi
/2; /* atan(-INF,+INF) */
58 case 2: return 1.5*pio2_hi
; /* atan(+INF,-INF) */
59 case 3: return -1.5*pio2_hi
; /* atan(-INF,-INF) */
63 case 0: return 0.0; /* atan(+...,+INF) */
64 case 1: return -0.0; /* atan(-...,+INF) */
65 case 2: return 2*pio2_hi
; /* atan(+...,-INF) */
66 case 3: return -2*pio2_hi
; /* atan(-...,-INF) */
70 if (ex
+120 < ey
|| ey
== 0x7fff)
71 return m
&1 ? -pio2_hi
: pio2_hi
;
72 /* z = atan(|y/x|) without spurious underflow */
73 if ((m
&2) && ey
+120 < ex
) /* |y/x| < 0x1p-120, x<0 */
76 z
= atanl(fabsl(y
/x
));
78 case 0: return z
; /* atan(+,+) */
79 case 1: return -z
; /* atan(-,+) */
80 case 2: return 2*pio2_hi
-(z
-2*pio2_lo
); /* atan(+,-) */
82 return (z
-2*pio2_lo
)-2*pio2_hi
; /* atan(-,-) */