1 /* ef_atan2.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 * ====================================================
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 */
32 float __ieee754_atan2f(float y
, float x
)
34 float __ieee754_atan2f(y
,x
)
39 __int32_t k
,m
,hx
,hy
,ix
,iy
;
45 if(FLT_UWORD_IS_NAN(ix
)||
46 FLT_UWORD_IS_NAN(iy
)) /* x or y is NaN */
48 if(hx
==0x3f800000) return atanf(y
); /* x=1.0 */
49 m
= ((hy
>>31)&1)|((hx
>>30)&2); /* 2*sign(x)+sign(y) */
52 if(FLT_UWORD_IS_ZERO(iy
)) {
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 */
61 if(FLT_UWORD_IS_ZERO(ix
)) return (hy
<0)? -pi_o_2
-tiny
: pi_o_2
+tiny
;
64 if(FLT_UWORD_IS_INFINITE(ix
)) {
65 if(FLT_UWORD_IS_INFINITE(iy
)) {
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)*/
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) */
82 if(FLT_UWORD_IS_INFINITE(iy
)) return (hy
<0)? -pi_o_2
-tiny
: pi_o_2
+tiny
;
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 */
90 case 0: return z
; /* atan(+,+) */
94 SET_FLOAT_WORD(z
,zh
^ 0x80000000);
96 return z
; /* atan(-,+) */
97 case 2: return pi
-(z
-pi_lo
);/* atan(+,-) */
99 return (z
-pi_lo
)-pi
;/* atan(-,-) */