fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libm / math / ef_atan2.c
blob45b5acb0c7457f93c49154c7db8ae9eb85985e30
1 /* ef_atan2.c -- float version of e_atan2.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
5 /*
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
12 * is preserved.
13 * ====================================================
17 #include "fdlibm.h"
19 #ifdef __STDC__
20 static const float
21 #else
22 static float
23 #endif
24 tiny = 1.0e-30,
25 zero = 0.0,
26 pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */
27 pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */
28 pi = 3.1415925026e+00, /* 0x40490fda */
29 pi_lo = 1.5099578832e-07; /* 0x34222168 */
31 #ifdef __STDC__
32 float __ieee754_atan2f(float y, float x)
33 #else
34 float __ieee754_atan2f(y,x)
35 float y,x;
36 #endif
38 float z;
39 __int32_t k,m,hx,hy,ix,iy;
41 GET_FLOAT_WORD(hx,x);
42 ix = hx&0x7fffffff;
43 GET_FLOAT_WORD(hy,y);
44 iy = hy&0x7fffffff;
45 if(FLT_UWORD_IS_NAN(ix)||
46 FLT_UWORD_IS_NAN(iy)) /* x or y is NaN */
47 return x+y;
48 if(hx==0x3f800000) return atanf(y); /* x=1.0 */
49 m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
51 /* when y = 0 */
52 if(FLT_UWORD_IS_ZERO(iy)) {
53 switch(m) {
54 case 0:
55 case 1: return y; /* atan(+-0,+anything)=+-0 */
56 case 2: return pi+tiny;/* atan(+0,-anything) = pi */
57 case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
60 /* when x = 0 */
61 if(FLT_UWORD_IS_ZERO(ix)) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
63 /* when x is INF */
64 if(FLT_UWORD_IS_INFINITE(ix)) {
65 if(FLT_UWORD_IS_INFINITE(iy)) {
66 switch(m) {
67 case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
68 case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
69 case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
70 case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
72 } else {
73 switch(m) {
74 case 0: return zero ; /* atan(+...,+INF) */
75 case 1: return -zero ; /* atan(-...,+INF) */
76 case 2: return pi+tiny ; /* atan(+...,-INF) */
77 case 3: return -pi-tiny ; /* atan(-...,-INF) */
81 /* when y is INF */
82 if(FLT_UWORD_IS_INFINITE(iy)) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
84 /* compute y/x */
85 k = (iy-ix)>>23;
86 if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */
87 else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */
88 else z=atanf(fabsf(y/x)); /* safe to do y/x */
89 switch (m) {
90 case 0: return z ; /* atan(+,+) */
91 case 1: {
92 __uint32_t zh;
93 GET_FLOAT_WORD(zh,z);
94 SET_FLOAT_WORD(z,zh ^ 0x80000000);
96 return z ; /* atan(-,+) */
97 case 2: return pi-(z-pi_lo);/* atan(+,-) */
98 default: /* case 3 */
99 return (z-pi_lo)-pi;/* atan(-,-) */