xref: /titanic_51/usr/src/lib/libm/common/R/atan2pif.c (revision ddc0e0b53c661f6e439e3b7072b3ef353eadb4af)
1*25c28e83SPiotr Jasiukajtis /*
2*25c28e83SPiotr Jasiukajtis  * CDDL HEADER START
3*25c28e83SPiotr Jasiukajtis  *
4*25c28e83SPiotr Jasiukajtis  * The contents of this file are subject to the terms of the
5*25c28e83SPiotr Jasiukajtis  * Common Development and Distribution License (the "License").
6*25c28e83SPiotr Jasiukajtis  * You may not use this file except in compliance with the License.
7*25c28e83SPiotr Jasiukajtis  *
8*25c28e83SPiotr Jasiukajtis  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*25c28e83SPiotr Jasiukajtis  * or http://www.opensolaris.org/os/licensing.
10*25c28e83SPiotr Jasiukajtis  * See the License for the specific language governing permissions
11*25c28e83SPiotr Jasiukajtis  * and limitations under the License.
12*25c28e83SPiotr Jasiukajtis  *
13*25c28e83SPiotr Jasiukajtis  * When distributing Covered Code, include this CDDL HEADER in each
14*25c28e83SPiotr Jasiukajtis  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*25c28e83SPiotr Jasiukajtis  * If applicable, add the following below this CDDL HEADER, with the
16*25c28e83SPiotr Jasiukajtis  * fields enclosed by brackets "[]" replaced with your own identifying
17*25c28e83SPiotr Jasiukajtis  * information: Portions Copyright [yyyy] [name of copyright owner]
18*25c28e83SPiotr Jasiukajtis  *
19*25c28e83SPiotr Jasiukajtis  * CDDL HEADER END
20*25c28e83SPiotr Jasiukajtis  */
21*25c28e83SPiotr Jasiukajtis /*
22*25c28e83SPiotr Jasiukajtis  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
23*25c28e83SPiotr Jasiukajtis  */
24*25c28e83SPiotr Jasiukajtis /*
25*25c28e83SPiotr Jasiukajtis  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26*25c28e83SPiotr Jasiukajtis  * Use is subject to license terms.
27*25c28e83SPiotr Jasiukajtis  */
28*25c28e83SPiotr Jasiukajtis 
29*25c28e83SPiotr Jasiukajtis #include "libm.h"
30*25c28e83SPiotr Jasiukajtis 
31*25c28e83SPiotr Jasiukajtis static const double invpi = 0.3183098861837906715377675;
32*25c28e83SPiotr Jasiukajtis 
33*25c28e83SPiotr Jasiukajtis float
34*25c28e83SPiotr Jasiukajtis atan2pif(float y, float x) {
35*25c28e83SPiotr Jasiukajtis 	int	ix, iy, hx, hy;
36*25c28e83SPiotr Jasiukajtis 
37*25c28e83SPiotr Jasiukajtis 	ix = *(int *)&x;
38*25c28e83SPiotr Jasiukajtis 	iy = *(int *)&y;
39*25c28e83SPiotr Jasiukajtis 	hx = ix & ~0x80000000;
40*25c28e83SPiotr Jasiukajtis 	hy = iy & ~0x80000000;
41*25c28e83SPiotr Jasiukajtis 	if (hx > 0x7f800000 || hy > 0x7f800000) /* x or y is nan */
42*25c28e83SPiotr Jasiukajtis 		return (x * y);
43*25c28e83SPiotr Jasiukajtis 	if ((hx | hy) == 0) {
44*25c28e83SPiotr Jasiukajtis 		/* x and y are both zero */
45*25c28e83SPiotr Jasiukajtis 		if (ix == 0)
46*25c28e83SPiotr Jasiukajtis 			return (y);
47*25c28e83SPiotr Jasiukajtis 		return ((iy == 0)? 1.0f : -1.0f);
48*25c28e83SPiotr Jasiukajtis 	}
49*25c28e83SPiotr Jasiukajtis 	return ((float)(invpi * atan2((double)y, (double)x)));
50*25c28e83SPiotr Jasiukajtis }
51