summaryrefslogtreecommitdiff
path: root/sc/source/core/tool/interpr1.cxx
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2022-05-12 19:23:14 +0200
committerEike Rathke <erack@redhat.com>2022-05-12 21:43:02 +0200
commit9391e9fb99a87e71897e29da79eba084682fdaa5 (patch)
tree1b20c86ac58ed53681d9ec03d478650b9e63ea9d /sc/source/core/tool/interpr1.cxx
parente9992e96faf92080402ab32322d16d51c367f6ce (diff)
Resolves: tdf#148863 In JumpMatrix context use its dimensions for results
Problem was, that in array mode the result matrix of random values was created according to the dimensions of the formula cell range selected/resulting, which if transposed and displayed obeys the general rules of a repeating vector if not a 2D matrix. For example, entering the array formula =TRANSPOSE(IF({1,1,1};RAND())) (with , comma array column separator) is supposed to create a row vector of 3 columns transposed to a column vector of 3 rows. The selection created for the automatically determined result is 3 rows in one column, for which the RAND() was calculated, resulting in a column vector { 1 2 3 } which transposed gave a row vector { 1, 2, 3 } and displayed for one column such row vector is repeated as { { 1, 2, 3 } { 1, 2, 3 } { 1, 2, 3 } } of which the first column displayed is the repeating first value 1. With this change the dimensions of the JumpMatrix created by IF({1,1,1};...) is used to generate the RAND() matrix, resulting in a { 1, 2, 3 } row vector that then is transposed and displayed as expected. Change-Id: I267ff5d336a86372ee456fd929249e5f0444f843 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134247 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins
Diffstat (limited to 'sc/source/core/tool/interpr1.cxx')
-rw-r--r--sc/source/core/tool/interpr1.cxx12
1 files changed, 11 insertions, 1 deletions
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 81b75fe21cd5..5b8e326a3c19 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -1743,7 +1743,17 @@ void ScInterpreter::ScRandomImpl( const std::function<double( double fFirst, dou
{
SCCOL nCols = 0;
SCROW nRows = 0;
- if (pMyFormulaCell)
+ // In JumpMatrix context use its dimensions for the return matrix; the
+ // formula cell range selected may differ, for example if the result is
+ // to be transposed.
+ if (pJumpMatrix)
+ {
+ SCSIZE nC, nR;
+ pJumpMatrix->GetDimensions( nC, nR);
+ nCols = std::max<SCCOL>(0, static_cast<SCCOL>(nC));
+ nRows = std::max<SCROW>(0, static_cast<SCROW>(nR));
+ }
+ else if (pMyFormulaCell)
pMyFormulaCell->GetMatColsRows( nCols, nRows);
if (nCols == 1 && nRows == 1)