/**************************************************************************/
/*                                                                        */
/*                                 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: l_muld.c,v 1.2 1997/09/25 17:37:14 ae59 Exp $ */
/*
$Log: l_muld.c,v $
 * Revision 1.2  1997/09/25  17:37:14  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:23:24  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : l_muld.c                              */
/*                                                              */
/*      Entries         : multiprecision l_muld(i1,i2)          */
/*                        multiprecision i1,i2;                 */
/*                                                              */
/*      Description     : Muliplication of multi-precision      */
/*                        numbers with rounding downwards.      */
/*                                                              */
/*      Date            : 1990-11-22                            */
/*      1990-11-22 : E_TPUSH+E_TPOPP                            */
/*      1990-10-30 : temporary flag                             */
/*      1990-08-06 : explicit compare                           */
/*      1990-07-16 : LINT_ARGS prototype                        */
/****************************************************************/

#ifndef ALL_IN_ONE
#ifdef AIX
#include "/u/p88c/runtime/o_defs.h"
#else
#include "o_defs.h"
#endif
#define local
#endif

#ifdef LINT_ARGS
local multiprecision l_muld(multiprecision i1,multiprecision i2)
#else
local multiprecision l_muld(i1,i2)

multiprecision i1;
multiprecision i2;
#endif
        {
        int rc;
        multiprecision res1,res2;

        E_TPUSH("l_muld")

        l_init(&res1);

        if (res1==NULL)
                e_trap(ALLOCATION,2,E_TMSG,65);
        else
            {
            l_init(&res2);

            if (res2==NULL)
                e_trap(ALLOCATION,2,E_TMSG,65);
            else if ((rc = b_bmul(i1,i2,res1,res2))!=0)
                {
                switch(rc)
                   {
                   case OFLOW : e_trap(OVERFLOW,4,E_TMLT+E_TEXT(1),&i1,
                                                  E_TMLT+E_TEXT(2),&i2);
                                break;
                   case UFLOW : e_trap(UNDERFLOW,4,E_TMLT+E_TEXT(1),&i1,
                                                   E_TMLT+E_TEXT(2),&i2);
                                break;
                   case ALLOC : e_trap(ALLOCATION,2,E_TMSG,65);
                                break;
                   }
                }
            else
               {
               res1->f = 1;
               if (res1->s)
                  {
                  if ((rc = b_brnd(res1,res1))!=0)
                     {
                     switch(rc)
                        {
                   case OFLOW : e_trap(OVERFLOW,4,E_TMLT+E_TEXT(1),&i1,
                                                  E_TMLT+E_TEXT(2),&i2);
                                break;
                   case ALLOC : e_trap(ALLOCATION,2,E_TMSG,65);
                                break;
                        }
                     }
                  }
               }

            l_free(&res2);
            }

        if (i1->f) l_free(&i1);
        if (i2->f) l_free(&i2);

        E_TPOPP("l_muld")
        return(res1);
        }
