/**************************************************************************/
/*                                                                        */
/*                                 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_deml.c,v 1.2 1997/09/25 18:10:43 ae59 Exp $ */
/*
$Log: t_deml.c,v $
 * Revision 1.2  1997/09/25  18:10:43  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:25:13  ae59
 * Put under RCS control
 *
 */
/************************************************************************
 * Fuer Reduktion exp()                                                 * 
 * mul ExtReal mit doppelt langem 1/ln(2)=ld(e)=LdE, res DReal          * 
 * res DReal, nur ca. 90 Bit genau:                                     * 
 *  Laenge mant(ExtReal) + Laenge mant(int(maximales Argument exp2())) =* 
 *           64         +           13                = 77              * 
 * mul au al                                                            * 
 *  b0 r0 r1                                                            * 
 *  b1 r2 r3        bi = ld(e)                                          * 
 *  b2 r4           res = sum(ri)                                       * 
 *                                                                      *
 *    Date : 1992-07-23                                                 *
 *    1992-07-23 : add sun4_cpp_c =b=                                   *
 ************************************************************************
 */
#ifdef AIX
#include "/u/p88c/runtime/tbyte/t_ddev.h"
#else
#include "t_ddev.h"
#endif

#ifdef ANSI_C
#ifdef LINT_ARGS
int mulLdE(const ExtReal *arg, DReal *res)
#else
int mulLdE(arg, res)
const ExtReal   *arg;
      DReal     *res;
#endif /* LINT_ARGS */
#else  /* NOT ANSI_C */
#ifdef LINT_ARGS
int mulLdE(ExtReal *arg, DReal *res)
#else
int mulLdE(arg, res)
ExtReal   *arg;
DReal     *res;
#endif /* LINT_ARGS */
#endif /* ANSI_C */
{
#define Log2e {                 /* 1/ln(2)=ld(e):                   */ \
           EXTREAL(0x3F, 0xFF,                                         \
                   0xB8, 0xAA, 0x3B, 0x29,                             \
                   0x00, 0x00, 0x00, 0x00), /* +1.442695040721446E+000 */ \
           EXTREAL(0x3F, 0xDE,                                         \
                   0xB8, 0x2F, 0xE1, 0x76,                             \
                   0x00, 0x00, 0x00, 0x00), /* +1.675171315681720E-010 */ \
           EXTREAL(0x3F, 0xBF,                                         \
                   0xBE, 0x87, 0xFE, 0xD0,                             \
                   0x00, 0x00, 0x00, 0x00)  /* +8.069311544173407E-020 */ \
} /* Log2e */

/* "1.71547 652B8 2FE17 77D0F
      FDA0D 23A7D 11D6A EF551 BAD2B 4B116 4A2CD 9A342 648FB C3887 EE$+0";*/
#ifdef ANSI_C
#if SUN4_CPP_C
   static ExtReal LdE[3];
   static char LdEc[3][sizeof(ExtReal)] = Log2e;
#else
   static ExtReal LdE[3]   = Log2e;
#endif
#else
   static ExtReal LdE[3];
   static char LdEc[3][sizeof(ExtReal)] = Log2e;
#endif
   ExtReal   r[5];
   ExtReal   au;
   ExtReal   al;
   DReal     d;
   register int   i;

#ifndef ANSI_C
   {
      int i;
      for (i=0; i<3; i++)
         memcpy(&(LdE[i]), LdEc[i], sizeof(LdE[0]));
   }
#else
#if SUN4_CPP_C
   {
      int i;
      for (i=0; i<3; i++)
         memcpy(&(LdE[i]), LdEc[i], sizeof(LdE[0]));
   }
#endif
#endif

   msplitee(arg, &au, &al);

   for (i=0; i<2; i++) {
     mulee (&au, &LdE[i], &r[2*i]);
     mulee (&al, &LdE[i], &r[2*i+1]);
   }
   mulee (&au, &LdE[2], &r[4]);

   initd(res);

   for (i=0; i<5; i++) {
      if (0!=cmpee(&r[i], &Zero)) {
         extreal_to_dreal(&r[i], &d);
         adddd(&d, res, res);
      }
   }

   return NoErr;
} /* mulLdE() */
