4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
27 * Use is subject to license terms.
34 * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
35 * 2. Reduce x to positive by (if x and y are unexceptional):
36 * ARG (x+iy) = arctan(y/x) ... if x > 0,
37 * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,
41 * ATAN2((anything), NaN ) is NaN;
42 * ATAN2(NAN , (anything) ) is NaN;
43 * ATAN2(+-0, +(anything but NaN)) is +-0 ;
44 * ATAN2(+-0, -(anything but NaN)) is +-PI ;
45 * ATAN2(+-(anything but 0 and NaN), 0) is +-PI/2;
46 * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
47 * ATAN2(+-(anything but INF and NaN), -INF) is +-PI;
48 * ATAN2(+-INF,+INF ) is +-PI/4 ;
49 * ATAN2(+-INF,-INF ) is +-3PI/4;
50 * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-PI/2;
53 * The hexadecimal values are the intended ones for the following constants.
54 * The decimal values may be used, provided that the compiler will convert
55 * from decimal to binary accurately enough to produce the hexadecimal values
59 #pragma weak __atan2l = atan2l
62 #include "longdouble.h"
64 static const long double
69 PI3o4
= 2.356194490192344928846982537459627163148L,
70 PIo4
= 0.785398163397448309615660845819875721049L,
71 PIo2
= 1.570796326794896619231321691639751442099L,
72 PI
= 3.141592653589793238462643383279502884197L,
73 PI_lo
= 8.671810130123781024797044026043351968762e-35L;
76 atan2l(long double y
, long double x
) {
78 int k
, m
, signy
, signx
;
81 return (x
+ y
); /* return NaN if x or y is NAN */
86 m
= signy
+ signx
+ signx
;
92 return (y
); /* atan(+0,+anything) */
94 return (y
); /* atan(-0,+anything) */
96 return (PI
+ tiny
); /* atan(+0,-anything) */
98 return (-PI
- tiny
); /* atan(-0,-anything) */
103 return (signy
== 1 ? -PIo2
- tiny
: PIo2
+ tiny
);
110 return (PIo4
+ tiny
); /* atan(+INF,+INF) */
112 return (-PIo4
- tiny
); /* atan(-INF,+INF) */
114 return (PI3o4
+ tiny
); /* atan(+INF,-INF) */
116 return (-PI3o4
- tiny
); /* atan(-INF,-INF) */
121 return (zero
); /* atan(+...,+INF) */
123 return (-zero
); /* atan(-...,+INF) */
125 return (PI
+ tiny
); /* atan(+...,-INF) */
127 return (-PI
- tiny
); /* atan(-...,-INF) */
133 return (signy
== 1 ? -PIo2
- tiny
: PIo2
+ tiny
);
139 k
= (ilogbl(y
) - ilogbl(x
));
143 else if (m
> 1 && k
< -120)
150 return (z
); /* atan(+,+) */
152 return (-z
); /* atan(-,+) */
154 return (PI
- (z
- t
)); /* atan(+,-) */
156 return ((z
- t
) - PI
); /* atan(-,-) */