summaryrefslogtreecommitdiff
path: root/sc/source/core/opencl/formulagroupcl.cxx
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2015-02-08 02:33:12 +0200
committerTor Lillqvist <tml@collabora.com>2015-02-08 09:58:18 +0200
commitf6dfb3b4098f4554782e35fdb471ef69f2f53386 (patch)
treefc8855d260ae8d3a3a5941708d3121fb4441a505 /sc/source/core/opencl/formulagroupcl.cxx
parent8c301bcc68eabafee0b9e19711857840be0e17de (diff)
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
Diffstat (limited to 'sc/source/core/opencl/formulagroupcl.cxx')
-rw-r--r--sc/source/core/opencl/formulagroupcl.cxx23
1 files changed, 22 insertions, 1 deletions
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"; }
};