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

Winfried Donkers winfrieddonkers at libreoffice.org
Tue Aug 16 15:33:40 UTC 2016


 sc/source/core/tool/interpr2.cxx |   43 ++++++++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 16 deletions(-)

New commits:
commit a81eac7ce80732f983eb06713ac79c9cd4c5340f
Author: Winfried Donkers <winfrieddonkers at libreoffice.org>
Date:   Mon Aug 1 16:31:15 2016 +0200

    tdf#101204 make VDB return correct results for fractional periods.
    
    Change-Id: I97f7ff5f0c632a2b2e0501919a4d0fc1414fa028
    Reviewed-on: https://gerrit.libreoffice.org/27779
    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/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 455ac73..37d8465 100644
--- a/sc/source/core/tool/interpr2.cxx
+++ b/sc/source/core/tool/interpr2.cxx
@@ -1814,26 +1814,37 @@ void ScInterpreter::ScVDB()
             }
             else
             {
-
-                double fTimeLength1=fTimeLength;
-
-                //@ The question of all questions: 'Is this right'
-                if(!::rtl::math::approxEqual(fStart,::rtl::math::approxFloor(fStart)))
+                double fPart = 0.0;
+                // respect partial period in the Beginning / End:
+                if ( !::rtl::math::approxEqual( fStart, fIntStart ) ||
+                     !::rtl::math::approxEqual( fEnd, fIntEnd ) )
                 {
-                    if(fFactor>1)
+                    if ( !::rtl::math::approxEqual( fStart, fIntStart ) )
                     {
-                        if(fStart>fTimeLength/2 || ::rtl::math::approxEqual(fStart,fTimeLength/2))
-                        {
-                            double fPart=fStart-fTimeLength/2;
-                            fStart=fTimeLength/2;
-                            fEnd-=fPart;
-                            fTimeLength1+=1;
-                        }
+                        // part to be subtracted at the beginning
+                        double fTempIntEnd = fIntStart + 1.0;
+                        double fTempValue = fValue -
+                            ScInterVDB( fValue, fRest, fTimeLength, fTimeLength, fIntStart, fFactor );
+                        fPart += ( fStart - fIntStart ) *
+                            ScInterVDB( fTempValue, fRest, fTimeLength, fTimeLength - fIntStart,
+                            fTempIntEnd - fIntStart, fFactor);
+                    }
+                    if ( !::rtl::math::approxEqual( fEnd, fIntEnd ) )
+                    {
+                        // part to be subtracted at the end
+                        double fTempIntStart = fIntEnd - 1.0;
+                        double fTempValue = fValue -
+                            ScInterVDB( fValue, fRest, fTimeLength, fTimeLength, fTempIntStart, fFactor );
+                        fPart += ( fIntEnd - fEnd ) *
+                            ScInterVDB( fTempValue, fRest, fTimeLength, fTimeLength - fTempIntStart,
+                            fIntEnd - fTempIntStart, fFactor);
                     }
                 }
-
-                fValue-=ScInterVDB(fValue,fRest,fTimeLength,fTimeLength1,fStart,fFactor);
-                fVdb=ScInterVDB(fValue,fRest,fTimeLength,fTimeLength-fStart,fEnd-fStart,fFactor);
+                // calculate depreciation for whole periods
+                fValue -= ScInterVDB( fValue, fRest, fTimeLength, fTimeLength, fIntStart, fFactor );
+                fVdb = ScInterVDB( fValue, fRest, fTimeLength, fTimeLength - fIntStart,
+                    fIntEnd - fIntStart, fFactor);
+                fVdb -= fPart;
             }
         }
         PushDouble(fVdb);


More information about the Libreoffice-commits mailing list