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
		
			
				
	
	
		
			128 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			128 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| /* DEC	*DepreciateSumOfYears(depr,remval, book, salv, life, partial, time);
 | |
|  *
 | |
|  * ARGUMENT
 | |
|  *	DEC	*depr, *remval,	*book, *salv, *partial;
 | |
|  *	int	life, time;
 | |
|  *
 | |
|  * DESCRIPTION
 | |
|  *	Calculate a specific year's depreciation and remaining depreciable
 | |
|  *   value according to	sum-of-the-years-digits	depreciation.
 | |
|  *   The item has book value
 | |
|  *   book, salvage value salv, and lifetime life (which	may include a partial
 | |
|  *   period).  At year time, the depreciation and remaining value are
 | |
|  *   computed and stored in depr and remval.  The first	year is	always
 | |
|  *   the partial year.
 | |
|  *
 | |
|  * SIDE	EFFECTS
 | |
|  *	depr and remval	are changed.
 | |
|  *
 | |
|  * RETURNS
 | |
|  *	depr if	successful, otherwise GM_NULL.
 | |
|  *
 | |
|  * 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	*DepreciateSumOfYears(depr, remval, book,salv,life,partial, time)
 | |
| DEC	*depr, *remval,	*book, *salv, *partial;
 | |
| int	life, time;
 | |
| {
 | |
| 	int	i, plife;
 | |
| 	DEC	drbv0, *rbv0=&drbv0, dladj, *ladj=&dladj;
 | |
| 	DEC	ddlife,	*dlife=&ddlife,	dsoyd, *soyd=&dsoyd;
 | |
| 	DEC	dtemp, *temp=&dtemp, dtemp2, *temp2=&dtemp2;
 | |
| 
 | |
| 	_MacStart(GM_DPSOYTBL);
 | |
| 
 | |
| 	if (!depr||!remval||!book||!salv||!partial)  {
 | |
| 		_MacErr(GM_NULLPOINTER);
 | |
| 		_MacRet(GM_NULL);
 | |
| 	}
 | |
| 	if (_MacBad(book)||_MacBad(salv)||_MacBad(partial))  {
 | |
| 		_MacErr(GM_INIT);
 | |
| 		_MacRet(GM_NULL);
 | |
| 	}
 | |
| 
 | |
| 	plife=life+(_MacIsDecZ(partial)?0:1);
 | |
| 
 | |
| /* check time>=0, life>=1, time<=life, 0<=partial<=1 */
 | |
| 	if (time<0||life<1||_MacIsDecN(book)||_MacIsDecN(salv)||time>plife
 | |
| 		||_MacIsDecN(partial)||CompareDecimal(partial,&decOne)==1)  {
 | |
| 		_MacDZero(depr);
 | |
| 		_MacDZero(remval);
 | |
| 		_MacErr(GM_ARGVAL);
 | |
| 		_MacRet(GM_NULL);
 | |
| 	}
 | |
| 
 | |
| /* calculate initial remaining book value & store zeroes indices */
 | |
| 	_MacDZero(depr);
 | |
| 	(void) _SubDec80Bit(rbv0,book,salv);
 | |
| 	(void) _ScaleDec80Bit(rbv0, rbv0, 2);
 | |
| 	_MacDCopy(remval, rbv0);
 | |
| 
 | |
| 	if (time==0)
 | |
| 		_MacRet(depr);
 | |
| 
 | |
| /* calculate sum of years digits soyd */
 | |
| 	(void) ConvLongToDecimal(soyd,
 | |
| 		(long) (life) *	(long) (life+1)	/ 2L);
 | |
| 
 | |
| 	if (_MacIsDecZ(partial))  {
 | |
| 		(void) ConvLongToDecimal(ladj, (long) life);
 | |
| 		i=0;
 | |
| 	}
 | |
| 	else  {
 | |
| 		(void) ConvLongToDecimal(dlife,	(long) life);
 | |
| /* calculate first partial year's depreciation */
 | |
| 		(void) _MulDec80Bit(temp, dlife, partial);
 | |
| 		(void) _MulDec80Bit(temp, temp,	rbv0);
 | |
| 		(void) _DivRndDec80Bit(depr, temp, soyd, 2);
 | |
| /* subtract first depreciation from rbv	*/
 | |
| 		(void) _SubDec80Bit(rbv0, rbv0,	depr);
 | |
| 		_MacDCopy(remval,rbv0);
 | |
| 		i=1;
 | |
| 
 | |
| /* calculate sum of years digits soyd */
 | |
| 		(void) _SubDec80Bit(ladj, dlife, partial);
 | |
| 		(void) _TruncateDec80Bit(temp, ladj, 0);
 | |
| 		(void) _SubDec80Bit(temp2, ladj, temp);
 | |
| 		(void) _AddDec80Bit(temp2, temp2, temp2);
 | |
| 		(void) _AddDec80Bit(temp2, temp2, temp);
 | |
| 		(void) _AddDec80Bit(temp, temp,	&decOne);
 | |
| 		(void) _MulDec80Bit(temp, temp,	temp2);
 | |
| 		(void) _MulDec80Bit(soyd, temp,	&decPoint5);
 | |
| 
 | |
| 	}
 | |
| 
 | |
| /* handle remaining years */
 | |
| 	(void) _DivDec80Bit(temp, rbv0,	soyd);
 | |
| 	while (i<time)	{
 | |
| 		i++;
 | |
| 		_MulDec80Bit(depr, ladj, temp);
 | |
| 		_ScaleDec80Bit(depr, depr, 2);
 | |
| 		_SubDec80Bit(ladj, ladj, &decOne);
 | |
| 		(void) _SubDec80Bit(remval, remval, depr);
 | |
| 	}
 | |
| 
 | |
| /* add balance to last depreciation period */
 | |
| 	if (time==plife)  {
 | |
| 		_AddDec80Bit(depr, depr, remval);
 | |
| 		_MacDZero(remval);
 | |
| 	}
 | |
| 
 | |
| 	_MacRet(depr);
 | |
| }
 |