diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2018-11-30 12:43:13 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2018-12-04 17:45:56 +0100 |
commit | 75395a68afa46dab3906275c46cd8542019c0f4c (patch) | |
tree | c854160ef4ae7447d8a04d5c134d9967f0f11bfa /sc | |
parent | b0c87ae5b671b9092c5460828c0a3c96f987e65c (diff) |
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.lunak@collabora.com>
(cherry picked from commit ac439c8c838a14db6ae02dff72dc8e8fffc333ef)
Reviewed-on: https://gerrit.libreoffice.org/64466
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/core/opencl/op_statistical.cxx | 19 |
1 files changed, 11 insertions, 8 deletions
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"; } |