1996-03-05 21:41:30 +00:00
|
|
|
/* e_atan2f.c -- float version of e_atan2.c.
|
|
|
|
* Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ====================================================
|
|
|
|
* Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Developed at SunPro, a Sun Microsystems, Inc. business.
|
|
|
|
* Permission to use, copy, modify, and distribute this
|
1997-07-22 00:10:33 +00:00
|
|
|
* software is freely granted, provided that this notice
|
1996-03-05 21:41:30 +00:00
|
|
|
* is preserved.
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
2012-03-09 19:29:16 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include <math_private.h>
|
1996-03-05 21:41:30 +00:00
|
|
|
|
1997-07-22 00:10:33 +00:00
|
|
|
static const float
|
1996-03-05 21:41:30 +00:00
|
|
|
tiny = 1.0e-30,
|
|
|
|
zero = 0.0,
|
1997-07-22 00:10:33 +00:00
|
|
|
pi_o_4 = 7.8539818525e-01, /* 0x3f490fdb */
|
|
|
|
pi_o_2 = 1.5707963705e+00, /* 0x3fc90fdb */
|
|
|
|
pi = 3.1415927410e+00, /* 0x40490fdb */
|
2005-07-20 18:02:49 +00:00
|
|
|
pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */
|
1996-03-05 21:41:30 +00:00
|
|
|
|
2011-10-12 15:27:51 +00:00
|
|
|
float
|
|
|
|
__ieee754_atan2f (float y, float x)
|
1997-07-22 00:10:33 +00:00
|
|
|
{
|
1996-03-05 21:41:30 +00:00
|
|
|
float z;
|
|
|
|
int32_t k,m,hx,hy,ix,iy;
|
|
|
|
|
|
|
|
GET_FLOAT_WORD(hx,x);
|
|
|
|
ix = hx&0x7fffffff;
|
|
|
|
GET_FLOAT_WORD(hy,y);
|
|
|
|
iy = hy&0x7fffffff;
|
|
|
|
if((ix>0x7f800000)||
|
|
|
|
(iy>0x7f800000)) /* x or y is NaN */
|
|
|
|
return x+y;
|
Sat Mar 16 20:08:22 1996 David Mosberger-Tang <davidm@azstarnet.com>
* sysdeps/alpha/memchr.S: new file.
* sysdeps/alpha/memchr.c: obsolete file removed.
Sat Mar 16 16:26:09 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu>
* misc/Makefile (headers): Add sysexits.h.
* misc/sysexits.h: New file.
Thu Mar 14 15:20:45 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/libm-ieee754/e_atan2.c (__ieee754_atan2): Change atan
call to __atan.
* sysdeps/libm-ieee754/e_atan2f.c (__ieee754_atan2f): Change atanf
call to __atanf.
* sysdeps/m68k/fpu/e_acos.c, sysdeps/m68k/fpu/e_acosf.c,
sysdeps/m68k/fpu/e_asin.c, sysdeps/m68k/fpu/e_asinf.c,
sysdeps/m68k/fpu/e_atanh.c, sysdeps/m68k/fpu/e_atanhf.c,
sysdeps/m68k/fpu/e_cosh.c, sysdeps/m68k/fpu/e_coshf.c,
sysdeps/m68k/fpu/e_exp.c, sysdeps/m68k/fpu/e_expf.c,
sysdeps/m68k/fpu/e_fmod.c, sysdeps/m68k/fpu/e_fmodf.c,
sysdeps/m68k/fpu/e_log.c, sysdeps/m68k/fpu/e_log10.c,
sysdeps/m68k/fpu/e_log10f.c, sysdeps/m68k/fpu/e_logf.c,
sysdeps/m68k/fpu/e_pow.c, sysdeps/m68k/fpu/e_powf.c,
sysdeps/m68k/fpu/e_remainder.c, sysdeps/m68k/fpu/e_remainderf.c,
sysdeps/m68k/fpu/e_scalb.c, sysdeps/m68k/fpu/e_scalbf.c,
sysdeps/m68k/fpu/e_sinh.c, sysdeps/m68k/fpu/e_sinhf.c,
sysdeps/m68k/fpu/e_sqrt.c, sysdeps/m68k/fpu/e_sqrtf.c,
sysdeps/m68k/fpu/k_cos.c, sysdeps/m68k/fpu/k_cosf.c,
sysdeps/m68k/fpu/k_sin.c, sysdeps/m68k/fpu/k_sinf.c,
sysdeps/m68k/fpu/k_tan.c, sysdeps/m68k/fpu/k_tanf.c,
sysdeps/m68k/fpu/s_atan.c, sysdeps/m68k/fpu/s_atanf.c,
sysdeps/m68k/fpu/s_ceil.c, sysdeps/m68k/fpu/s_ceilf.c,
sysdeps/m68k/fpu/s_cos.c, sysdeps/m68k/fpu/s_cosf.c,
sysdeps/m68k/fpu/s_expm1.c, sysdeps/m68k/fpu/s_expm1f.c,
sysdeps/m68k/fpu/s_fabs.c, sysdeps/m68k/fpu/s_fabsf.c,
sysdeps/m68k/fpu/s_finite.c, sysdeps/m68k/fpu/s_finitef.c,
sysdeps/m68k/fpu/s_floor.c, sysdeps/m68k/fpu/s_floorf.c,
sysdeps/m68k/fpu/s_frexp.c, sysdeps/m68k/fpu/s_frexpf.c,
sysdeps/m68k/fpu/s_ilogb.c, sysdeps/m68k/fpu/s_ilogbf.c,
sysdeps/m68k/fpu/s_isinf.c, sysdeps/m68k/fpu/s_isinff.c,
sysdeps/m68k/fpu/s_isnan.c, sysdeps/m68k/fpu/s_isnanf.c,
sysdeps/m68k/fpu/s_ldexp.c, sysdeps/m68k/fpu/s_ldexpf.c,
sysdeps/m68k/fpu/s_log1p.c, sysdeps/m68k/fpu/s_log1pf.c,
sysdeps/m68k/fpu/s_logb.c, sysdeps/m68k/fpu/s_logbf.c,
sysdeps/m68k/fpu/s_modf.c, sysdeps/m68k/fpu/s_modff.c,
sysdeps/m68k/fpu/s_rint.c, sysdeps/m68k/fpu/s_rintf.c,
sysdeps/m68k/fpu/s_scalbn.c, sysdeps/m68k/fpu/s_scalbnf.c,
sysdeps/m68k/fpu/s_significand.c,
sysdeps/m68k/fpu/s_significandf.c, sysdeps/m68k/fpu/s_sin.c,
sysdeps/m68k/fpu/s_sinf.c, sysdeps/m68k/fpu/s_tan.c,
sysdeps/m68k/fpu/s_tanf.c, sysdeps/m68k/fpu/s_tanh.c,
sysdeps/m68k/fpu/s_tanhf.c: New files, for m68881 port of fdlibm.
* sysdeps/m68k/fpu/__math.h: Rewritten for fdlibm.
* sysdeps/m68k/fpu/isinfl.c: Rewritten to get argument type right.
* sysdeps/m68k/fpu/isnanl.c: Likewise.
Thu Mar 14 06:01:07 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu>
* posix/glob.c (glob): In GLOB_BRACE brace expansion, fix buffer size
calculation to include trailing invariant portion. Don't use alloca;
instead use a dynamic auto array for GCC, malloc for non-GCC.
Handle nested braces properly.
* elf/elf.h (Elf32_auxv_t): Specify prototype (void) for `a_un.a_fcn'.
* libc-symbols.h (lint): New macro.
Fri Mar 15 01:18:00 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* libio/iosetvbuf.c: Add weak alias setvbuf.
1996-03-17 01:58:17 +00:00
|
|
|
if(hx==0x3f800000) return __atanf(y); /* x=1.0 */
|
1996-03-05 21:41:30 +00:00
|
|
|
m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
|
|
|
|
|
|
|
|
/* when y = 0 */
|
|
|
|
if(iy==0) {
|
|
|
|
switch(m) {
|
1997-07-22 00:10:33 +00:00
|
|
|
case 0:
|
2011-10-12 15:27:51 +00:00
|
|
|
case 1: return y; /* atan(+-0,+anything)=+-0 */
|
1996-03-05 21:41:30 +00:00
|
|
|
case 2: return pi+tiny;/* atan(+0,-anything) = pi */
|
|
|
|
case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* when x = 0 */
|
|
|
|
if(ix==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
1997-07-22 00:10:33 +00:00
|
|
|
|
1996-03-05 21:41:30 +00:00
|
|
|
/* when x is INF */
|
|
|
|
if(ix==0x7f800000) {
|
|
|
|
if(iy==0x7f800000) {
|
|
|
|
switch(m) {
|
|
|
|
case 0: return pi_o_4+tiny;/* atan(+INF,+INF) */
|
|
|
|
case 1: return -pi_o_4-tiny;/* atan(-INF,+INF) */
|
|
|
|
case 2: return (float)3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
|
|
|
|
case 3: return (float)-3.0*pi_o_4-tiny;/*atan(-INF,-INF)*/
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch(m) {
|
|
|
|
case 0: return zero ; /* atan(+...,+INF) */
|
|
|
|
case 1: return -zero ; /* atan(-...,+INF) */
|
|
|
|
case 2: return pi+tiny ; /* atan(+...,-INF) */
|
|
|
|
case 3: return -pi-tiny ; /* atan(-...,-INF) */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* when y is INF */
|
|
|
|
if(iy==0x7f800000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
|
|
|
|
|
|
|
/* compute y/x */
|
|
|
|
k = (iy-ix)>>23;
|
2011-10-12 15:27:51 +00:00
|
|
|
if(k > 60) z=pi_o_2+(float)0.5*pi_lo; /* |y/x| > 2**60 */
|
|
|
|
else if(hx<0&&k<-60) z=0.0; /* |y|/x < -2**60 */
|
Sat Mar 16 20:08:22 1996 David Mosberger-Tang <davidm@azstarnet.com>
* sysdeps/alpha/memchr.S: new file.
* sysdeps/alpha/memchr.c: obsolete file removed.
Sat Mar 16 16:26:09 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu>
* misc/Makefile (headers): Add sysexits.h.
* misc/sysexits.h: New file.
Thu Mar 14 15:20:45 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* sysdeps/libm-ieee754/e_atan2.c (__ieee754_atan2): Change atan
call to __atan.
* sysdeps/libm-ieee754/e_atan2f.c (__ieee754_atan2f): Change atanf
call to __atanf.
* sysdeps/m68k/fpu/e_acos.c, sysdeps/m68k/fpu/e_acosf.c,
sysdeps/m68k/fpu/e_asin.c, sysdeps/m68k/fpu/e_asinf.c,
sysdeps/m68k/fpu/e_atanh.c, sysdeps/m68k/fpu/e_atanhf.c,
sysdeps/m68k/fpu/e_cosh.c, sysdeps/m68k/fpu/e_coshf.c,
sysdeps/m68k/fpu/e_exp.c, sysdeps/m68k/fpu/e_expf.c,
sysdeps/m68k/fpu/e_fmod.c, sysdeps/m68k/fpu/e_fmodf.c,
sysdeps/m68k/fpu/e_log.c, sysdeps/m68k/fpu/e_log10.c,
sysdeps/m68k/fpu/e_log10f.c, sysdeps/m68k/fpu/e_logf.c,
sysdeps/m68k/fpu/e_pow.c, sysdeps/m68k/fpu/e_powf.c,
sysdeps/m68k/fpu/e_remainder.c, sysdeps/m68k/fpu/e_remainderf.c,
sysdeps/m68k/fpu/e_scalb.c, sysdeps/m68k/fpu/e_scalbf.c,
sysdeps/m68k/fpu/e_sinh.c, sysdeps/m68k/fpu/e_sinhf.c,
sysdeps/m68k/fpu/e_sqrt.c, sysdeps/m68k/fpu/e_sqrtf.c,
sysdeps/m68k/fpu/k_cos.c, sysdeps/m68k/fpu/k_cosf.c,
sysdeps/m68k/fpu/k_sin.c, sysdeps/m68k/fpu/k_sinf.c,
sysdeps/m68k/fpu/k_tan.c, sysdeps/m68k/fpu/k_tanf.c,
sysdeps/m68k/fpu/s_atan.c, sysdeps/m68k/fpu/s_atanf.c,
sysdeps/m68k/fpu/s_ceil.c, sysdeps/m68k/fpu/s_ceilf.c,
sysdeps/m68k/fpu/s_cos.c, sysdeps/m68k/fpu/s_cosf.c,
sysdeps/m68k/fpu/s_expm1.c, sysdeps/m68k/fpu/s_expm1f.c,
sysdeps/m68k/fpu/s_fabs.c, sysdeps/m68k/fpu/s_fabsf.c,
sysdeps/m68k/fpu/s_finite.c, sysdeps/m68k/fpu/s_finitef.c,
sysdeps/m68k/fpu/s_floor.c, sysdeps/m68k/fpu/s_floorf.c,
sysdeps/m68k/fpu/s_frexp.c, sysdeps/m68k/fpu/s_frexpf.c,
sysdeps/m68k/fpu/s_ilogb.c, sysdeps/m68k/fpu/s_ilogbf.c,
sysdeps/m68k/fpu/s_isinf.c, sysdeps/m68k/fpu/s_isinff.c,
sysdeps/m68k/fpu/s_isnan.c, sysdeps/m68k/fpu/s_isnanf.c,
sysdeps/m68k/fpu/s_ldexp.c, sysdeps/m68k/fpu/s_ldexpf.c,
sysdeps/m68k/fpu/s_log1p.c, sysdeps/m68k/fpu/s_log1pf.c,
sysdeps/m68k/fpu/s_logb.c, sysdeps/m68k/fpu/s_logbf.c,
sysdeps/m68k/fpu/s_modf.c, sysdeps/m68k/fpu/s_modff.c,
sysdeps/m68k/fpu/s_rint.c, sysdeps/m68k/fpu/s_rintf.c,
sysdeps/m68k/fpu/s_scalbn.c, sysdeps/m68k/fpu/s_scalbnf.c,
sysdeps/m68k/fpu/s_significand.c,
sysdeps/m68k/fpu/s_significandf.c, sysdeps/m68k/fpu/s_sin.c,
sysdeps/m68k/fpu/s_sinf.c, sysdeps/m68k/fpu/s_tan.c,
sysdeps/m68k/fpu/s_tanf.c, sysdeps/m68k/fpu/s_tanh.c,
sysdeps/m68k/fpu/s_tanhf.c: New files, for m68881 port of fdlibm.
* sysdeps/m68k/fpu/__math.h: Rewritten for fdlibm.
* sysdeps/m68k/fpu/isinfl.c: Rewritten to get argument type right.
* sysdeps/m68k/fpu/isnanl.c: Likewise.
Thu Mar 14 06:01:07 1996 Roland McGrath <roland@charlie-brown.gnu.ai.mit.edu>
* posix/glob.c (glob): In GLOB_BRACE brace expansion, fix buffer size
calculation to include trailing invariant portion. Don't use alloca;
instead use a dynamic auto array for GCC, malloc for non-GCC.
Handle nested braces properly.
* elf/elf.h (Elf32_auxv_t): Specify prototype (void) for `a_un.a_fcn'.
* libc-symbols.h (lint): New macro.
Fri Mar 15 01:18:00 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* libio/iosetvbuf.c: Add weak alias setvbuf.
1996-03-17 01:58:17 +00:00
|
|
|
else z=__atanf(fabsf(y/x)); /* safe to do y/x */
|
1996-03-05 21:41:30 +00:00
|
|
|
switch (m) {
|
|
|
|
case 0: return z ; /* atan(+,+) */
|
|
|
|
case 1: {
|
2011-10-12 15:27:51 +00:00
|
|
|
u_int32_t zh;
|
1996-03-05 21:41:30 +00:00
|
|
|
GET_FLOAT_WORD(zh,z);
|
|
|
|
SET_FLOAT_WORD(z,zh ^ 0x80000000);
|
|
|
|
}
|
|
|
|
return z ; /* atan(-,+) */
|
|
|
|
case 2: return pi-(z-pi_lo);/* atan(+,-) */
|
|
|
|
default: /* case 3 */
|
2011-10-12 15:27:51 +00:00
|
|
|
return (z-pi_lo)-pi;/* atan(-,-) */
|
1996-03-05 21:41:30 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-12 15:27:51 +00:00
|
|
|
strong_alias (__ieee754_atan2f, __atan2f_finite)
|