summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorWinfried Donkers <winfrieddonkers@libreoffice.org>2016-08-01 16:31:15 +0200
committerEike Rathke <erack@redhat.com>2016-08-16 15:33:18 +0000
commita81eac7ce80732f983eb06713ac79c9cd4c5340f (patch)
treeb8fd98faaf819d552d2ab6490aeb980cc2afa231 /sc
parentc3c5635b9bbd3de65760409c7f4e72b295b749be (diff)
tdf#101204 make VDB return correct results for fractional periods.
Change-Id: I97f7ff5f0c632a2b2e0501919a4d0fc1414fa028 Reviewed-on: https://gerrit.libreoffice.org/27779 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/tool/interpr2.cxx43
1 files changed, 27 insertions, 16 deletions
diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx
index 455ac73f28a3..37d84650215a 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);