Branch data Line data Source code
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 "cdefs-compat.h"
17 : : //__FBSDID("$FreeBSD: src/lib/msun/src/e_atan2f.c,v 1.12 2008/08/03 17:39:54 das Exp $");
18 : :
19 : : #include <openlibm_math.h>
20 : :
21 : : #include "math_private.h"
22 : :
23 : : static volatile float
24 : : tiny = 1.0e-30;
25 : : static const float
26 : : zero = 0.0,
27 : : pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */
28 : : pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */
29 : : pi = 3.1415927410e+00; /* 0x40490fdb */
30 : : static volatile float
31 : : pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */
32 : :
33 : : OLM_DLLEXPORT float
34 : 30 : __ieee754_atan2f(float y, float x)
35 : : {
36 : : float z;
37 : : int32_t k,m,hx,hy,ix,iy;
38 : :
39 : 30 : GET_FLOAT_WORD(hx,x);
40 : 30 : ix = hx&0x7fffffff;
41 : 30 : GET_FLOAT_WORD(hy,y);
42 : 30 : iy = hy&0x7fffffff;
43 [ + + - + ]: 30 : if((ix>0x7f800000)||
44 : : (iy>0x7f800000)) /* x or y is NaN */
45 : 1 : return x+y;
46 [ + + ]: 29 : if(hx==0x3f800000) return atanf(y); /* x=1.0 */
47 : 23 : m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
48 : :
49 : : /* when y = 0 */
50 [ + + ]: 23 : if(iy==0) {
51 [ + + + - ]: 6 : switch(m) {
52 : 2 : case 0:
53 : 2 : case 1: return y; /* atan(+-0,+anything)=+-0 */
54 : 2 : case 2: return pi+tiny;/* atan(+0,-anything) = pi */
55 : 2 : case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
56 : : }
57 : : }
58 : : /* when x = 0 */
59 [ + + + + ]: 17 : if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
60 : :
61 : : /* when x is INF */
62 [ + + ]: 13 : if(ix==0x7f800000) {
63 [ + + ]: 8 : if(iy==0x7f800000) {
64 [ + + + + : 4 : switch(m) {
- ]
65 : 1 : case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
66 : 1 : case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
67 : 1 : case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
68 : 1 : case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
69 : : }
70 : : } else {
71 [ + + + + : 4 : switch(m) {
- ]
72 : 1 : case 0: return zero ; /* atan(+...,+INF) */
73 : 1 : case 1: return -zero ; /* atan(-...,+INF) */
74 : 1 : case 2: return pi+tiny ; /* atan(+...,-INF) */
75 : 1 : case 3: return -pi-tiny ; /* atan(-...,-INF) */
76 : : }
77 : : }
78 : : }
79 : : /* when y is INF */
80 [ + + - + ]: 5 : if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
81 : :
82 : : /* compute y/x */
83 : 4 : k = (iy-ix)>>23;
84 [ - + ]: 4 : if(k > 26) { /* |y/x| > 2**26 */
85 : 0 : z=pi_o_2+(float)0.5*pi_lo;
86 : 0 : m&=1;
87 : : }
88 [ - + - - ]: 4 : else if(k<-26&&hx<0) z=0.0; /* 0 > |y|/x > -2**-26 */
89 : 4 : else z=atanf(fabsf(y/x)); /* safe to do y/x */
90 [ + - + + ]: 4 : switch (m) {
91 : 1 : case 0: return z ; /* atan(+,+) */
92 : 0 : case 1: return -z ; /* atan(-,+) */
93 : 2 : case 2: return pi-(z-pi_lo);/* atan(+,-) */
94 : 1 : default: /* case 3 */
95 : 1 : return (z-pi_lo)-pi;/* atan(-,-) */
96 : : }
97 : : }
|