sc/source/core/opencl/op_statistical.cxx | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-)
New commits: commit ac439c8c838a14db6ae02dff72dc8e8fffc333ef Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Fri Nov 30 12:43:13 2018 +0100 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Mon Dec 3 15:34:35 2018 +0100 fix OpenCL PEARSON() Some error checking, but also simply use "if(cond) code;" rather than "if(!cond) try-to-set-benign-values-that-will-break-things-nevertheless". Change-Id: Ic0c296273ba4c174dba5e96eadeeee4005988142 Reviewed-on: https://gerrit.libreoffice.org/64342 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> diff --git a/sc/source/core/opencl/op_statistical.cxx b/sc/source/core/opencl/op_statistical.cxx index 62f35865c7c7..374b383dcc4c 100644 --- a/sc/source/core/opencl/op_statistical.cxx +++ b/sc/source/core/opencl/op_statistical.cxx @@ -3274,11 +3274,14 @@ void OpPearson::GenSlidingWindowFunction( ss << ";\n"; ss << " fIny = "<<vSubArguments[1]->GenSlidingWindowDeclRef(true); ss << " ;\n"; - ss << " if(isnan(fInx)||isnan(fIny)){fInx=0.0;fIny=0.0;fCount = fCount-1;}\n"; + ss << " if(!isnan(fInx)&&!isnan(fIny)){\n"; ss << " fSumX += fInx;\n"; ss << " fSumY += fIny;\n"; ss << " fCount = fCount + 1;\n"; + ss << " }\n"; ss << " }\n"; + ss << " if(fCount < 1)\n"; + ss << " return CreateDoubleError(NoValue);\n"; ss << " double fMeanX = fSumX / fCount;\n"; ss << " double fMeanY = fSumY / fCount;\n"; ss << " fSumX = 0.0;\n"; @@ -3301,15 +3304,15 @@ void OpPearson::GenSlidingWindowFunction( ss << " ;\n"; ss << " fIny = "<<vSubArguments[1]->GenSlidingWindowDeclRef(true); ss << " ;\n"; - ss << " if(isnan(fInx)||isnan(fIny)){fInx=0.0;fIny=0.0;}\n"; + ss << " if(!isnan(fInx)&&!isnan(fIny)){\n"; ss << " fSumDeltaXDeltaY += (fInx - fMeanX) * (fIny - fMeanY);\n"; - ss << " fSumX += pow(fInx - fMeanX,2);\n"; - ss << " fSumY += pow(fIny - fMeanY,2);\n"; + ss << " fSumX += (fInx - fMeanX) * (fInx - fMeanX);\n"; + ss << " fSumY += (fIny - fMeanY) * (fIny - fMeanY);\n"; + ss << " }\n"; ss << " }\n"; - ss << " double tmp = ( fSumDeltaXDeltaY / "; - ss << "sqrt( fSumX * fSumY));\n\t"; - ss << " if (isnan(tmp))\n"; - ss << " return CreateDoubleError(NoValue);\n"; + ss << " if (fSumX == 0 || fSumY == 0)\n"; + ss << " return CreateDoubleError(DivisionByZero);\n"; + ss << " double tmp = ( fSumDeltaXDeltaY / sqrt( fSumX * fSumY));\n"; ss << " return tmp;\n"; ss << "}\n"; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits