/**************************************************************************/
/*                                                                        */
/*                                 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_exp2.c,v 1.2 1997/09/25 18:13:46 ae59 Exp $ */
/*
$Log: t_exp2.c,v $
 * Revision 1.2  1997/09/25  18:13:46  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:25:22  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : t_exp2.c                              */
/*                                                              */
/*      Entries         : a_real t_exp2(arg)                    */
/*                        a_real arg;                           */
/*                                                              */
/*      Arguments       : arg  = argument of exponential        */
/*                                                              */
/*      Description     : 2**x                                  */
/*                                                              */
/*      Date            : 1992-07-23                            */
/*      1992-07-23 : add sun4_cpp_c =b=                         */
/*      1992-07-03 : removed {} from ln2  defininition =b=      */
/*      1992-05-11 : changed "10" to "sizeof(ExtReal)"          */
/*      1992-02-07 : 25: del ,after )=b=                        */
/*      1992-01-21 : new routine                                */
/****************************************************************/
 
#ifdef AIX
#include "/u/p88c/runtime/tbyte/t_defs.h"
#else
#include "t_defs.h"
#endif
 
#define ln2                  /* ln(2)   */ \
           EXTREAL(0x3F, 0xFE,              \
                   0xB1, 0x72, 0x17, 0xF7,  \
                   0xD1, 0xCF, 0x79, 0xAB)  
/* --- Ende ln(2) Konstante --- */
/* ln(2) = 0.6931471805599453094172321214581765680755001...   */
/*  ->F7 17 72 B1   AB 79 CF D1   98 B3 E3 C9 INTEL Darst.!!! */
 
/*--------------------------------------------------------------*
 | exp2(x) = 2**x  = exp(x*ln(2))      Punktroutine             |
 *--------------------------------------------------------------*/
#ifdef ANSI_C
#ifdef LINT_ARGS
int t_2exp(const ExtReal *arg, ExtReal *res)
#else
int t_2exp(arg, res)
const ExtReal   *arg;
      ExtReal   *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int t_2exp(ExtReal *arg, ExtReal *res)
#else
int t_2exp(arg, res)
ExtReal   *arg;
ExtReal   *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
   int         rnd;        /* RundungsMode                       */
   int         ret;        /* Rueckgabe                          */
   int         check;      /* Rueckgabe von Makro ArgCheck       */
#ifdef ANSI_C
#if SUN4_CPP_C
static ExtReal logcnst;
static char    logvalue[sizeof(ExtReal)] = ln2;
 
memcpy(&logcnst,logvalue,sizeof(logcnst));
#else
static const ExtReal logcnst = ln2;
#endif
#else
static ExtReal logcnst;
static char    logvalue[sizeof(ExtReal)] = ln2;
 
memcpy(&logcnst,logvalue,sizeof(logcnst));
#endif
   /* --- pruefe Argument --- */
   ArgCheck1(Exp, arg, res);
 
   /* --- RundungsMode sichern, NEAR setzen --- */
   rnd  = getrndmode();
   setrndmode(NEAR);
 
   /* --- exp2() --- */
   mulee(arg, &logcnst, arg);   /* x = x*ln(2) */
   ret = (expee(arg, res) != 0);
 
   /* --- RundungsMode zuruecksetzen --- */
   setrndmode(rnd);
 
   return ret;
} /* exp2() */


#ifdef LINT_ARGS
a_real t_exp2(a_real arg)
#else
a_real t_exp2(arg)
a_real arg;
#endif
        {
        int      rnd, rc;
        a_real   res;
        ExtReal  a, r;
 
        E_SPUSH("t_exp2")
 
        rnd = getrndmode();
        longreal_to_extreal((LongReal *)&arg, &a);
 
        if ((rc = t_2exp(&a, &r))!=0
            || (rc = extreal_to_longreal(&r, (LongReal *)&res))!=0)
           ieee_abortr1(rc, &arg);
 
        setrndmode(rnd);
 
        E_SPOPP("t_exp2")
        return res;
        }
/* ------------------------------------------------------------ */
 
