diff options
author | das <das@FreeBSD.org> | 2008-08-02 19:17:00 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2008-08-02 19:17:00 +0000 |
commit | 9df7b1ac5c081557d761b1e0135a16f782e21354 (patch) | |
tree | 8dd9dc5eefc364756dc4b562e48e374a77b63581 /lib/msun/src | |
parent | ddf87cb1a8b2c7d47271b84b2ec340c96163187f (diff) | |
download | FreeBSD-src-9df7b1ac5c081557d761b1e0135a16f782e21354.zip FreeBSD-src-9df7b1ac5c081557d761b1e0135a16f782e21354.tar.gz |
A few minor corrections, including some from bde:
- When y/x is huge, it's faster and more accurate to return pi/2
instead of pi - pi/2.
- There's no need for 3 lines of bit fiddling to compute -z.
- Fix a comment.
Diffstat (limited to 'lib/msun/src')
-rw-r--r-- | lib/msun/src/e_atan2.c | 14 | ||||
-rw-r--r-- | lib/msun/src/e_atan2f.c | 14 | ||||
-rw-r--r-- | lib/msun/src/e_atan2l.c | 5 |
3 files changed, 16 insertions, 17 deletions
diff --git a/lib/msun/src/e_atan2.c b/lib/msun/src/e_atan2.c index 399822a..a4a985b 100644 --- a/lib/msun/src/e_atan2.c +++ b/lib/msun/src/e_atan2.c @@ -109,17 +109,15 @@ __ieee754_atan2(double y, double x) /* compute y/x */ k = (iy-ix)>>20; - if(k > 60) z=pi_o_2+0.5*pi_lo; /* |y/x| > 2**60 */ - else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ + if(k > 60) { /* |y/x| > 2**60 */ + z=pi_o_2+0.5*pi_lo; + m&=1; + } + else if(hx<0&&k<-60) z=0.0; /* 0 > |y|/x > -2**-60 */ else z=atan(fabs(y/x)); /* safe to do y/x */ switch (m) { case 0: return z ; /* atan(+,+) */ - case 1: { - u_int32_t zh; - GET_HIGH_WORD(zh,z); - SET_HIGH_WORD(z,zh ^ 0x80000000); - } - return z ; /* atan(-,+) */ + case 1: return -z ; /* atan(-,+) */ case 2: return pi-(z-pi_lo);/* atan(+,-) */ default: /* case 3 */ return (z-pi_lo)-pi;/* atan(-,-) */ diff --git a/lib/msun/src/e_atan2f.c b/lib/msun/src/e_atan2f.c index a48ada1..3b6818a 100644 --- a/lib/msun/src/e_atan2f.c +++ b/lib/msun/src/e_atan2f.c @@ -80,17 +80,15 @@ __ieee754_atan2f(float y, float x) /* compute y/x */ k = (iy-ix)>>23; - if(k > 26) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**26 */ - else if(hx<0&&k<-26) z=0.0; /* |y|/x < -2**26 */ + if(k > 26) { /* |y/x| > 2**26 */ + z=pi_o_2+(float)0.5*pi_lo; + m&=1; + } + else if(hx<0&&k<-26) z=0.0; /* 0 > |y|/x > -2**-26 */ else z=atanf(fabsf(y/x)); /* safe to do y/x */ switch (m) { case 0: return z ; /* atan(+,+) */ - case 1: { - u_int32_t zh; - GET_FLOAT_WORD(zh,z); - SET_FLOAT_WORD(z,zh ^ 0x80000000); - } - return z ; /* atan(-,+) */ + case 1: return -z ; /* atan(-,+) */ case 2: return pi-(z-pi_lo);/* atan(+,-) */ default: /* case 3 */ return (z-pi_lo)-pi;/* atan(-,-) */ diff --git a/lib/msun/src/e_atan2l.c b/lib/msun/src/e_atan2l.c index 0071a7c..0326482 100644 --- a/lib/msun/src/e_atan2l.c +++ b/lib/msun/src/e_atan2l.c @@ -104,7 +104,10 @@ atan2l(long double y, long double x) /* compute y/x */ k = expty-exptx; - if(k > LDBL_MANT_DIG+2) z=pio2_hi+pio2_lo; /* |y/x| huge */ + if(k > LDBL_MANT_DIG+2) { /* |y/x| huge */ + z=pio2_hi+pio2_lo; + m&=1; + } else if(expsignx<0&&k<-LDBL_MANT_DIG-2) z=0.0; /* |y/x| tiny, x<0 */ else z=atanl(fabsl(y/x)); /* safe to do y/x */ switch (m) { |