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