campo-sirio/gfm/ptoy.c

83 lines
1.6 KiB
C
Raw Normal View History

/* 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);
}