e_atan2f.c revision 181062
10Sstevel@tonic-gate/* e_atan2f.c -- float version of e_atan2.c. 20Sstevel@tonic-gate * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 30Sstevel@tonic-gate */ 40Sstevel@tonic-gate 56223Sab196087/* 66223Sab196087 * ==================================================== 70Sstevel@tonic-gate * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * Developed at SunPro, a Sun Microsystems, Inc. business. 100Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this 110Sstevel@tonic-gate * software is freely granted, provided that this notice 120Sstevel@tonic-gate * is preserved. 130Sstevel@tonic-gate * ==================================================== 140Sstevel@tonic-gate */ 150Sstevel@tonic-gate 160Sstevel@tonic-gate#include <sys/cdefs.h> 170Sstevel@tonic-gate__FBSDID("$FreeBSD: head/lib/msun/src/e_atan2f.c 181062 2008-07-31 19:57:50Z das $"); 180Sstevel@tonic-gate 190Sstevel@tonic-gate#include "math.h" 200Sstevel@tonic-gate#include "math_private.h" 210Sstevel@tonic-gate 220Sstevel@tonic-gatestatic volatile float 230Sstevel@tonic-gatetiny = 1.0e-30; 246223Sab196087static const float 250Sstevel@tonic-gatezero = 0.0, 260Sstevel@tonic-gatepi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */ 270Sstevel@tonic-gatepi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */ 280Sstevel@tonic-gatepi = 3.1415927410e+00; /* 0x40490fdb */ 296223Sab196087static volatile float 300Sstevel@tonic-gatepi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */ 310Sstevel@tonic-gate 320Sstevel@tonic-gatefloat 336223Sab196087__ieee754_atan2f(float y, float x) 340Sstevel@tonic-gate{ 356223Sab196087 float z; 366223Sab196087 int32_t k,m,hx,hy,ix,iy; 376223Sab196087 386223Sab196087 GET_FLOAT_WORD(hx,x); 396223Sab196087 ix = hx&0x7fffffff; 400Sstevel@tonic-gate GET_FLOAT_WORD(hy,y); 410Sstevel@tonic-gate iy = hy&0x7fffffff; 420Sstevel@tonic-gate if((ix>0x7f800000)|| 436223Sab196087 (iy>0x7f800000)) /* x or y is NaN */ 440Sstevel@tonic-gate return x+y; 456223Sab196087 if(hx==0x3f800000) return atanf(y); /* x=1.0 */ 466223Sab196087 m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */ 476223Sab196087 480Sstevel@tonic-gate /* when y = 0 */ 496223Sab196087 if(iy==0) { 506223Sab196087 switch(m) { 516223Sab196087 case 0: 526223Sab196087 case 1: return y; /* atan(+-0,+anything)=+-0 */ 530Sstevel@tonic-gate case 2: return pi+tiny;/* atan(+0,-anything) = pi */ 540Sstevel@tonic-gate 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} 99