e_atan2f.c revision 50476
12116Sjkh/* e_atan2f.c -- float version of e_atan2.c. 22116Sjkh * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 32116Sjkh */ 42116Sjkh 52116Sjkh/* 62116Sjkh * ==================================================== 72116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 82116Sjkh * 92116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business. 102116Sjkh * Permission to use, copy, modify, and distribute this 118870Srgrimes * software is freely granted, provided that this notice 122116Sjkh * is preserved. 132116Sjkh * ==================================================== 142116Sjkh */ 152116Sjkh 162116Sjkh#ifndef lint 1750476Speterstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/e_atan2f.c 50476 1999-08-28 00:22:10Z peter $"; 182116Sjkh#endif 192116Sjkh 202116Sjkh#include "math.h" 212116Sjkh#include "math_private.h" 222116Sjkh 232116Sjkh#ifdef __STDC__ 248870Srgrimesstatic const float 252116Sjkh#else 268870Srgrimesstatic float 272116Sjkh#endif 282116Sjkhtiny = 1.0e-30, 292116Sjkhzero = 0.0, 302116Sjkhpi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */ 312116Sjkhpi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */ 322116Sjkhpi = 3.1415925026e+00, /* 0x40490fda */ 332116Sjkhpi_lo = 1.5099578832e-07; /* 0x34222168 */ 342116Sjkh 352116Sjkh#ifdef __STDC__ 362116Sjkh float __ieee754_atan2f(float y, float x) 372116Sjkh#else 382116Sjkh float __ieee754_atan2f(y,x) 392116Sjkh float y,x; 402116Sjkh#endif 418870Srgrimes{ 422116Sjkh float z; 432116Sjkh int32_t k,m,hx,hy,ix,iy; 442116Sjkh 452116Sjkh GET_FLOAT_WORD(hx,x); 462116Sjkh ix = hx&0x7fffffff; 472116Sjkh GET_FLOAT_WORD(hy,y); 482116Sjkh iy = hy&0x7fffffff; 492116Sjkh if((ix>0x7f800000)|| 502116Sjkh (iy>0x7f800000)) /* x or y is NaN */ 512116Sjkh return x+y; 522116Sjkh if(hx==0x3f800000) return atanf(y); /* x=1.0 */ 532116Sjkh m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ 542116Sjkh 552116Sjkh /* when y = 0 */ 562116Sjkh if(iy==0) { 572116Sjkh switch(m) { 588870Srgrimes case 0: 592116Sjkh case 1: return y; /* atan(+-0,+anything)=+-0 */ 602116Sjkh case 2: return pi+tiny;/* atan(+0,-anything) = pi */ 612116Sjkh case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ 622116Sjkh } 632116Sjkh } 642116Sjkh /* when x = 0 */ 652116Sjkh if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; 668870Srgrimes 672116Sjkh /* when x is INF */ 682116Sjkh if(ix==0x7f800000) { 692116Sjkh if(iy==0x7f800000) { 702116Sjkh switch(m) { 712116Sjkh case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */ 722116Sjkh case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */ 732116Sjkh case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/ 742116Sjkh case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/ 752116Sjkh } 762116Sjkh } else { 772116Sjkh switch(m) { 782116Sjkh case 0: return zero ; /* atan(+...,+INF) */ 792116Sjkh case 1: return -zero ; /* atan(-...,+INF) */ 802116Sjkh case 2: return pi+tiny ; /* atan(+...,-INF) */ 812116Sjkh case 3: return -pi-tiny ; /* atan(-...,-INF) */ 822116Sjkh } 832116Sjkh } 842116Sjkh } 852116Sjkh /* when y is INF */ 862116Sjkh if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; 872116Sjkh 882116Sjkh /* compute y/x */ 892116Sjkh k = (iy-ix)>>23; 902116Sjkh if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */ 912116Sjkh else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ 922116Sjkh else z=atanf(fabsf(y/x)); /* safe to do y/x */ 932116Sjkh switch (m) { 942116Sjkh case 0: return z ; /* atan(+,+) */ 952116Sjkh case 1: { 962116Sjkh u_int32_t zh; 972116Sjkh GET_FLOAT_WORD(zh,z); 982116Sjkh SET_FLOAT_WORD(z,zh ^ 0x80000000); 992116Sjkh } 1002116Sjkh return z ; /* atan(-,+) */ 1012116Sjkh case 2: return pi-(z-pi_lo);/* atan(+,-) */ 1022116Sjkh default: /* case 3 */ 1032116Sjkh return (z-pi_lo)-pi;/* atan(-,-) */ 1042116Sjkh } 1052116Sjkh} 106