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 * ====================================================
17 static char rcsid
[] = "$FreeBSD: src/lib/msun/src/e_atan2f.c,v 1.12 2008/08/03 17:39:54 das Exp $";
21 #include "math_private.h"
23 static const volatile float
24 tiny
__attribute__ ((__section__(".rodata,\"a\" " SECTIONCOMMENT
))) = 1.0e-30;
27 pi_o_4
= 7.8539818525e-01, /* 0x3f490fdb */
28 pi_o_2
= 1.5707963705e+00, /* 0x3fc90fdb */
29 pi
= 3.1415927410e+00; /* 0x40490fdb */
30 static const volatile float
31 pi_lo
__attribute__ ((__section__(".rodata,\"a\" " SECTIONCOMMENT
))) = -8.7422776573e-08; /* 0xb3bbbd2e */
34 __ieee754_atan2f(float y
, float x
)
37 int32_t k
,m
,hx
,hy
,ix
,iy
;
44 (iy
>0x7f800000)) /* x or y is NaN */
46 if(hx
==0x3f800000) return atanf(y
); /* x=1.0 */
47 m
= ((hy
>>31)&1)|((hx
>>30)&2); /* 2*sign(x)+sign(y) */
53 case 1: return y
; /* atan(+-0,+anything)=+-0 */
54 case 2: return pi
+tiny
;/* atan(+0,-anything) = pi */
55 case 3: return -pi
-tiny
;/* atan(-0,-anything) =-pi */
59 if(ix
==0) return (hy
<0)? -pi_o_2
-tiny
: pi_o_2
+tiny
;
65 case 0: return pi_o_4
+tiny
;/* atan(+INF,+INF) */
66 case 1: return -pi_o_4
-tiny
;/* atan(-INF,+INF) */
67 case 2: return (float)3.0*pi_o_4
+tiny
;/*atan(+INF,-INF)*/
68 case 3: return (float)-3.0*pi_o_4
-tiny
;/*atan(-INF,-INF)*/
72 case 0: return zero
; /* atan(+...,+INF) */
73 case 1: return -zero
; /* atan(-...,+INF) */
74 case 2: return pi
+tiny
; /* atan(+...,-INF) */
75 case 3: return -pi
-tiny
; /* atan(-...,-INF) */
80 if(iy
==0x7f800000) return (hy
<0)? -pi_o_2
-tiny
: pi_o_2
+tiny
;
84 if(k
> 26) { /* |y/x| > 2**26 */
85 z
=pi_o_2
+(float)0.5*pi_lo
;
88 else if(k
<-26&&hx
<0) z
=0.0; /* 0 > |y|/x > -2**-26 */
89 else z
=atanf(fabsf(y
/x
)); /* safe to do y/x */
91 case 0: return z
; /* atan(+,+) */
92 case 1: return -z
; /* atan(-,+) */
93 case 2: return pi
-(z
-pi_lo
);/* atan(+,-) */
95 return (z
-pi_lo
)-pi
;/* atan(-,-) */