From f6dfb3b4098f4554782e35fdb471ef69f2f53386 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Sun, 8 Feb 2015 02:33:12 +0200 Subject: Create proper error when dividing by zero Create a so-called "double error", i.e. a NaN with a error code payload. Change-Id: I6d538426c184b30d067f8ef6035b49f3a8986f12 --- sc/source/core/opencl/formulagroupcl.cxx | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/sc/source/core/opencl/formulagroupcl.cxx b/sc/source/core/opencl/formulagroupcl.cxx index a4a3fcada82c..993bd53fd4c6 100644 --- a/sc/source/core/opencl/formulagroupcl.cxx +++ b/sc/source/core/opencl/formulagroupcl.cxx @@ -36,6 +36,27 @@ #define UNROLLING_FACTOR 16 // set to 4 for correctness testing (if no reduce) static const char* publicFunc = + "\n" + "#define errIllegalFPOperation 503 // #NUM!\n" + "#define errNoValue 519 // #VALUE!\n" + "#define errDivisionByZero 532 // #DIV/0!\n" + "\n" + "double CreateDoubleError(ulong nErr)\n" + "{\n" + " return nan(nErr);\n" + "}\n" + "\n" + "uint GetDoubleErrorValue(double fVal)\n" + "{\n" + " if (isfinite(fVal))\n" + " return 0;\n" + " if (isinf(fVal))\n" + " return errIllegalFPOperation; // normal INF\n" + " if (as_ulong(fVal) & 0XFFFF0000u)\n" + " return errNoValue; // just a normal NAN\n" + " return (as_ulong(fVal) & 0XFFFF); // any other error\n" + "}\n" + "\n" "int isNan(double a) { return isnan(a); }\n" "double fsum_count(double a, double b, __private int *p) {\n" " bool t = isNan(a);\n" @@ -2118,7 +2139,7 @@ public: virtual std::string GetBottom() SAL_OVERRIDE { return "1.0"; } virtual std::string Gen2( const std::string& lhs, const std::string& rhs ) const SAL_OVERRIDE { - return "(" + lhs + "/" + rhs + ")"; + return "(" + rhs + "==0 ? CreateDoubleError(errDivisionByZero) : (" + lhs + "/" + rhs + ") )"; } virtual std::string BinFuncName() const SAL_OVERRIDE { return "fdiv"; } }; -- cgit v1.2.3