/**************************************************************************/
/*                                                                        */
/*                                 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: b_exp_.c,v 1.2 1997/09/25 17:02:14 ae59 Exp $ */
/*
$Log: b_exp_.c,v $
 * Revision 1.2  1997/09/25  17:02:14  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:22  ae59
 * Put under RCS control
 *
 */
/*************************************************************************
 *                                                                       *
 * Descriptive Name : Lexp               Processor : C                   *
 *                                                                       *
 * Exponential Function for Multiple Precision Arithmetic                *
 * ======================================================                *
 *                                                                       *
 * Include files :  b_lari.h  - definitions for INTERN standard functions*
 *                                                                       *
 * Function value : int       - 0                                        *
 *                                                                       *
 * Argument Range :    All nonnegative numbers                           *
 * Result Range :      Nonnegative numbers                               *
 *                                                                       *
 * Used Functions :                                                      *
 *    expve           Computation of function value and error bound      *
 *    Lassign         Assignment of function value and number of ulp's   *
 *                                                                       *
 * Used Global INTERN Variables and Constants :                          *
 *    LhF, LhE        Used for debugging only                            *
 *                                                                       *
 * Used UNSIGNED Global Variables :                                      *
 *    Maxl            Length of INTERN Variables                         *
 *    Lcurrprec       Initial Length of INTERN Variables                 *
 *    Ldebug          Flag for printing additional information           *
 *                                                                       */
/*      Date            : 1991-09-09                            */
/*      1991-09-09 : reduce max. line length                    */
/*      1991-08-01 : INT_HPREC introduced                       *
 *      1991-07-29 : return 0 in case of underflow              *
 *      1990-09-04 : Larith.h replaced by b_lari.h              *
 *************************************************************************/

#define  Name        "Lexp"
#define  Main
        
#ifdef AIX
#include "/u/p88c/runtime/base/b_lari.h"
#else
#include "b_lari.h"
#endif

static char  *function = Name;
        
/****************************************************************
 * Algorithm                                                    *
 ****************************************************************/
        
#ifdef LINT_ARGS
int b_exp_(dynamic *xi,dynamic *ri)
#else
int b_exp_(xi,ri)

dynamic *xi;
dynamic *ri;
#endif
#define  LRoutine    "Lexp"
{
   extern dynamic Lone;
   extern a_btyp  Maxl;
   extern a_btyp  Lcurrprec;
   extern char    *Lroutine;
        
   int  rc;
#define poolvars  0

#ifdef Debug
   extern dynamic   LhF, LhE;
   extern int       Ldebug;
#endif
        
#ifdef Debug
   Ldebug -= 1;                 /* Diminish Debug Level         */
   if (Ldebug >= 0) printf("\n Entering Routine %s",LRoutine);
#endif


  /*----------------*
   | Initialization |
   *----------------*/

   Lroutine = function;
   Lcurrprec = Maxl;                    /* Save precision setting */
   rc = 0;
        
        
  /*----------------------------*
   | Check and Handle Case xi=0 |
   *----------------------------*/
        
   if (xi->z == 1) {
      if ((COPY_(&Lone,ri)) != 0)       /* ri = exp(0) = 1      */
         ERREXIT(rc,rc,0);
      ri->r = 0;                        /* Result exact         */
      EXIT(0);
      }

        
  /*-------------------------------------*
   | Check and Handle Undefined Mantissa |
   *-------------------------------------*/
        
   if (xi->m[0] == 0) {
      ERREXIT(NANDE,NANDE,0);   /* Error message and handling       */
      }
        
   rc  = expve(xi);             /* Function value and error bound   */
   if (rc != 0)
      {
      if (rc != UFLOW)
         ERREXIT(0,RESUL,0)     /* Error message and handling       */
      else {
         ri->z = 1;             /* Set result 0                 */
         ri->s = 0;             /* Set sign to positive         */
         ri->r = 1;             /* Set rounding bit to 1 ulp    */
         ERREXIT(0,0,0);        /* Error message and handling   */
         }
      }
        
#if INT_HPREC
   b_case = (xi->s) ? LESS_ABS_ONE : GREATER_ABS_ONE;
#endif

   ASSIGN_(ri);                 /* Assign result and ulp's          */

#ifdef Debug
   if (Ldebug >= 0) {
      printf("\n  (Lexp 139) LhF    = ");  Lprinti(&LhF);
      printf("\n  (Lexp 140) LhE    = ");  Lprinti(&LhE);
      printf("\n  (Lexp 141) Result = ");  Lprinti(ri);
      printf("   (+ %d ulp)",ri->r);
      }
#endif
        
   RETURN(0);
}
        
        
        
