diff options
author | Winfried Donkers <winfrieddonkers@libreoffice.org> | 2017-03-04 09:29:58 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-03-06 16:39:16 +0000 |
commit | 67bff281f9befbea8b4ff028fabe056b8c4e184b (patch) | |
tree | efcea15dc4158e1ef0dafdb6f571025e8b762b7b /sc | |
parent | 055c8cc676921176e2b9df76bd0e09bacab1d80b (diff) |
Add constraint and divide by 0 check for Calc function RRI.
Plus rename variables with correct prefixes and common names.
Test for type of error in unit test.
Change-Id: I48d2fee180e5e093189c1bb6fe889cbf74260fc4
Reviewed-on: https://gerrit.libreoffice.org/34882
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/data/functions/financial/fods/rri.fods | 51 | ||||
-rw-r--r-- | sc/source/core/tool/interpr2.cxx | 11 |
2 files changed, 41 insertions, 21 deletions
diff --git a/sc/qa/unit/data/functions/financial/fods/rri.fods b/sc/qa/unit/data/functions/financial/fods/rri.fods index 09f9760cae21..b687cbd11291 100644 --- a/sc/qa/unit/data/functions/financial/fods/rri.fods +++ b/sc/qa/unit/data/functions/financial/fods/rri.fods @@ -2409,7 +2409,7 @@ </table:table-row> <table:table-row table:style-name="ro6"> <table:table-cell table:style-name="ce11" table:formula="of:=RRI(96;10000;-11000)" office:value-type="string" office:string-value="" calcext:value-type="error"> - <text:p>#VALUE!</text:p> + <text:p>#NUM!</text:p> </table:table-cell> <table:table-cell office:value-type="string" calcext:value-type="string"> <text:p>error</text:p> @@ -2429,7 +2429,7 @@ </table:table-row> <table:table-row table:style-name="ro6"> <table:table-cell table:style-name="ce11" table:formula="of:=RRI(96;-10000;11000)" office:value-type="string" office:string-value="" calcext:value-type="error"> - <text:p>#VALUE!</text:p> + <text:p>#NUM!</text:p> </table:table-cell> <table:table-cell office:value-type="string" calcext:value-type="string"> <text:p>error</text:p> @@ -2450,18 +2450,21 @@ </table:table-row> <table:table-row table:style-name="ro6"> <table:table-cell table:style-name="ce11" table:formula="of:=RRI(0;10000;11000)" office:value-type="string" office:string-value="" calcext:value-type="error"> - <text:p>#NUM!</text:p> + <text:p>Err:502</text:p> </table:table-cell> - <table:table-cell office:value-type="string" calcext:value-type="string"> - <text:p>error</text:p> + <table:table-cell table:formula="of:#ERR502!" office:value-type="string" office:string-value="" calcext:value-type="error"> + <text:p>Err:502</text:p> </table:table-cell> - <table:table-cell table:style-name="ce20" table:formula="of:=ISERROR([.A8])" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean"> + <table:table-cell table:style-name="ce20" table:formula="of:=ORG.OPENOFFICE.ERRORTYPE([.A8])=502" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean"> <text:p>TRUE</text:p> </table:table-cell> <table:table-cell table:style-name="ce25" table:formula="of:=FORMULA([.A8])" office:value-type="string" office:string-value="=RRI(0,10000,11000)" calcext:value-type="string"> <text:p>=RRI(0,10000,11000)</text:p> </table:table-cell> - <table:table-cell table:number-columns-repeated="5"/> + <table:table-cell office:value-type="string" calcext:value-type="string"> + <text:p>constraint N>0</text:p> + </table:table-cell> + <table:table-cell table:number-columns-repeated="4"/> <table:table-cell table:style-name="ce37"/> <table:table-cell table:style-name="ce35"/> <table:table-cell/> @@ -2490,18 +2493,21 @@ </table:table-row> <table:table-row table:style-name="ro6"> <table:table-cell table:style-name="ce11" table:formula="of:=RRI(96;;11000)" office:value-type="string" office:string-value="" calcext:value-type="error"> - <text:p>#NUM!</text:p> + <text:p>Err:502</text:p> </table:table-cell> - <table:table-cell office:value-type="string" calcext:value-type="string"> - <text:p>error</text:p> + <table:table-cell table:formula="of:#ERR502!" office:value-type="string" office:string-value="" calcext:value-type="error"> + <text:p>Err:502</text:p> </table:table-cell> - <table:table-cell table:style-name="ce20" table:formula="of:=ISERROR([.A10])" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean"> + <table:table-cell table:style-name="ce70" table:formula="of:=ORG.OPENOFFICE.ERRORTYPE([.A10])=502" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean"> <text:p>TRUE</text:p> </table:table-cell> <table:table-cell table:style-name="ce25" table:formula="of:=FORMULA([.A10])" office:value-type="string" office:string-value="=RRI(96,,11000)" calcext:value-type="string"> <text:p>=RRI(96,,11000)</text:p> </table:table-cell> - <table:table-cell table:number-columns-repeated="6"/> + <table:table-cell office:value-type="string" calcext:value-type="string"> + <text:p>check for divide by 0</text:p> + </table:table-cell> + <table:table-cell table:number-columns-repeated="5"/> <table:table-cell table:style-name="ce39"/> <table:table-cell/> <table:table-cell table:style-name="ce43"/> @@ -2509,11 +2515,22 @@ <table:table-cell table:number-columns-repeated="6"/> </table:table-row> <table:table-row table:style-name="ro6"> - <table:table-cell table:style-name="ce12"/> - <table:table-cell/> - <table:table-cell table:style-name="ce21"/> - <table:table-cell table:style-name="ce25"/> - <table:table-cell table:number-columns-repeated="6"/> + <table:table-cell table:style-name="ce12" table:formula="of:=RRI(4;0;10000)" office:value-type="string" office:string-value="" calcext:value-type="error"> + <text:p>Err:502</text:p> + </table:table-cell> + <table:table-cell table:formula="of:#ERR502!" office:value-type="string" office:string-value="" calcext:value-type="error"> + <text:p>Err:502</text:p> + </table:table-cell> + <table:table-cell table:style-name="ce71" table:formula="of:=ORG.OPENOFFICE.ERRORTYPE([.A11])=502" office:value-type="boolean" office:boolean-value="true" calcext:value-type="boolean"> + <text:p>TRUE</text:p> + </table:table-cell> + <table:table-cell table:style-name="ce25" table:formula="of:=FORMULA([.A11])" office:value-type="string" office:string-value="=RRI(4,0,10000)" calcext:value-type="string"> + <text:p>=RRI(4,0,10000)</text:p> + </table:table-cell> + <table:table-cell office:value-type="string" calcext:value-type="string"> + <text:p>check for divide by 0</text:p> + </table:table-cell> + <table:table-cell table:number-columns-repeated="5"/> <table:table-cell table:style-name="ce39"/> <table:table-cell table:number-columns-repeated="9"/> </table:table-row> diff --git a/sc/source/core/tool/interpr2.cxx b/sc/source/core/tool/interpr2.cxx index a5dae57722fe..cf305836b3a2 100644 --- a/sc/source/core/tool/interpr2.cxx +++ b/sc/source/core/tool/interpr2.cxx @@ -1948,10 +1948,13 @@ void ScInterpreter::ScRRI() nFuncFmtType = css::util::NumberFormat::PERCENT; if ( MustHaveParamCount( GetByte(), 3 ) ) { - double nValueInFuture = GetDouble(); - double nValueNow = GetDouble(); - double nSpaceOfTime = GetDouble(); - PushDouble(pow(nValueInFuture / nValueNow, 1.0 / nSpaceOfTime) - 1.0); + double fFutureValue = GetDouble(); + double fPresentValue = GetDouble(); + double NrOfPeriods = GetDouble(); + if ( NrOfPeriods <= 0.0 || fPresentValue == 0.0 ) + PushIllegalArgument(); + else + PushDouble(pow(fFutureValue / fPresentValue, 1.0 / NrOfPeriods) - 1.0); } } |