/* RCS $Id: q_acos.c,v 1.2 1997/07/15 14:57:04 ae13 Exp $ */
/*
$Log: q_acos.c,v $
 * Revision 1.2  1997/07/15  14:57:04  ae13
 * *** empty log message ***
 *
 * Revision 1.1  1997/05/16  13:29:06  ae13
 * Initial revision
 *
 */
/****************************************************************/
/*                                                              */
/*      Entries         : a_real q_acos(a_real x)               */
/*                        a_real x  ;                           */
/*                                                              */
/*      Arguments       : x = real argument of acos(x)          */
/*                                                              */
/*      Description     : Fast real arcus cosine function       */
/*                        for double IEEE Floating-Point        */
/*                        Arithmetic                            */
/*                                                              */
/*      Date            : 1997-03-10                            */
/*                                                              */
/*      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_acos(double x)
#else
local double q_acos(x)

double x;
#endif
{
  double res;

#ifdef PXSCTRAP
  E_SPUSH("q_acos");
#endif
  if NANTEST(x)                                       /* Test: x=NaN */
    res=q_abortnan(INV_ARG,&x,15);
  else {
  /* main program with different cases */
    if ((x<-1.0)||(1.0<x))                            /* check argument */
       res=q_abortr1(INV_ARG,&x,15);
    else if ((-1e-17<x)&(x<1e-17)) res=q_piha;
    else if (x<0) res=q_pi+q_atn1(sqrt((1+x)*(1-x))/x);
    else          res=     q_atn1(sqrt((1+x)*(1-x))/x); 
  }
#ifdef PXSCTRAP
  E_SPOPP("q_acos");
#endif
  return(res);
}

