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
		
			
				
	
	
		
			82 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			82 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
| /* DEC	*ConvYearlyToPeriodic(peri, yeari, nper);
 | |
|  *
 | |
|  * ARGUMENT
 | |
|  *	DEC	*peri, *yeari;
 | |
|  *	int	nper;
 | |
|  *
 | |
|  * DESCRIPTION
 | |
|  *	Changes	the interest rate per year to the interest rate	per period.
 | |
|  *  For	instance, a yearly rate	is changed to a	monthly	rate.
 | |
|  *  Interest rates should are expressed	as percentages.
 | |
|  *	yeari is the period rate
 | |
|  *	nper is	the number of compounding periods.
 | |
|  *	The resulting periodic rate is store in	peri.
 | |
|  *
 | |
|  * SIDE	EFFECTS
 | |
|  *	none.
 | |
|  *
 | |
|  * RETURNS
 | |
|  *	peri if	successful, otherwise GM_NULL.
 | |
|  *
 | |
|  * POSSIBLE ERRORS
 | |
|  *	GM_NULLPOINTER
 | |
|  *	GM_ARGVAL
 | |
|  *
 | |
|  * AUTHOR
 | |
|  *  Jared Levy
 | |
|  *   Copyright (C) 1989-1990 Greenleaf Software	Inc.  All rights reserved.
 | |
|  *
 | |
|  * MODIFICATIONS
 | |
|  *
 | |
|  *
 | |
|  */
 | |
| 
 | |
| #include <stdio.h>
 | |
| #include "gmsystem.h"
 | |
| 
 | |
| DEC	*ConvYearlyToPeriodic(peri, yeari, nper)
 | |
| DEC	*peri, *yeari;
 | |
| int	nper;
 | |
| {
 | |
| 	DEC	dtemp, *temp=&dtemp, ddper, *dper=&ddper;
 | |
| 
 | |
| 	_MacStart(GM_YTOP);
 | |
| 
 | |
| 	_MacInVarD(yeari);
 | |
| 	_MacOutVarD(peri);
 | |
| 
 | |
| /* nper	must be	>= 1 */
 | |
| 	if ((nper<=0)
 | |
| 		||CompareDecimal(yeari,&decMinusHundred)<=0)  {
 | |
| 		_MacErr(GM_ARGVAL);
 | |
| 		_MacRet(GM_NULL);
 | |
| 	}
 | |
| 
 | |
| /* convert percent to decimal */
 | |
| 	_MacDCopy(temp,	yeari);
 | |
| 	temp->dc.id+=2;
 | |
| 
 | |
| 	(void) ConvLongToDecimal(dper, (long) nper);
 | |
| 	(void) _AddDec80Bit(temp, temp,	&decOne);
 | |
| 	(void) _LnDec80Bit(temp, temp);
 | |
| 	(void) _DivDec80Bit(temp, temp,	dper);
 | |
| 	(void) _ExpDec80Bit(temp, temp);
 | |
| 	(void) _SubDec80Bit(temp, temp,	&decOne);
 | |
| 
 | |
| /* convert decimal to percent */
 | |
| 	if (temp->dc.id>=2)
 | |
| 		temp->dc.id-=2;
 | |
| 	else  {
 | |
| 		(void) ConvLongToDecimal(dper, 100L);
 | |
| 		(void) _MulDec80Bit(temp, temp,	dper);
 | |
| 	}
 | |
| 
 | |
| 	if ( _Sq5UnsTo4Uns( temp ) != GM_SUCCESS )  {
 | |
| 		_MacErr(GM_ARGVAL);
 | |
| 		_MacRet(GM_NULL);
 | |
| 	}
 | |
| 
 | |
| 	_MacDCopy(peri,temp);
 | |
| 	_MacRet(peri);
 | |
| }
 |