84 lines
1.5 KiB
C
Raw Normal View History

/* DEC *NetFutureValue(net, flows, nflow, intr)
*
* ARGUMENT
* DEC *net, **flows, *intr;
* int nflow;
*
* DESCRIPTION
* Calculates the net future value of a series of cash flows.
* The nflow cash flows in the array flows are processed at interest
* rate intr. The net future value, rounded to two decimal places,
* is stored in net.
*
* SIDE EFFECTS
* None.
*
* RETURNS
* net 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 *NetFutureValue(net, flows, nflow, intr)
DEC *net, **flows, *intr;
int nflow;
{
int i;
DEC dtemp, *temp=&dtemp, dopi, *opi=&dopi;
DEC dtnet, *tnet=&dtnet, dpow, *pow=&dpow;
_MacStart(GM_NFV);
if (nflow<0) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULL);
}
_MacInVarD(intr);
if (!flows||!net) {
_MacErr(GM_NULLPOINTER);
_MacRet(GM_NULL);
}
for (i=0;i<nflow;i++) {
_MacInVarD(flows[i]);
}
if (CompareDecimal(intr,&decMinusHundred)!=1) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULL);
}
_MacDZero(tnet);
_MacDCopy(temp, intr);
temp->dc.id+=2;
(void) _AddDec80Bit(opi, temp, &decOne);
_MacDCopy(pow, (&decOne));
for (i=nflow-1;i>=0;i--) {
(void) _MulDec80Bit(temp, flows[i], pow);
(void) _AddDec80Bit(tnet, tnet, temp);
(void) _MulDec80Bit(pow, pow, opi);
}
_ScaleDec80Bit(net, tnet, 2);
_MacRet(net);
}