/**************************************************************************/
/*                                                                        */
/*                                 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: mulbody.h,v 1.2 1997/09/25 16:44:09 ae59 Exp $ */
/*
$Log: mulbody.h,v $
 * Revision 1.2  1997/09/25  16:44:09  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:23:36  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : mulbody.h                             */
/*                                                              */
/*      Description     : Multiplication of IEEE numbers.       */
/*                                                              */
/*      Notes           : included by r_mul,r_muld,r_mulu       */
/*                                                              */
/*      Date            : 1991-11-11                            */
/*      1991-11-11 : product 0*NaN,Nan*real handles correctly   */
/*      1991-04-23 : MANT_INFINITY() used                       */
/*      1991-04-15 : apply b_prod()                             */
/*      1991-01-07 : SIGNALING macro introduced/union q removed */
/*      1990-11-16 : E_TPUSH+E_TPOPP                            */
/*      1990-11-12 : INV_OP                                     */
/****************************************************************/

                /* a = infinity or NaN                          */
                if (expoa==EXPO_MAX+1) {

                   /* a = infinity                              */
                   if (MANT_INFINITY(manta)) {

                      /* b = zero                               */
                      if (zerob) {
                         e_trap(INV_OP+E_IEEE,8,E_TMSG,10,
                                                E_TDBL+E_TEXT(1),&a,
                                                E_TDBL+E_TEXT(2),&b,
                                                E_TRES+E_TDBL,&a);
                         E_TPOPP("mulbody")
                         return(a);
                         }

                      /* b = infinity or NaN                    */
                      if (expob==EXPO_MAX+1) {

                         /* a = b = infinity                    */
                         if (MANT_INFINITY(mantb)) {
                            if (vza!=vzc) b_comp(&a,expoa,manta,vzc);
                            E_TPOPP("mulbody")
                            return(a);
                            }

                         /* a = infinity b = NaN                */
                         if (SIGNALING(mantb[0]))
                            e_trap(INV_OP+E_IEEE,8,E_TMSG,5,
                                                   E_TDBL+E_TEXT(1),&a,
                                                   E_TDBL+E_TEXT(2),&b,
                                                   E_TRES+E_TDBL,&b);
                         E_TPOPP("mulbody")
                         return(b);
                         }

                      /* multiplication with infinity => a      */
                      if (vza!=vzc) b_comp(&a,expoa,manta,vzc);
                      E_TPOPP("mulbody")
                      return(a);
                      }

                   /* a = NaN                                   */
                   else {
                      if (SIGNALING(manta[0]))
                         e_trap(INV_OP+E_IEEE,8,E_TMSG,5,
                                                E_TDBL+E_TEXT(1),&a,
                                                E_TDBL+E_TEXT(2),&b,
                                                E_TRES+E_TDBL,&a);

                      if (expob>EXPO_MAX && !MANT_INFINITY(mantb) && 
                          SIGNALING(mantb[0]))
                         {
                         e_trap(INV_OP+E_IEEE,8,E_TMSG,5,
                                                E_TDBL+E_TEXT(1),&a,
                                                E_TDBL+E_TEXT(2),&b,
                                                E_TRES+E_TDBL,&b);
                         E_TPOPP("mulbody")
                         return(b);
                         }

                      E_TPOPP("mulbody")
                      return(a);
                      }
                   }

                /* b = infinity or NaN                          */
                else {

                   /* b = infinity                             */
                   if (MANT_INFINITY(mantb)) {

                      /* a = zero                                  */
                      if (zeroa) {
                         e_trap(INV_OP+E_IEEE,8,E_TMSG,10,
                                              E_TDBL+E_TEXT(1),&a,
                                              E_TDBL+E_TEXT(2),&b,
                                              E_TRES+E_TDBL,&b);
                         }
                      else if (vzb!=vzc) b_comp(&b,expob,mantb,NOT(vzb));

                      E_TPOPP("mulbody")
                      return(b);
                      }

                    /* b = NaN                                  */
                    if (SIGNALING(mantb[0]))
                       e_trap(INV_OP+E_IEEE,8,E_TMSG,5,
                                              E_TDBL+E_TEXT(1),&a,
                                              E_TDBL+E_TEXT(2),&b,
                                              E_TRES+E_TDBL,&b);
                    E_TPOPP("mulbody")
                    return(b);
                    }
                }

        /* product is zero                                      */
        if (zeroa || zerob) {
            E_TPOPP("mulbody")
            return(*r_zero);
            }

        /* add exponents                                        */
        expoc = expoa+expob;

#if C_P_3
        /* determine exact product                              */
        lang[BSIZE-1] = ZERO;
        b_prod(manta,mantb,lang);
#else
        /* initialize exact mantissa array lang                 */
        B_CLEAR(lang,BSIZE)

        /* determine exact product                              */
        for ( i=2*D_U_RATIO-1; i>=D_U_RATIO; i-- ) {
            j = i-D_U_RATIO;
            while ( j<D_U_RATIO ) {
                b_muad(manta[j],mantb[i-j-1],lang+i);
                j++;
                }
            }
        for ( i=D_U_RATIO-1; i>0; i-- ) {
            j = i-1;
            while( j>=0 ) {
                b_muad(manta[j],mantb[i-j-1],lang+i);
                j--;
                }
            }
#endif

        /* adjust mantissa                                      */
        b_shlu(lang,BSIZE,ZERO_BITS);

        /* normalization                                        */
        if ( SHFT_MASK & lang[0]) {
            b_shr1(lang,BSIZE);
            expoc++;
            }
        else {
            while ( (HIDDEN_BIT & lang[0])==ZERO ) {
                b_shl1(lang,BSIZE);
                expoc--;
                }
            }

        /* adjust denormalized number                           */
        rc = b_adj(lang,&expoc);
