/**************************************************************************/
/*                                                                        */
/*                                 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: b_subu.c,v 1.2 1997/09/25 17:08:14 ae59 Exp $ */
/*
$Log: b_subu.c,v $
 * Revision 1.2  1997/09/25  17:08:14  ae59
 * Copyright-message
 *
 * Revision 1.1  1994/01/27  13:21:46  ae59
 * Put under RCS control
 *
 */
/****************************************************************/
/*                                                              */
/*      Filename        : b_subu.c                              */
/*                                                              */
/*      Entry           : void b_subu(a,b,bin,c,bout);          */
/*                        a_btyp a,b,*c;                        */
/*                        a_intg bin,*bout;                     */
/*                                                              */
/*      Arguments       : a = first operand of subtraction      */
/*                        b = second operand of subtraction     */
/*                        bin = borrow in                       */
/*                        c = a-b-bin                           */
/*                        bout = borrow out                     */
/*                                                              */
/*      Description     : Subtraction of a_btyp digits with     */
/*                        borrow                                */
/*                                                              */
/*      Date            : 1990-07-16                            */
/*      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 void b_subu(a_btyp a,a_btyp b,a_intg bin,a_btyp *c,a_intg *bout)
#else
local void b_subu(a,b,bin,c,bout)

a_btyp a;
a_btyp b;
a_intg bin;
a_btyp *c;
a_intg *bout;
#endif
        {
#if C_P_2
        *c = a-b-bin;
        *bout = (b>a || (b==a && bin)) ? 1 : 0;
#else
        /* b+bin produce carry => (c-bout) = (a-1)              */
        if ( (b==MAX_BASETYPE) && bin ) {
                *bout = 1;
                *c = a;
                return;
                }

        b += bin;

        /* determine borrow and difference                      */
        if (a>=b) {
                *bout = 0;
                *c = a-b;
                }
        else {
                *bout = 1;
                *c = ~(b-a)+1;
                }
#endif

        return;
        }
