mtollari 1b14ec9415 Spostamento cartella sorgenti
git-svn-id: svn://10.65.10.50/branches/R_10_00@23236 c028cbd2-c16b-5b4b-a496-9718f37d4682
2016-09-09 13:59:02 +00:00

79 lines
1.5 KiB
C
Executable File

/* DEC *UniformSeriesPresentValue(dst, intr, nper);
*
* ARGUMENT
* DEC *dst,*intr;
* int nper;
*
* DESCRIPTION
* Calculates the present value of a uniform series of nper payments
* of 1 dollar at the percentage interest rate of intr.
* dst = [ 1 - (1 + intr / 100) ^ -nper ] / (intr / 100) if intr != 0
* dst = n if intr == 0
*
* SIDE EFFECTS
* The result is stored in dst.
*
* RETURNS
* dst 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 "gmsystem.h"
DEC *UniformSeriesPresentValue(dst, intr, nper)
DEC *dst,*intr;
int nper;
{
DEC dtemp, *temp=&dtemp, dnintr, *nintr=&dnintr;
int i;
_MacStart(GM_USPV);
_MacInVarD(intr);
_MacOutVarD(dst);
/* interest rate must be greater than -100% */
if (CompareDecimal(intr,&decMinusHundred)<=0) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULL);
}
if (_MacIsDecZ(intr)) {
ConvLongToDecimal(dst, (long) nper);
_MacRet(dst);
}
_MacDCopy(nintr, intr);
nintr->dc.id +=2;
(void) _AddDec80Bit(temp, nintr, &decOne);
i = _IntPwrDec80Bit(temp, temp, -nper);
if (i==GM_OVERFLOW) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULL);
}
(void) _SubDec80Bit(temp, &decOne, temp);
(void) _DivDec80Bit(temp, temp, nintr);
if (_Sq5UnsTo4Uns(temp)!=GM_SUCCESS) {
_MacErr(GM_ARGVAL);
_MacRet(GM_NULL);
}
_MacDCopy(dst, temp);
_MacRet(temp);
}