summaryrefslogtreecommitdiff
path: root/sc/source/core
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2021-05-03 17:07:39 +0200
committerEike Rathke <erack@redhat.com>2021-05-03 19:39:33 +0200
commit9a71644aa475a6090f60a8b90665116b98851b9c (patch)
treeef74c5f7dc6340b7dfb5e6f72bb3d3095f753037 /sc/source/core
parentdff586735b6618d9b011823594a33287d8f7f223 (diff)
RAWSUBTRACT() process arguments from left to right
RAWSUBTRACT(1;2;3;4) calculated 1-4-3-2, popping from stack. Reverse stack to calculate 1-2-3-4 in "natural" left to right order. That may make a difference like in =RAWSUBTRACT(0.3;0.2;0.1;-0.1;-0.2;0.3) where the result was 2.77555756156289E-17 (0.3-0.3--0.2--0.1-0.1-0.2) == (0.0--0.2--0.1-0.1-0.2) same as =RAWSUBTRACT(0;0.2;0.1;-0.1;-0.2) and now is 0 (0.3-0.2-0.1--0.1--0.2-0.3) but =RAWSUBTRACT(0;0.2;0.1;-0.1;-0.2) now is -2.77555756156289E-17 Change-Id: If00d88e3d3d1944a3d9a6b4576b773afe9cbd294 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115047 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'sc/source/core')
-rw-r--r--sc/source/core/tool/interpr6.cxx8
1 files changed, 3 insertions, 5 deletions
diff --git a/sc/source/core/tool/interpr6.cxx b/sc/source/core/tool/interpr6.cxx
index a48d7d3ad77b..0e2824ef1f2e 100644
--- a/sc/source/core/tool/interpr6.cxx
+++ b/sc/source/core/tool/interpr6.cxx
@@ -995,17 +995,15 @@ void ScInterpreter::ScRawSubtract()
if (!MustHaveParamCountMin( nParamCount, 2))
return;
- // Fish the 1st parameter from the stack and push it on top.
- const FormulaToken* p = pStack[ sp - nParamCount ];
- PushWithoutError( *p );
+ // Reverse stack to process arguments from left to right.
+ ReverseStack( nParamCount);
// Obtain the minuend.
double fRes = GetDouble();
- while (nGlobalError == FormulaError::NONE && nParamCount > 1)
+ while (nGlobalError == FormulaError::NONE && --nParamCount > 0)
{
// Simple single values without matrix support.
fRes -= GetDouble();
- --nParamCount;
}
while (nParamCount-- > 0)
PopError();