/**************************************************************************/
/*                                                                        */
/*                                 Sources                                */
/*                                from  the                               */
/*                           XSC SOFTWARE PACKAGE                         */
/*                                                                        */
/*                Copyright (c) 1997 University of Karlsruhe              */
/*                     Institute for Appl. Mathematics                    */
/*                                                                        */
/* This program is free software for non-commercial use. For details, see */
/* the file LICENSE.XSC, distributed with this software package.          */
/*                                                                        */
/* This program is distributed WITHOUT ANY WARRANTY. For details, see the */
/* file LICENSE.XSC, distributed with this software package.              */
/*                                                                        */
/**************************************************************************/

/* RCS $Id: t_acos.c,v 1.2 1997/09/25 18:05:13 ae59 Exp $ */
/*
$Log: t_acos.c,v $
 * Revision 1.2  1997/09/25  18:05:13  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:56  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : t_acos.c                              */
/*                                                              */
/*      Entries         : a_real t_acos(arg)                    */
/*                        a_real arg;                           */
/*                                                              */
/*      Arguments       : arg  = argument of arcus cosine       */
/*                                                              */
/*      Description     : Arcus cosine function                 */
/*                                                              */
/*      Date            : 1991-11-13                            */
/*      1991-11-13 : flags saved and restored                   */
/*      1991-09-24 : macro call StdFctReal replaced             */
/*      1991-09-17 : remove semicolon after makro               */
/*      1991-08-05 : remove unused variable r                   */
/*      1991-06-21 : new routine                                */
/****************************************************************/

#ifdef AIX
#include "/u/p88c/runtime/tbyte/t_defs.h"
#else
#include "t_defs.h"
#endif

/* StdFctReal(t_acos,acosee) */

#ifdef LINT_ARGS
a_real t_acos(a_real arg)
#else
a_real t_acos(arg)

a_real arg;
#endif
        {
        int      rnd, rc;
        a_real   res;
        ExtReal  a, r;

        E_SPUSH("t_acos")

        rnd = getrndmode();
        longreal_to_extreal((LongReal *)&arg, &a);

        if ((rc = acosee(&a, &r))!=0
            || (rc = extreal_to_longreal(&r, (LongReal *)&res))!=0)
           ieee_abortr1(rc, &arg);

        setrndmode(rnd);

        E_SPOPP("t_acos")
        return res;
        }

/* ------------------------------------------------------------ */

/*--------------------------------------------------------------*
 | Punkt Arcus Cosinus                                          |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int acosee (const ExtReal *arg, ExtReal *res)
#else
int acosee (arg, res)
const ExtReal *arg;
      ExtReal *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int acosee (ExtReal *arg, ExtReal *res)
#else
int acosee (arg, res)
ExtReal *arg;
ExtReal *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   ExtReal     a;          /* absolutes Argument                */
   int         sgn;        /* Vorzeichen des Arguments          */
   int         rnd;        /* RundungsMode                      */
   int         ret;        /* Rueckgabe                         */
   int         check;      /* Rueckgabe von Makro ArgCheck      */

   /* --- pruefe Argument --- */
   ArgCheck1(Acos, arg, res);

   /* --- RundungsMode sichern, NEAR setzen --- */
   rnd  = getrndmode();
   setrndmode(NEAR);

   /* --- a = |arg|, sgn = Vorzeichen --- */
   sgn = SGNE(arg);
   absee(arg, &a);

   /* --- Arcus Cosinus --- */
   if(0==cmpee(arg, &Zero))
      ret = copyee(&PiHalf, res);
   else {
      ret = acosviatan(&a, res);
      if (sgn == NEG)
         subee(&Pi, res, res);
   }

   /* --- RundungsMode zuruecksetzen --- */
   setrndmode(rnd);

   return ret;
} /* acosee() */
