Files correlati : Ricompilazione Demo : [ ] Commento : Aggiunti i sorgenti per Greenleaf Math Library (gfm.dll) git-svn-id: svn://10.65.10.50/trunk@10079 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			84 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
/* DEC	*SumDecimalArray(pDst,pSrc,n)
 | 
						|
 *
 | 
						|
 * ARGUMENT
 | 
						|
 *	DEC	*pDst;
 | 
						|
 *	DEC	**pSrc;
 | 
						|
 *	int n;
 | 
						|
 *
 | 
						|
 * DESCRIPTION
 | 
						|
 *	Sets pDst to the sum of	the n DEC elements of the array	pSrc.
 | 
						|
 *   If	n is 0,	0 is returned.	pDst is	unchanged if an	error occurs.
 | 
						|
 *
 | 
						|
 * SIDE	EFFECTS
 | 
						|
 *	None.
 | 
						|
 *
 | 
						|
 * RETURNS
 | 
						|
 *	Returns	pointer	to the sum if successful, otherwise
 | 
						|
 *   returns GM_NULL.
 | 
						|
 *
 | 
						|
 * POSSIBLE ERROR CODES
 | 
						|
 *
 | 
						|
 *	GM_NULLPOINTER
 | 
						|
 *	GM_OVERFLOW
 | 
						|
 *	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	*SumDecimalArray(pDst,pSrc,n)
 | 
						|
DEC	*pDst;
 | 
						|
DEC	**pSrc;
 | 
						|
int n;
 | 
						|
{
 | 
						|
	int i;
 | 
						|
	DEC	*p, dsum, *sum=&dsum;
 | 
						|
 | 
						|
/*  source must	be supplied !! */
 | 
						|
	_MacStart(GM_SUMARR);
 | 
						|
 | 
						|
	if (!pSrc||!pDst) {
 | 
						|
		_MacErr(GM_NULLPOINTER);
 | 
						|
		_MacRet(GM_NULL);
 | 
						|
	}
 | 
						|
 | 
						|
	if (n<0)  {
 | 
						|
		_MacErr(GM_ARGVAL);
 | 
						|
		_MacRet(GM_NULL);
 | 
						|
	}
 | 
						|
 | 
						|
	for (i=0; i<n; i++)  {
 | 
						|
		_MacInVar(pSrc[i],GM_NULL);
 | 
						|
		}
 | 
						|
 | 
						|
	if (n==0)
 | 
						|
		{_MacDZero(sum);}
 | 
						|
	else {
 | 
						|
		p = pSrc[0];
 | 
						|
		_MacDCopy(sum, p);
 | 
						|
	}
 | 
						|
 | 
						|
	for (i=1;i<n;i++)  {
 | 
						|
		p = pSrc[i];
 | 
						|
		(void) _AddDec80Bit(sum, sum, p);
 | 
						|
		/* overflow impossible here since sum is 80 bits */
 | 
						|
	}
 | 
						|
 | 
						|
/* sum must be 64 bits */
 | 
						|
	if (_Sq5UnsTo4Uns(sum) != GM_SUCCESS)  {
 | 
						|
		_MacErr(GM_OVERFLOW);
 | 
						|
		_MacRet(GM_NULL);
 | 
						|
	}
 | 
						|
 | 
						|
	_MacDCopy(pDst,sum);
 | 
						|
	_MacRet(pDst);
 | 
						|
}
 |