campo-sirio/gfm/subarrd.c

82 lines
1.6 KiB
C
Raw Normal View History

/* DEC **SubtractDecimalFromDecimalArray(pDst,pSrc1,pSrc2,n)
*
* ARGUMENT
* pDst is a ptr to the array of destination DEC pointers.
* pSrc1 is a ptr to the arrays of source DEC pointers
* pSrc2 is a ptr to another DEC.
* n is the number of elements in pSrc
*
* DESCRIPTION
* Sets pDst[i] = pSrc1[i] - pSrc2. If pDst is null, tries to create a
* DEC structure, then subtract. If some of the pSrc structures
* are null, the non-null ones are still subtracted.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* Returns pointer to the new structure if successful, otherwise
* returns GM_NULLARR.
*
* POSSIBLE ERROR CODES
*
* GM_NULLPOINTER
* GM_ARGVAL
*
* AUTHOR
* Jared Levy
* Copyright (C) 1987-1990 Greenleaf Software Inc. All rights reserved.
*
* MODIFICATIONS
*
*/
#include <stdio.h>
#include "gm.h"
#include "gmsystem.h"
DEC **SubtractDecimalFromDecimalArray(pDst,pSrc1,pSrc2,n)
DEC **pDst;
DEC **pSrc1, *pSrc2;
int n;
{
int i;
DEC dcop2, *cop2=&dcop2;
mbool copyback;
/* source must be supplied !! */
_MacStart(GM_SUBARRD);
_MacInVar(pSrc2, GM_NULLARR);
if (!pSrc1 || !pDst) {
_MacErr(GM_NULLPOINTER);
_MacRet(GM_NULLARR);
}
if (n<=0) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULLARR);
}
/* Copy Src2 in case it is part of destination array */
_MacDCopy(cop2, pSrc2);
/* check if backwards copy is necessary */
copyback=(pDst > pSrc1);
/* Subtract the numbers */
i = copyback ? n-1 : 0;
while ((i<n) && (i>=0)) {
(void) SubtractDecimal(pDst[i], pSrc1[i], cop2);
/* SubtractDecimal sets the error flag each time an error occurs */
if (copyback)
i--;
else
i++;
}
_MacRet(pDst);
}