1 /* e_atan2f.c -- float version of e_atan2.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
13 * ====================================================
15 * $NetBSD: e_atan2f.c,v 1.7 2002/05/26 22:01:49 wiz Exp $
16 * $DragonFly: src/lib/libm/src/e_atan2f.c,v 1.1 2005/07/26 21:15:20 joerg Exp $
20 #include "math_private.h"
25 pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */
26 pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */
27 pi = 3.1415925026e+00, /* 0x40490fda */
28 pi_lo = 1.5099578832e-07; /* 0x34222168 */
31 atan2f(float y, float x)
34 int32_t k,m,hx,hy,ix,iy;
41 (iy>0x7f800000)) /* x or y is NaN */
43 if(hx==0x3f800000) return atanf(y); /* x=1.0 */
44 m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
50 case 1: return y; /* atan(+-0,+anything)=+-0 */
51 case 2: return pi+tiny;/* atan(+0,-anything) = pi */
52 case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
56 if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
62 case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
63 case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
64 case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
65 case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
69 case 0: return zero ; /* atan(+...,+INF) */
70 case 1: return -zero ; /* atan(-...,+INF) */
71 case 2: return pi+tiny ; /* atan(+...,-INF) */
72 case 3: return -pi-tiny ; /* atan(-...,-INF) */
77 if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
81 if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */
82 else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */
83 else z=atanf(fabsf(y/x)); /* safe to do y/x */
85 case 0: return z ; /* atan(+,+) */
89 SET_FLOAT_WORD(z,zh ^ 0x80000000);
91 return z ; /* atan(-,+) */
92 case 2: return pi-(z-pi_lo);/* atan(+,-) */
94 return (z-pi_lo)-pi;/* atan(-,-) */