/**************************************************************************/
/*                                                                        */
/*                                 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_acth.c,v 1.2 1997/09/25 18:05:41 ae59 Exp $ */
/*
$Log: t_acth.c,v $
 * Revision 1.2  1997/09/25  18:05:41  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:57  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : t_acth.c                              */
/*                                                              */
/*      Entries         : a_real t_acth(arg)                    */
/*                        a_real arg;                           */
/*                                                              */
/*      Arguments       : arg  = argument of area cotangent     */
/*                                                              */
/*      Description     : Area cotangent function               */
/*                                                              */
/*      Date            : 1992-07-22                            */
/*      1992-07-22 : add sun4_cpp_c switch =b=                  */
/*      1992-05-11 : changed "10" to "sizeof(ExtReal)"          */
/*      1991-11-13 : save and restore flags                     */
/*      1991-09-24 : macro call StdFctReal replaced             */
/*      1991-09-17 : remove semicolon after makro               */
/*      1991-08-05 : remove unused variable ret                 */
/*      1991-06-21 : new routine                                */
/****************************************************************/

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

/* #include "acoth.h"      */
/* Teilpunkt               */
/* +8.000000000000000E+000 */
#define Tp                                 \
           EXTREAL(0x40, 0x02,             \
                   0x80, 0x00, 0x00, 0x00, \
                   0x00, 0x00, 0x00, 0x00)

/* StdFctReal(t_acth,acothee) */
#ifdef LINT_ARGS
a_real t_acth(a_real arg)
#else
a_real t_acth(arg)

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

        E_SPUSH("t_acth")

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

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

        setrndmode(rnd);

        E_SPOPP("t_acth")
        return res;
        }
/* ------------------------------------------------------------ */

/*----------------------------------------------------------------*
 | acothee                                                        |
 *----------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int acothee (const ExtReal *arg, ExtReal *res)
#else
int acothee (arg, res)
const ExtReal   *arg;
      ExtReal   *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int acothee (ExtReal *arg, ExtReal *res)
#else
int acothee (arg, res)
ExtReal   *arg;
ExtReal   *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
#ifdef ANSI_C
#if SUN4_CPP_C
   static ExtReal tp;
   static char tpc[sizeof(ExtReal)] = Tp;
#else
   static const ExtReal tp=Tp; /* Teilungspunkt = 8     */
#endif
#else
   static ExtReal tp;
   static char tpc[sizeof(ExtReal)] = Tp;
#endif
   ExtReal     radd;       /* Ergebnis arg + 1          */
   ExtReal     rsub;       /* Ergebnis arg - 1                  */
   ExtReal     rdiv;       /* Ergebnis radd / rsub              */
   ExtReal     rln;        /* Ergebnis ln                       */
   int         rnd;        /* RundungsMode                      */
   int         check;      /* Rueckgabe von Makro ArgCheck      */

#ifndef ANSI_C
   memcpy(&tp, tpc, sizeof(tp));
#else
#if SUN4_CPP_C
   memcpy(&tp, tpc, sizeof(tp));
#endif
#endif

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

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

   /* --- rsub = arg - 1 --- */
   subee(arg, &One, &rsub);

   /* --- |arg| <= Teilungspunkt --- */
   if(1!=cmpabsee(&rsub, &tp)) {
      addee(arg, &One, &radd);
      divee(&radd, &rsub, &rdiv);
      lnee(&rdiv, &rln);
   }
   /* --- |arg| > Teilungspunkt --- */
   else {
      divee(&Two, &rsub, &rdiv);
      lnp1ee(&rdiv, &rln);
   }

   /* --- res = 0.5*rln --- */
   scaliee(&rln, -1, res);

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

   return NoErr;
} /* acothee() */
