/**************************************************************************/
/*                                                                        */
/*                                 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: subbody.h,v 1.3 1997/09/25 16:46:45 ae59 Exp $ */
/*
$Log: subbody.h,v $
 * Revision 1.3  1997/09/25  16:46:45  ae59
 * Copyright-message
 *
 * Revision 1.2  1994/10/12  12:56:52  ae59
 * result returned in case of a=b=inf with different sign
 *
 * Revision 1.1  1994/01/27  13:24:55  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : subbody.h                             */
/*                                                              */
/*      Description     : Subtraction of IEEE numbers.          */
/*                                                              */
/*      Notes           : included by r_sub.c,r_subd.c,r_subu.c */
/*                                                              */
/*      Include         : body.h                                */
/*                                                              */
/*      Date            : 1991-11-13                            */
/*      1991-11-13 : zero operands handled after NaN,infinity   */
/*                   handle inf-inf correctly                   */
/*                   handle qNaN-real correctly                 */
/*      1991-04-23 : MANT_INFINITY() used                       */
/*      1991-04-22 : real assignment replaced by R_ASSIGN()     */
/*      1991-01-07 : SIGNALING macro introduced                 */
/*      1990-11-16 : E_TPUSH+E_TPOPP                            */
/*      1990-11-12 : INV_OP                                     */
/****************************************************************/

/* Note: at entry of this routine vzb holds sign of -b */

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

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

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

                         /* a = b = infinity                    */
                         if (MANT_INFINITY(mantb)) {
                            if (vza!=vzb)
                               e_trap(INV_OP+E_IEEE,8,E_TMSG,9,
                                      E_TDBL+E_TEXT(1),&a,
                                      E_TDBL+E_TEXT(2),&b,
                                      E_TDBL+E_TRES,&a);
                            E_TPOPP("subbody")
                            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_TDBL+E_TRES,&b);
                         E_TPOPP("subbody")
                         return(b);
                         }

                      /* subtract number from infinity => a     */
                      E_TPOPP("subbody")
                      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_TDBL+E_TRES,&a);

                      /* a = qNaN     b = sNaN                  */
                      else 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_TDBL+E_TRES,&b);
                         E_TPOPP("subbody")
                         return(b);
                         }

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

                /* b = infinity or NaN                          */
                else {

                   /* b = infinity                              */
                   if (MANT_INFINITY(mantb)) {
                      b_comp(&b,expob,mantb,vzb);
                      E_TPOPP("subbody")
                      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_TDBL+E_TRES,&b);
                   E_TPOPP("subbody")
                   return(b);
                   }
                }

        /* check for one operand to be zero */
        if (zeroa)
           {

           /* special case (-0)-(-0),0-0 */
           if (zerob && vza!=vzb) vzb = vzz;
           
           b_comp(&b,expob,mantb,vzb);

           E_TPOPP("subbody")
           return(b);
           }
        else if (zerob)
           {
           E_TPOPP("subbody")
           return(a);
           }

        /* change sign of real number b (Now do addition !)     */
        R_ASSIGN(oldb,b);
        b_comp(&b,expob,mantb,vzb);

/* equivalent part for addition and subtraction                 */
#ifdef AIX
#include "/u/p88c/runtime/real/body.h"
#else
#include "body.h"
#endif
