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-03 15:34:35 +0100 |
commit | ac439c8c838a14db6ae02dff72dc8e8fffc333ef (patch) | |
tree | c55f3c2261e03d1ddd713fa576c433ffd1bf70e6 /sc/source/core/opencl | |
parent | a0b059a37e775a466c6fb0043335aae4d3e93fbf (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>
Diffstat (limited to 'sc/source/core/opencl')
-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"; } |