diff options
author | Winfried Donkers <winfrieddonkers@libreoffice.org> | 2016-07-28 10:20:35 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-07-29 20:09:49 +0000 |
commit | 1ca11b55aecb18f9dcca1e9678910dc2e7593623 (patch) | |
tree | 48eafdaae9ca82b21a0a4f2eaf73c02d235fa874 /sc | |
parent | c772c8fd273d73af4734ce0ed1b4bb082dc1886c (diff) |
tdf#101166 treat argument PayType for Calc function RATE as boolean.
Excel and Gnumeric treat this argument as boolean.
Financially, payment at beginning or at end of period are the only
existing options, i.e. there no other feasible options.
Change-Id: I7ba9fcdac69b9b0756cdf48abde001a44c8b4c88
Reviewed-on: https://gerrit.libreoffice.org/27612
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/inc/interpre.hxx | 2 | ||||
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 26 |
2 files changed, 14 insertions, 14 deletions
diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx index e8f618596876..33386b7a9b6b 100644 --- a/sc/source/core/inc/interpre.hxx +++ b/sc/source/core/inc/interpre.hxx @@ -760,7 +760,7 @@ static double ScGetZw(double fZins, double fZzr, double fRmz, void ScFV(); void ScNper(); static bool RateIteration(double fNper, double fPayment, double fPv, - double fFv, double fPayType, double& fGuess); + double fFv, bool bPayType, double& fGuess); void ScRate(); double ScGetCompoundInterest(double fZins, double fZr, double fZzr, double fBw, double fZw, bool bPayInAdvance, double& fRmz); diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index 1723059db614..a8d632fe6788 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -1970,7 +1970,7 @@ void ScInterpreter::ScNper() } bool ScInterpreter::RateIteration( double fNper, double fPayment, double fPv, - double fFv, double fPayType, double & fGuess ) + double fFv, bool bPayType, double & fGuess ) { // See also #i15090# // Newton-Raphson method: x(i+1) = x(i) - f(x(i)) / f'(x(i)) @@ -1983,9 +1983,12 @@ bool ScInterpreter::RateIteration( double fNper, double fPayment, double fPv, const sal_uInt16 nIterationsMax = 150; sal_uInt16 nCount = 0; const double fEpsilonSmall = 1.0E-14; - // convert any fPayType situation to fPayType == zero situation - fFv = fFv - fPayment * fPayType; - fPv = fPv + fPayment * fPayType; + if ( bPayType ) + { + // payment at beginning of each period + fFv = fFv - fPayment; + fPv = fPv + fPayment; + } if (fNper == ::rtl::math::round( fNper )) { // Nper is an integer value fX = fGuess; @@ -2070,8 +2073,8 @@ void ScInterpreter::ScRate() { double fPv, fPayment, fNper; // defaults for missing arguments, see ODFF spec - double fFv = 0, fPayType = 0, fGuess = 0.1, fOrigGuess = 0.1; - bool bValid = true; + double fFv = 0, fGuess = 0.1, fOrigGuess = 0.1; + bool bPayType = false, bValid = true; bool bDefaultGuess = true; nFuncFmtType = css::util::NumberFormat::PERCENT; sal_uInt8 nParamCount = GetByte(); @@ -2083,7 +2086,7 @@ void ScInterpreter::ScRate() bDefaultGuess = false; } if (nParamCount >= 5) - fPayType = GetDouble(); + bPayType = GetBool(); if (nParamCount >= 4) fFv = GetDouble(); fPv = GetDouble(); @@ -2094,10 +2097,7 @@ void ScInterpreter::ScRate() PushIllegalArgument(); return; } - // other values for fPayType might be meaningful, - // ODFF spec is not clear yet, enable statement if you want only 0 and 1 - //if (fPayType != 0.0) fPayType = 1.0; - bValid = RateIteration(fNper, fPayment, fPv, fFv, fPayType, fGuess); + bValid = RateIteration(fNper, fPayment, fPv, fFv, bPayType, fGuess); if (!bValid) { /* TODO: try also for specified guess values, not only default? As is, @@ -2115,11 +2115,11 @@ void ScInterpreter::ScRate() for (int nStep = 2; nStep <= 10 && !bValid; ++nStep) { fGuess = fX * nStep; - bValid = RateIteration( fNper, fPayment, fPv, fFv, fPayType, fGuess); + bValid = RateIteration( fNper, fPayment, fPv, fFv, bPayType, fGuess); if (!bValid) { fGuess = fX / nStep; - bValid = RateIteration( fNper, fPayment, fPv, fFv, fPayType, fGuess); + bValid = RateIteration( fNper, fPayment, fPv, fFv, bPayType, fGuess); } } } |