[Libreoffice-commits] core.git: 2 commits - sc/inc sc/source
Eike Rathke
erack at redhat.com
Thu Aug 13 13:44:48 PDT 2015
sc/inc/math.hxx | 29 +++++++++++++++++++++++++++++
sc/source/core/tool/interpr3.cxx | 2 +-
2 files changed, 30 insertions(+), 1 deletion(-)
New commits:
commit 8747442d179367a9cea652643a516021fa7c5510
Author: Eike Rathke <erack at redhat.com>
Date: Thu Aug 13 22:36:20 2015 +0200
use sc::divide() for -fsanitize=float-divide-by-zero triggered by unit test
Change-Id: I370f2f5e3e0ceb40051cbf2f806072f4fd213811
diff --git a/sc/source/core/tool/interpr3.cxx b/sc/source/core/tool/interpr3.cxx
index ce3dc91..3fad7e7 100644
--- a/sc/source/core/tool/interpr3.cxx
+++ b/sc/source/core/tool/interpr3.cxx
@@ -2850,7 +2850,7 @@ void ScInterpreter::ScChiTest()
{
double fValX = pMat1->GetDouble(i,j);
double fValE = pMat2->GetDouble(i,j);
- fChi += (fValX - fValE) * (fValX - fValE) / fValE;
+ fChi += sc::divide( (fValX - fValE) * (fValX - fValE), fValE);
}
else
{
commit d0d76a9aad90c8f07330da7f67eef5c607a27aec
Author: Eike Rathke <erack at redhat.com>
Date: Thu Aug 13 22:03:53 2015 +0200
add sc::divide() for defined -fsanitize=float-divide-by-zero behavior
Change-Id: I3af85344119ca0056a127a5278e8993f9d79e2f9
diff --git a/sc/inc/math.hxx b/sc/inc/math.hxx
index 8a95f21..46f9a1d 100644
--- a/sc/inc/math.hxx
+++ b/sc/inc/math.hxx
@@ -24,12 +24,41 @@
namespace sc {
+/** Return fNumerator/fDenominator if fDenominator!=0 else #DIV/0! error coded
+ into double.
+ */
inline double div( const double& fNumerator, const double& fDenominator )
{
return (fDenominator != 0.0) ? (fNumerator / fDenominator) :
CreateDoubleError( errDivisionByZero);
}
+/** Return fNumerator/fDenominator if fDenominator!=0 else +-Infinity if
+ fNumerator!=0 or NaN if fNumerator==0.
+
+ This allows to build/run with -fsanitize=float-divide-by-zero and have a
+ defined behavior for the otherwise undefined division by zero case ("If the
+ second operand of / or % is zero the behavior is undefined."
+ ([expr.mul]/4)).
+
+ The Calc interpreter gracefully handles Infinity or NaN double values
+ encountered as interim or final results, using this function we can ensure
+ defined behavior where desired.
+
+ Use where the double coded error creating div() is not wanted.
+ */
+inline double divide( const double& fNumerator, const double& fDenominator )
+{
+ if (fDenominator == 0.0) {
+ if (std::isfinite(fNumerator) && fNumerator != 0.0) {
+ return std::copysign(INFINITY, fNumerator);
+ } else {
+ return NAN;
+ }
+ }
+ return fNumerator / fDenominator;
+}
+
}
#endif
More information about the Libreoffice-commits
mailing list