campo-sirio/gfm/ptoy.c
alex ba237a9d91 Patch level : no patch
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
2002-02-26 12:19:02 +00:00

83 lines
1.6 KiB
C
Executable File

/* DEC *ConvPeriodicToYearly(yeari, peri, nper);
*
* ARGUMENT
* DEC *peri, *yeari;
* int nper;
*
* DESCRIPTION
* Changes the interest rate per period to the interest rate per year.
* For instance, a monthly rate is changed to a yearly rate.
* Interest rates should are expressed as percentages.
* peri is the period rate
* nper is the number of compounding periods.
* The resulting yearly rate is store in yeari.
*
* SIDE EFFECTS
* none.
*
* RETURNS
* yeari 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 *ConvPeriodicToYearly(yeari, peri, nper)
DEC *peri, *yeari;
int nper;
{
DEC dtemp, *temp=&dtemp, ddper, *dper=&ddper;
_MacStart(GM_PTOY);
_MacInVarD(peri);
_MacOutVarD(yeari);
/* nper must be >= 1 */
if ((nper<=0)
||CompareDecimal(peri,&decMinusHundred)<=0) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULL);
}
/* convert percent to decimal */
_MacDCopy(temp, peri);
temp->dc.id+=2;
(void) ConvLongToDecimal(dper, (long) nper);
(void) _AddDec80Bit(temp, temp, &decOne);
if (_IntPwrDec80Bit(temp, temp, nper)!=GM_SUCCESS) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULL);
}
(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(yeari,temp);
_MacRet(yeari);
}