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
		
			
				
	
	
		
			107 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			107 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| /* DEC	*DepreciateStraightLine(depr, remval, book, salv, life,	partial, time)
 | |
|  *
 | |
|  * ARGUMENT
 | |
|  *	DEC	*depr, *remval,	*book, *salv, *partial;
 | |
|  *	int	time, life;
 | |
|  *
 | |
|  * DESCRIPTION
 | |
|  *	Calculate a particular year's 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#	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	*DepreciateStraightLine(depr, remval, book, salv, life,	partial, time)
 | |
| DEC	*depr, *remval,	*book, *salv, *partial;
 | |
| int	time, life;
 | |
| {
 | |
| 	int	i, plife;
 | |
| 	DEC	dtotlif, *totlif=&dtotlif;
 | |
| 	DEC	dydep, *ydep=&dydep;
 | |
| 
 | |
| 	_MacStart(GM_DPSL);
 | |
| 
 | |
| 	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 yearly depreciation */
 | |
| 	(void) _SubDec80Bit(remval,book,salv);
 | |
| 	(void) _ScaleDec80Bit(remval, remval, 2);
 | |
| 	(void) ConvLongToDecimal(totlif, (long)	life);
 | |
| 	(void) _DivRndDec80Bit(ydep, remval, totlif, 2);
 | |
| 
 | |
| 	_MacDZero(depr);
 | |
| 
 | |
| 	if (time==0)
 | |
| 		_MacRet(depr);
 | |
| 
 | |
| /* handle partial first	year */
 | |
| 	if (_MacIsDecZ(partial))  {
 | |
| 		i=0;
 | |
| 	}
 | |
| 	else  {
 | |
| 		(void) _MulDec80Bit(depr,ydep,partial);
 | |
| 		(void) _ScaleDec80Bit(depr,depr,2);
 | |
| 		(void) _SubDec80Bit(remval, remval, depr);
 | |
| 		i=1;
 | |
| 	}
 | |
| 
 | |
| /* handle remaining years */
 | |
| 	if (time>i)
 | |
| 		_MacDCopy(depr,	ydep);
 | |
| 
 | |
| 	while (i<time)	{
 | |
| 		(void) _SubDec80Bit(remval, remval, ydep);
 | |
| 		i++;
 | |
| 	}
 | |
| 
 | |
| /* add balance to last depreciation period */
 | |
| 	if (time==plife)  {
 | |
| 		_AddDec80Bit(depr, depr, remval);
 | |
| 		_MacDZero(remval);
 | |
| 	}
 | |
| 
 | |
| 	_MacRet(depr);
 | |
| }
 |