e_atan2f.c revision 97407
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 97407 2002-05-28 17:03:12Z alfred $"; 182116Sjkh#endif 192116Sjkh 202116Sjkh#include "math.h" 212116Sjkh#include "math_private.h" 222116Sjkh 238870Srgrimesstatic const float 242116Sjkhtiny = 1.0e-30, 252116Sjkhzero = 0.0, 262116Sjkhpi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */ 272116Sjkhpi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */ 282116Sjkhpi = 3.1415925026e+00, /* 0x40490fda */ 292116Sjkhpi_lo = 1.5099578832e-07; /* 0x34222168 */ 302116Sjkh 3197407Salfredfloat 3297407Salfred__ieee754_atan2f(float y, float x) 338870Srgrimes{ 342116Sjkh float z; 352116Sjkh int32_t k,m,hx,hy,ix,iy; 362116Sjkh 372116Sjkh GET_FLOAT_WORD(hx,x); 382116Sjkh ix = hx&0x7fffffff; 392116Sjkh GET_FLOAT_WORD(hy,y); 402116Sjkh iy = hy&0x7fffffff; 412116Sjkh if((ix>0x7f800000)|| 422116Sjkh (iy>0x7f800000)) /* x or y is NaN */ 432116Sjkh return x+y; 442116Sjkh if(hx==0x3f800000) return atanf(y); /* x=1.0 */ 452116Sjkh m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ 462116Sjkh 472116Sjkh /* when y = 0 */ 482116Sjkh if(iy==0) { 492116Sjkh switch(m) { 508870Srgrimes case 0: 512116Sjkh case 1: return y; /* atan(+-0,+anything)=+-0 */ 522116Sjkh case 2: return pi+tiny;/* atan(+0,-anything) = pi */ 532116Sjkh case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */ 542116Sjkh } 552116Sjkh } 562116Sjkh /* when x = 0 */ 572116Sjkh if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; 588870Srgrimes 592116Sjkh /* when x is INF */ 602116Sjkh if(ix==0x7f800000) { 612116Sjkh if(iy==0x7f800000) { 622116Sjkh switch(m) { 632116Sjkh case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */ 642116Sjkh case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */ 652116Sjkh case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/ 662116Sjkh case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/ 672116Sjkh } 682116Sjkh } else { 692116Sjkh switch(m) { 702116Sjkh case 0: return zero ; /* atan(+...,+INF) */ 712116Sjkh case 1: return -zero ; /* atan(-...,+INF) */ 722116Sjkh case 2: return pi+tiny ; /* atan(+...,-INF) */ 732116Sjkh case 3: return -pi-tiny ; /* atan(-...,-INF) */ 742116Sjkh } 752116Sjkh } 762116Sjkh } 772116Sjkh /* when y is INF */ 782116Sjkh if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny; 792116Sjkh 802116Sjkh /* compute y/x */ 812116Sjkh k = (iy-ix)>>23; 822116Sjkh if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */ 832116Sjkh else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */ 842116Sjkh else z=atanf(fabsf(y/x)); /* safe to do y/x */ 852116Sjkh switch (m) { 862116Sjkh case 0: return z ; /* atan(+,+) */ 872116Sjkh case 1: { 882116Sjkh u_int32_t zh; 892116Sjkh GET_FLOAT_WORD(zh,z); 902116Sjkh SET_FLOAT_WORD(z,zh ^ 0x80000000); 912116Sjkh } 922116Sjkh return z ; /* atan(-,+) */ 932116Sjkh case 2: return pi-(z-pi_lo);/* atan(+,-) */ 942116Sjkh default: /* case 3 */ 952116Sjkh return (z-pi_lo)-pi;/* atan(-,-) */ 962116Sjkh } 972116Sjkh} 98