1/* e_atan2f.c -- float version of e_atan2.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3 */
4
5/*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
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 * ====================================================
14 */
15
16#include <math.h>
17#include <math_private.h>
18#include <libm-alias-finite.h>
19
20static const float
21tiny = 1.0e-30,
22zero = 0.0,
23pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */
24pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */
25pi = 3.1415927410e+00, /* 0x40490fdb */
26pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */
27
28float
29__ieee754_atan2f (float y, float x)
30{
31 float z;
32 int32_t k,m,hx,hy,ix,iy;
33
34 GET_FLOAT_WORD(hx,x);
35 ix = hx&0x7fffffff;
36 GET_FLOAT_WORD(hy,y);
37 iy = hy&0x7fffffff;
38 if((ix>0x7f800000)||
39 (iy>0x7f800000)) /* x or y is NaN */
40 return x+y;
41 if(hx==0x3f800000) return __atanf(y); /* x=1.0 */
42 m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
43
44 /* when y = 0 */
45 if(iy==0) {
46 switch(m) {
47 case 0:
48 case 1: return y; /* atan(+-0,+anything)=+-0 */
49 case 2: return pi+tiny;/* atan(+0,-anything) = pi */
50 case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
51 }
52 }
53 /* when x = 0 */
54 if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
55
56 /* when x is INF */
57 if(ix==0x7f800000) {
58 if(iy==0x7f800000) {
59 switch(m) {
60 case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
61 case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
62 case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
63 case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
64 }
65 } else {
66 switch(m) {
67 case 0: return zero ; /* atan(+...,+INF) */
68 case 1: return -zero ; /* atan(-...,+INF) */
69 case 2: return pi+tiny ; /* atan(+...,-INF) */
70 case 3: return -pi-tiny ; /* atan(-...,-INF) */
71 }
72 }
73 }
74 /* when y is INF */
75 if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
76
77 /* compute y/x */
78 k = (iy-ix)>>23;
79 if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */
80 else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */
81 else z=__atanf(fabsf(y/x)); /* safe to do y/x */
82 switch (m) {
83 case 0: return z ; /* atan(+,+) */
84 case 1: {
85 uint32_t zh;
86 GET_FLOAT_WORD(zh,z);
87 SET_FLOAT_WORD(z,zh ^ 0x80000000);
88 }
89 return z ; /* atan(-,+) */
90 case 2: return pi-(z-pi_lo);/* atan(+,-) */
91 default: /* case 3 */
92 return (z-pi_lo)-pi;/* atan(-,-) */
93 }
94}
95libm_alias_finite (__ieee754_atan2f, __atan2f)
96