/**************************************************************************/
/*                                                                        */
/*                                 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_acsh.c,v 1.2 1997/09/25 18:05:32 ae59 Exp $ */
/*
$Log: t_acsh.c,v $
 * Revision 1.2  1997/09/25  18:05:32  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:24:57  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : t_acsh.c                              */
/*                                                              */
/*      Entries         : a_real t_acsh(arg)                    */
/*                        a_real arg;                           */
/*                                                              */
/*      Arguments       : arg  = argument of area cosine hyp.   */
/*                                                              */
/*      Description     : Area cosine hyp. function             */
/*                                                              */
/*      Date            : 1992-07-22                            */
/*      1992-07-22 : add SUN4_CPP_c =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-06-21 : new routine                                */
/****************************************************************/

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

/* #include "acosh.h"      */
/* Teilungspunkt           */
/* +1.025000000000000E+000 */
#define Tp  EXTREAL(0x3F, 0xFF, 0x83, 0x33, 0x33, 0x33,  \
                    0x33, 0x33, 0x33, 0x34)

/* StdFctReal(t_acsh,acoshee) */
#ifdef LINT_ARGS
a_real t_acsh(a_real arg)
#else
a_real t_acsh(arg)

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

        E_SPUSH("t_acsh")

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

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

        setrndmode(rnd);

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

/*--------------------------------------------------------------*
 | acoshee                                                      |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int acoshee (const ExtReal *arg, ExtReal *res)
#else
int acoshee (arg, res)
const ExtReal   *arg;
      ExtReal   *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int acoshee (ExtReal *arg, ExtReal *res)
#else
int acoshee (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 1.025           */
#endif
#else
   static ExtReal tp;
   static char tpc[sizeof(ExtReal)] = Tp;
#endif
   ExtReal     am1;        /* Argument - 1                      */
   ExtReal     ap1;        /* Argument + 1                      */
   ExtReal     a2m1;       /* Argumetn**2 - 1                   */
   ExtReal     rsqrt;      /* Ergebnis Sqrt                     */
   ExtReal     radd;       /* Ergebnis Add                      */
   int         rnd;        /* RundungsMode                      */
   int         ret;        /* Rueckgabe                         */
   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(Acosh, arg, res);

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

   /* --- sqrt(arg**2-1) --- */
   subee(arg, &One, &am1);
   addee(arg, &One, &ap1);
   mulee(&am1, &ap1, &a2m1);
   sqrtee(&a2m1, &rsqrt);

   /* --- arg >= Teilungspunkt --- */
   if(-1!=cmpee(arg, &tp)) {
      /* --- acosh = ln(arg+rsqrt) --- */
      addee(arg, &rsqrt, &radd);
      ret = lnee(&radd, res);
   }
   /* --- |arg| < Teilungspunkt --- */
   else {
      /* --- acosh = lnp1(am1+rsqrt) --- */
      addee(&am1, &rsqrt, &radd);
      ret = lnp1ee(&radd, res);
   }

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

   return ret ;
} /* acoshee() */
