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
		
			
				
	
	
		
			105 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			105 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
/* DEC	**DepreciateStraightLineTable(depr,remval, book, salv, life, partial);
 | 
						|
 *
 | 
						|
 * ARGUMENT
 | 
						|
 *	DEC	**depr,	**remval, *book, *salv,	*partial;
 | 
						|
 *	int	life;
 | 
						|
 *
 | 
						|
 * DESCRIPTION
 | 
						|
 *	Calculate several years' depreciation and remaining depreciable
 | 
						|
 *   value according to	straight line depreciation.  The item has book value
 | 
						|
 *   book, salvage value salv, and lifetime life (which	may include a partial
 | 
						|
 *   period).  At year#	i, the depreciation and	remaining value	are
 | 
						|
 *   computed and stored in depr[i] and	remval[i].  The	first year is always
 | 
						|
 *   the partial year.	The results are	calculated for the entire lifetime.
 | 
						|
 *
 | 
						|
 * SIDE	EFFECTS
 | 
						|
 *	depr and remval	are changed.
 | 
						|
 *
 | 
						|
 * RETURNS
 | 
						|
 *	depr if	successful, otherwise GM_NULLARR.
 | 
						|
 *
 | 
						|
 * POSSIBLE ERRORS
 | 
						|
 *	GM_NULLPOINTER
 | 
						|
 *	GM_ARGVAL
 | 
						|
 *
 | 
						|
 * AUTHOR
 | 
						|
 *  Jared Levy
 | 
						|
 *   Copyright (C) 1988-1990 Greenleaf Software	Inc.  All rights reserved.
 | 
						|
 *
 | 
						|
 * MODIFICATIONS
 | 
						|
 *
 | 
						|
 *
 | 
						|
 */
 | 
						|
 | 
						|
#include <stdio.h>
 | 
						|
#include "gm.h"
 | 
						|
#include "gmsystem.h"
 | 
						|
 | 
						|
DEC	**DepreciateStraightLineTable(depr, remval, book, salv,	life, partial)
 | 
						|
DEC	**depr,	**remval, *book, *salv,	*partial;
 | 
						|
int	life;
 | 
						|
{
 | 
						|
	int	i, plife;
 | 
						|
	DEC	dtotlif, *totlif=&dtotlif;
 | 
						|
	DEC	dydep, *ydep=&dydep;
 | 
						|
 | 
						|
	_MacStart(GM_DPSLTBL);
 | 
						|
 | 
						|
	if (!depr||!remval||!book||!salv||!partial)  {
 | 
						|
		_MacErr(GM_NULLPOINTER);
 | 
						|
		_MacRet(GM_NULLARR);
 | 
						|
	}
 | 
						|
	if (_MacBad(book)||_MacBad(salv)||_MacBad(partial))  {
 | 
						|
		_MacErr(GM_INIT);
 | 
						|
		_MacRet(GM_NULLARR);
 | 
						|
	}
 | 
						|
 | 
						|
	plife=life+(_MacIsDecZ(partial)?0:1);
 | 
						|
 | 
						|
	for (i=0;i<=plife;i++)
 | 
						|
		if(!depr[i]||!remval[i])  {
 | 
						|
			_MacErr(GM_NULLPOINTER);
 | 
						|
			_MacRet(GM_NULLARR);
 | 
						|
		}
 | 
						|
 | 
						|
/* check life>=1, 0<=partial<=1	*/
 | 
						|
	if (life<1||_MacIsDecN(partial)||CompareDecimal(partial,&decOne)==1
 | 
						|
		||_MacIsDecN(book)||_MacIsDecN(salv))  {
 | 
						|
		_MacErr(GM_ARGVAL);
 | 
						|
		_MacRet(GM_NULLARR);
 | 
						|
	}
 | 
						|
 | 
						|
/* calculate yearly depreciation */
 | 
						|
	(void) _SubDec80Bit(remval[0],book,salv);
 | 
						|
	(void) _ScaleDec80Bit(remval[0], remval[0], 2);
 | 
						|
	(void) ConvLongToDecimal(totlif, (long)	life);
 | 
						|
	(void) _DivRndDec80Bit(ydep, remval[0],	totlif,	2);
 | 
						|
 | 
						|
	_MacDZero(depr[0]);
 | 
						|
 | 
						|
/* handle partial first	year */
 | 
						|
	if (_MacIsDecZ(partial))  {
 | 
						|
		i=0;
 | 
						|
	}
 | 
						|
	else  {
 | 
						|
		(void) _MulDec80Bit(depr[1],ydep,partial);
 | 
						|
		(void) _ScaleDec80Bit(depr[1],depr[1],2);
 | 
						|
		(void) _SubDec80Bit(remval[1], remval[0], depr[1]);
 | 
						|
		i=1;
 | 
						|
	}
 | 
						|
 | 
						|
/* handle remaining years */
 | 
						|
 | 
						|
	while (i<plife)	 {
 | 
						|
		i++;
 | 
						|
		_MacDCopy(depr[i],ydep);
 | 
						|
		(void) _SubDec80Bit(remval[i], remval[i-1], ydep);
 | 
						|
	}
 | 
						|
 | 
						|
/* add balance to last depreciation period */
 | 
						|
	_MacDCopy(depr[plife],remval[plife-1]);
 | 
						|
	_MacDZero(remval[plife]);
 | 
						|
 | 
						|
	_MacRet(depr);
 | 
						|
}
 |