From 08b0c3b848b8f2bd667fad00068f3c828c709ef5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= Date: Thu, 1 Sep 2022 13:59:50 +0200 Subject: [PATCH] fixes to opencl rounding functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I5cd99116a7230b8070051cbf6969a1fdd2f7fe62 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139196 Tested-by: Jenkins Reviewed-by: Luboš Luňák --- sc/source/core/opencl/op_math.cxx | 55 +++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/sc/source/core/opencl/op_math.cxx b/sc/source/core/opencl/op_math.cxx index 7cb632050aa4..edcc2b940bd6 100644 --- a/sc/source/core/opencl/op_math.cxx +++ b/sc/source/core/opencl/op_math.cxx @@ -1670,27 +1670,28 @@ void OpRoundUp::GenSlidingWindowFunction(outputstream &ss, ss << " int gid0=get_global_id(0);\n"; ss << " int singleIndex = gid0;\n"; ss << " int intTmp;\n"; - ss << " double doubleTmp;\n"; ss << " double tmp;\n"; GenTmpVariables(ss,vSubArguments); CheckAllSubArgumentIsNan(ss,vSubArguments); if( vSubArguments.size() == 1 ) ss << " double tmp1 = 0;\n"; - ss << " if(tmp1 >20 || tmp1 < -20)"; + ss << " int shift = (int)tmp1;\n"; + ss << " if(shift >20 || shift < -20)"; ss << " {\n"; ss << " tmp = NAN;\n"; ss << " }else\n"; ss << " {\n"; - ss << " for(int i=0;ishift;i--)\n"; + ss << " multiply /= 10;\n"; + ss << " intTmp = (int)(tmp0*multiply);\n"; + ss << " if(tmp0 >= 0)\n"; + ss << " tmp = intTmp + 1;\n"; ss << " else\n"; - ss << " tmp = doubleTmp + 1;\n"; - ss << " for(int i=0;i20 || tmp1 < -20)"; + ss << " int shift = (int)tmp1;\n"; + ss << " if(shift >20 || shift < -20)"; ss << " {\n"; ss << " tmp = NAN;\n"; ss << " }else\n"; ss << " {\n"; - ss << " for(int i=0;ishift;i--)\n"; + ss << " multiply /= 10;\n"; + ss << " intTmp = (int)(tmp0*multiply);\n"; ss << " tmp = intTmp;\n"; - ss << " for(int i=0;i=0 && approx_equal( intTmp + 1, tmp0 ))\n"; + ss << " ++intTmp;\n"; + // negative values are rounded down + ss << " if( tmp0 < 0 && !approx_equal( intTmp, tmp0 ))\n"; + ss << " --intTmp;\n"; ss << " tmp = intTmp;\n"; ss << " return tmp;\n"; ss << "}"; @@ -2173,6 +2183,11 @@ void OpTrunc::GenSlidingWindowFunction(outputstream &ss, ss << " argm = argm * 10;\n"; ss << " nn = nn * 10;\n"; ss << " }\n"; + ss << " for(int i = 0; i > n; --i)\n"; + ss << " {\n"; + ss << " argm = argm / 10;\n"; + ss << " nn = nn / 10;\n"; + ss << " }\n"; ss << " modf(argm, &argm);\n"; ss << " return argm / nn;\n"; ss << "}"; @@ -2207,7 +2222,9 @@ void OpFloor::GenSlidingWindowFunction( ss << " if(isnan(arg2))\n"; ss << " arg2 = 0.0;\n"; ss << " if(arg0*arg1<0)\n"; - ss << " return NAN;\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; + ss << " if(arg1 == 0.0)\n"; + ss << " return 0.0;\n"; ss << " else if(arg2==0.0&&arg0<0.0)\n"; ss << " return (trunc(arg0/arg1)+1)*arg1;\n"; ss << " else\n"; @@ -2574,6 +2591,8 @@ void OpCeil::GenSlidingWindowFunction(outputstream &ss, ss << " else\n "; ss << " bAbs = "<GenSlidingWindowDeclRef()<<";\n"; } + ss << " if(num*significance < 0.0)\n"; + ss << " return CreateDoubleError(IllegalArgument);\n"; ss << " if(significance == 0.0)\n"; ss << " return 0.0;\n"; ss << " return ";