/* RCS $Id: q_atan.c,v 1.3 1997/06/24 10:09:05 ae13 Exp $ */
/*
$Log: q_atan.c,v $
 * Revision 1.3  1997/06/24  10:09:05  ae13
 * delete variable neg
 *
 * Revision 1.3  1997/06/24  10:09:05  ae13
 * delete variable neg
 *
 * Revision 1.2  1997/06/10  14:04:40  ae13
 * new approximation
 *
 */
/****************************************************************/
/*                                                              */
/*      Entries         : a_real q_atan(a_real x)               */
/*                        a_real x  ;                           */
/*                                                              */
/*      Arguments       : x = real argument of atan(x)          */
/*                                                              */
/*      Description     : Fast real arcus tangent function      */
/*                        for double IEEE Floating-Point        */
/*                        Arithmetic                            */
/*                                                              */
/*      Date            : 1997-06-23                            */
/*                                                              */
/*      Author          : W. Hofschuster                        */
/*                                                              */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
#endif


#include "q_defs.h"
#include "q_fcth.h"
#ifdef LINT_ARGS
local double q_atan(double x)
#else
local double q_atan(x)

double x;
#endif
{
  double res;
  double absx,ym,y,ysq;
  int    ind,sgn;

#ifdef PXSCTRAP
  E_SPUSH("q_atan");
#endif
  if NANTEST(x)
    res=q_abortnan(INV_ARG,&x,16);
  else {
     
    if (x<0) absx=-x; else absx=x;    
    if (absx<=q_atnt) res=x;
    else {
            if (absx<8) {sgn=1; ym=0;}
            else        {sgn=-1; ym=q_piha; absx=1/absx;}
          
            ind=0;
            while (absx>=q_atnb[ind+1]) ind+=1;
            y=(absx-q_atnc[ind])/(1+absx*q_atnc[ind]);    
            ysq=y*y; 
            res = (y+y*(ysq*(((((q_atnd[5]*ysq+q_atnd[4])
                  *ysq+q_atnd[3])*ysq+q_atnd[2])
                  *ysq+q_atnd[1])*ysq+q_atnd[0])))+q_atna[ind]; 
            if (x<0) res=-(res*sgn+ym);
            else     res= (res*sgn+ym);  
          }
  }
#ifdef PXSCTRAP
  E_SPOPP("q_atan");
#endif
  return(res);
}

