1996-03-06 05:41:30 +08:00
|
|
|
/* @(#)e_atan2.c 5.1 93/09/24 */
|
|
|
|
/*
|
|
|
|
* ====================================================
|
|
|
|
* 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
|
|
|
|
* software is freely granted, provided that this notice
|
|
|
|
* is preserved.
|
|
|
|
* ====================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(LIBM_SCCS) && !defined(lint)
|
|
|
|
static char rcsid[] = "$NetBSD: e_atan2.c,v 1.8 1995/05/10 20:44:51 jtc Exp $";
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* __ieee754_atan2(y,x)
|
|
|
|
* Method :
|
|
|
|
* 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x).
|
|
|
|
* 2. Reduce x to positive by (if x and y are unexceptional):
|
|
|
|
* ARG (x+iy) = arctan(y/x) ... if x > 0,
|
|
|
|
* ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0,
|
|
|
|
*
|
|
|
|
* Special cases:
|
|
|
|
*
|
|
|
|
* ATAN2((anything), NaN ) is NaN;
|
|
|
|
* ATAN2(NAN , (anything) ) is NaN;
|
|
|
|
* ATAN2(+-0, +(anything but NaN)) is +-0 ;
|
|
|
|
* ATAN2(+-0, -(anything but NaN)) is +-pi ;
|
|
|
|
* ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2;
|
|
|
|
* ATAN2(+-(anything but INF and NaN), +INF) is +-0 ;
|
|
|
|
* ATAN2(+-(anything but INF and NaN), -INF) is +-pi;
|
|
|
|
* ATAN2(+-INF,+INF ) is +-pi/4 ;
|
|
|
|
* ATAN2(+-INF,-INF ) is +-3pi/4;
|
|
|
|
* ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2;
|
|
|
|
*
|
|
|
|
* Constants:
|
|
|
|
* The hexadecimal values are the intended ones for the following
|
|
|
|
* constants. The decimal values may be used, provided that the
|
|
|
|
* compiler will convert from decimal to binary accurately enough
|
|
|
|
* to produce the hexadecimal values shown.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "math.h"
|
|
|
|
#include "math_private.h"
|
|
|
|
|
|
|
|
#ifdef __STDC__
|
|
|
|
static const double
|
|
|
|
#else
|
|
|
|
static double
|
|
|
|
#endif
|
|
|
|
tiny = 1.0e-300,
|
|
|
|
zero = 0.0,
|
|
|
|
pi_o_4 = 7.8539816339744827900E-01, /* 0x3FE921FB, 0x54442D18 */
|
|
|
|
pi_o_2 = 1.5707963267948965580E+00, /* 0x3FF921FB, 0x54442D18 */
|
|
|
|
pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */
|
|
|
|
pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */
|
|
|
|
|
|
|
|
#ifdef __STDC__
|
|
|
|
double __ieee754_atan2(double y, double x)
|
|
|
|
#else
|
|
|
|
double __ieee754_atan2(y,x)
|
|
|
|
double y,x;
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
double z;
|
|
|
|
int32_t k,m,hx,hy,ix,iy;
|
|
|
|
u_int32_t lx,ly;
|
|
|
|
|
|
|
|
EXTRACT_WORDS(hx,lx,x);
|
|
|
|
ix = hx&0x7fffffff;
|
|
|
|
EXTRACT_WORDS(hy,ly,y);
|
|
|
|
iy = hy&0x7fffffff;
|
|
|
|
if(((ix|((lx|-lx)>>31))>0x7ff00000)||
|
|
|
|
((iy|((ly|-ly)>>31))>0x7ff00000)) /* x or y is NaN */
|
|
|
|
return x+y;
|
1998-11-27 19:34:40 +08:00
|
|
|
if(((hx-0x3ff00000)|lx)==0) return __atan(y); /* x=1.0 */
|
1996-03-06 05:41:30 +08:00
|
|
|
m = ((hy>>31)&1)|((hx>>30)&2); /* 2*sign(x)+sign(y) */
|
|
|
|
|
|
|
|
/* when y = 0 */
|
|
|
|
if((iy|ly)==0) {
|
|
|
|
switch(m) {
|
|
|
|
case 0:
|
|
|
|
case 1: return y; /* atan(+-0,+anything)=+-0 */
|
|
|
|
case 2: return pi+tiny;/* atan(+0,-anything) = pi */
|
|
|
|
case 3: return -pi-tiny;/* atan(-0,-anything) =-pi */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* when x = 0 */
|
|
|
|
if((ix|lx)==0) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
|
|
|
|
|
|
|
/* when x is INF */
|
|
|
|
if(ix==0x7ff00000) {
|
|
|
|
if(iy==0x7ff00000) {
|
|
|
|
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 3.0*pi_o_4+tiny;/*atan(+INF,-INF)*/
|
|
|
|
case 3: return -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==0x7ff00000) return (hy<0)? -pi_o_2-tiny: pi_o_2+tiny;
|
|
|
|
|
|
|
|
/* 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 */
|
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 09:58:17 +08:00
|
|
|
else z=__atan(fabs(y/x)); /* safe to do y/x */
|
1996-03-06 05:41:30 +08:00
|
|
|
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 2: return pi-(z-pi_lo);/* atan(+,-) */
|
|
|
|
default: /* case 3 */
|
|
|
|
return (z-pi_lo)-pi;/* atan(-,-) */
|
|
|
|
}
|
|
|
|
}
|