From c9de441f84ad4641662f2ce510868f3e3164a22f Mon Sep 17 00:00:00 2001 From: dante Date: Wed, 12 May 2021 11:17:57 +0200 Subject: Use double to iterate products in scmatrix. Change-Id: If094c33d396dc5aba31b37a3042add72076f344f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115468 Reviewed-by: Eike Rathke Tested-by: Mike Kaganski --- sc/inc/matrixoperators.hxx | 2 +- sc/inc/scmatrix.hxx | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) (limited to 'sc/inc') diff --git a/sc/inc/matrixoperators.hxx b/sc/inc/matrixoperators.hxx index 36fa1cabe3d6..813813626350 100644 --- a/sc/inc/matrixoperators.hxx +++ b/sc/inc/matrixoperators.hxx @@ -48,7 +48,7 @@ struct SumSquare struct Product { static const double InitVal; - void operator()(KahanSum& rAccum, double fVal) const; + void operator()(double& rAccum, double fVal) const; }; } diff --git a/sc/inc/scmatrix.hxx b/sc/inc/scmatrix.hxx index 463b15e17b42..c91253811398 100644 --- a/sc/inc/scmatrix.hxx +++ b/sc/inc/scmatrix.hxx @@ -140,29 +140,30 @@ public: * summation algorithm, * https://en.wikipedia.org/wiki/Kahan_summation_algorithm */ - struct IterateResult + struct IterateResultMultiple { double mfFirst; double mfRest; size_t mnCount; - IterateResult(double fFirst, double fRest, size_t nCount) : + IterateResultMultiple(double fFirst, double fRest, size_t nCount) : mfFirst(fFirst), mfRest(fRest), mnCount(nCount) {} }; /** - * Version of IterateResult for using Kahan sum. + * Iterator for executing one operation with the matrix data. */ - struct KahanIterateResult + template + struct IterateResult { - KahanSum maAccumulator; + tRes maAccumulator; size_t mnCount; - KahanIterateResult(double fAccumulator, size_t nCount) + IterateResult(tRes fAccumulator, size_t nCount) : maAccumulator(fAccumulator), mnCount(nCount) {} - - double get() const { return maAccumulator.get(); } }; + typedef IterateResult KahanIterateResult; + typedef IterateResult DoubleIterateResult; /** Checks nC or nR for zero and uses GetElementsMax() whether a matrix of @@ -378,7 +379,7 @@ public: KahanIterateResult Sum( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ; KahanIterateResult SumSquare( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ; - KahanIterateResult Product( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ; + DoubleIterateResult Product( bool bTextAsZero, bool bIgnoreErrorValues = false ) const ; size_t Count(bool bCountStrings, bool bCountErrors, bool bIgnoreEmptyStrings = false) const ; size_t MatchDoubleInColumns(double fValue, size_t nCol1, size_t nCol2) const ; size_t MatchStringInColumns(const svl::SharedString& rStr, size_t nCol1, size_t nCol2) const ; @@ -410,7 +411,7 @@ public: void DivOp(bool bFlag, double fVal, const ScMatrix& rMat) ; void PowOp(bool bFlag, double fVal, const ScMatrix& rMat) ; - std::vector Collect(const std::vector& aOp) ; + std::vector Collect(const std::vector& aOp) ; void ExecuteOperation(const std::pair& rStartPos, const std::pair& rEndPos, DoubleOpFunction aDoubleFunc, BoolOpFunction aBoolFunc, StringOpFunction aStringFunc, -- cgit