[Libreoffice-commits] core.git: sc/source

Winfried Donkers winfrieddonkers at libreoffice.org
Fri Jul 29 20:10:24 UTC 2016


 sc/source/core/inc/interpre.hxx  |    2 +-
 sc/source/core/tool/interpr2.cxx |   26 +++++++++++++-------------
 2 files changed, 14 insertions(+), 14 deletions(-)

New commits:
commit 1ca11b55aecb18f9dcca1e9678910dc2e7593623
Author: Winfried Donkers <winfrieddonkers at libreoffice.org>
Date:   Thu Jul 28 10:20:35 2016 +0200

    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 at libreoffice.org>
    Reviewed-by: Eike Rathke <erack at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index e8f6185..33386b7 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 1723059..a8d632f 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);
                 }
             }
         }


More information about the Libreoffice-commits mailing list