/**************************************************************************/
/*                                                                        */
/*                                 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: body.h,v 1.2 1997/09/25 16:42:57 ae59 Exp $ */
/*
$Log: body.h,v $
 * Revision 1.2  1997/09/25  16:42:57  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:52  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : body.h                                */
/*                                                              */
/*      Description     : Addition or subtraction of a_btyp     */
/*                        mantissas                             */
/*                                                              */
/*      Notes           : included by addbody.h,subbody.h       */
/*                                                              */
/*      Date            : 1992-07-22                            */
/*      1992-07-22 : cast at vza exchange =b=                   */
/*      1990-11-16 : E_TPUSH+E_TPOPP                            */
/****************************************************************/

        /* order operands in order to get |a|>=|b|              */
        if ( expob > expoa ) {
                i = expoa; expoa = expob; expob = i;
                i = (a_intg) vza;   vza = vzb;  vzb = (a_bool) i;
#if C_P_3
                hu = manta[0];
                manta[0] = mantb[0];
                mantb[0] = hu;
                hu = manta[1];
                manta[1] = mantb[1];
                mantb[1] = hu;
#else
                for ( i=0 ; i<D_U_RATIO ; i++ )
                        {
                        hu = manta[i];
                        manta[i] = mantb[i];
                        mantb[i] = hu;
                        }
#endif
                }
        else if ( expoa == expob ) {
                for ( i=0; i<D_U_RATIO; i++ )
                    if ( manta[i]<mantb[i] ) {
                        i = (a_intg) vza; vza = vzb; vzb = (a_bool) i;
#if C_P_3
                        hu = manta[0];
                        manta[0] = mantb[0];
                        mantb[0] = hu;
                        hu = manta[1];
                        manta[1] = mantb[1];
                        mantb[1] = hu;
#else
                        for (i=0;i<D_U_RATIO;i++ ) {
                                hu = manta[i];
                                manta[i] = mantb[i];
                                mantb[i] = hu;
                                }
#endif
                        break;
                        }
                    else if ( manta[i]>mantb[i] ) break;
                }

        /* initialize unused mantissa positions                 */
        for ( i=D_U_RATIO; i<BSIZE; i++ ) manta[i] = ZERO;

        /* 1. case                                              */
        /* difference of exponents >= length of mantissa+2      */
        if ( expoa-expob>=MANTL+2 ) {

                /* propagate a borrow to mantissa               */
                if (vza!=vzb) b_subc(manta+D_U_RATIO);

                /* set lsb of of result mantissa                */
                else manta[D_U_RATIO] |= LSB;
                }

        /* 2. case                                              */
        /* difference of exponents < length of mantissa+2       */
        else {

                /* initialize unused mantissa positions         */
                for ( i=D_U_RATIO; i<BSIZE; i++ ) mantb[i] = ZERO;

                /* adjust mantissa of mantb to manta            */
                b_shru( mantb, BSIZE, expoa-expob );

                /* add a_btyp mantissas                         */
                if ( vza==vzb ) {
                        (void)b_addm(BSIZE,manta,mantb);
                        }

                /* subtract a_btyp mantissas                    */
                else {
                        (void)b_subm(BSIZE,manta,mantb);

                        /* return zero if no bits are set            */
                        if (b_test(BSIZE,manta))
                            {
                            b_comp(&a,-CHARAC,manta,vzz);
                            E_TPOPP("body")
                            return(a);
                            }
                        }
                }

        /* normalization of mantissa                            */
        if ( SHFT_MASK & *manta ) {
                b_shr1( manta, BSIZE );
                expoa++;
                }
        else while ( (HIDDEN_BIT & *manta)==ZERO ) {
                b_shl1( manta, BSIZE );
                expoa--;
                }

        /* adjust denormalized number and check inexact data    */
        rc = b_adj(manta,&expoa);
