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
		
			
				
	
	
		
			124 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			124 lines
		
	
	
		
			3.1 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| /* DEC	**DepreciateDecliningTable(depr, remval, book, salv,dbf,life,partial);
 | |
|  *
 | |
|  * ARGUMENT
 | |
|  *	DEC	**depr,	**remval, *book, *salv,	*dbf, *partial;
 | |
|  *	int	life;
 | |
|  *
 | |
|  * DESCRIPTION
 | |
|  *	Calculate several years' depreciation and remaining depreciable
 | |
|  *   value according to	declining balance depreciation.
 | |
|  *   With a declining balance factor of	dbf, 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	**DepreciateDecliningTable(depr, remval, book, salv,dbf,life, partial)
 | |
| DEC	**depr,	**remval, *book, *salv,	*dbf, *partial;
 | |
| int	life;
 | |
| {
 | |
| 	int	i, plife;
 | |
| 	DEC	drbv, *rbv=&drbv, dfol,	*fol=&dfol;
 | |
| 	DEC	dtemp, *temp=&dtemp, dnsalv, *nsalv=&dnsalv;
 | |
| 
 | |
| 	_MacStart(GM_DPDBTBL);
 | |
| 
 | |
| 	if (!depr||!remval||!book||!salv||!partial||!dbf)  {
 | |
| 		_MacErr(GM_NULLPOINTER);
 | |
| 		_MacRet(GM_NULLARR);
 | |
| 	}
 | |
| 	if (_MacBad(salv)||_MacBad(partial)||_MacBad(dbf))  {
 | |
| 		_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(dbf)
 | |
| 		||_MacIsDecN(book)||_MacIsDecN(salv))  {
 | |
| 		_MacErr(GM_ARGVAL);
 | |
| 		_MacRet(GM_NULLARR);
 | |
| 	}
 | |
| 
 | |
| 	(void) _ScaleDec80Bit(rbv, book, 2);
 | |
| 	(void) _ScaleDec80Bit(nsalv, salv, 2);
 | |
| 	(void) _SubDec80Bit(remval[0],rbv,nsalv);
 | |
| 
 | |
| 	_MacDZero(depr[0]);
 | |
| 
 | |
| 	(void) ConvLongToDecimal(temp, (long) life * 100L);
 | |
| 	(void) _DivDec80Bit(fol, dbf, temp);
 | |
| 
 | |
| /* handle partial first	year */
 | |
| 	if (_MacIsDecZ(partial))  {
 | |
| 		i=0;
 | |
| 	}
 | |
| 	else  {
 | |
| 		(void) _MulDec80Bit(temp,rbv,fol);
 | |
| 		(void) _MulDec80Bit(depr[1], temp, partial);
 | |
| 		(void) _ScaleDec80Bit(depr[1],depr[1],2);
 | |
| 		(void) _SubDec80Bit(remval[1], remval[0], depr[1]);
 | |
| /* remaining value can't be negative */
 | |
| 		if (_MacIsDecN(remval[1]))  {
 | |
| 			(void) _AddDec80Bit(depr[1], depr[1], remval[1]);
 | |
| 			_MacDZero(remval[1]);
 | |
| 		}
 | |
| 		(void) _SubDec80Bit(rbv,rbv,depr[1]);
 | |
| 		i=1;
 | |
| 	}
 | |
| 
 | |
| /* handle remaining years */
 | |
| 
 | |
| 	while (i<plife)	 {
 | |
| 		i++;
 | |
| 		(void) _MulDec80Bit(depr[i], rbv, fol);
 | |
| 		(void) _ScaleDec80Bit(depr[i],depr[i],2);
 | |
| 		(void) _SubDec80Bit(remval[i], remval[i-1], depr[i]);
 | |
| /* remaining value can't be negative */
 | |
| 		if (_MacIsDecN(remval[i]))  {
 | |
| 			(void) _AddDec80Bit(depr[i], depr[i], remval[i]);
 | |
| 			_MacDZero(remval[i]);
 | |
| 		}
 | |
| 		(void) _SubDec80Bit(rbv,rbv,depr[i]);
 | |
| 	}
 | |
| 
 | |
| /* remaining depreciable value after last year should be 0 */
 | |
| 	if (!_MacIsDecZ(remval[plife]))	 {
 | |
| 		(void) _AddDec80Bit(depr[plife],depr[plife],remval[plife]);
 | |
| 		_MacDZero(remval[plife]);
 | |
| 	}
 | |
| 
 | |
| 	_MacRet(depr);
 | |
| }
 |