summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSupreme Aryal <supremearyal@gmail.com>2014-12-09 00:09:39 -0500
committerEike Rathke <erack@redhat.com>2015-02-13 11:57:15 +0100
commitb0fdf6cf11ee46d46925e9cd9fa2768a1b49bb64 (patch)
treedb92807e3f7dfe2b638a1004348039262cb373af
parentnative-code.py: Don't add the entire libchartcorelo.a. (diff)
downloadcore-b0fdf6cf11ee46d46925e9cd9fa2768a1b49bb64.tar.gz
core-b0fdf6cf11ee46d46925e9cd9fa2768a1b49bb64.zip
Compute n-th root of negative numbers where n is odd. (tdf#69293)
Compute expressions like (-8)^(1/3) correctly. This makes calculations compatible with Excel. Exponents must reduce to the form 1/n. Change-Id: I007c818f584323f80f2f6b1000d931f19a4590ad
-rw-r--r--sc/source/core/tool/interpr5.cxx15
1 files changed, 14 insertions, 1 deletions
diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx
index b6d616e11619..e6ca13816579 100644
--- a/sc/source/core/tool/interpr5.cxx
+++ b/sc/source/core/tool/interpr5.cxx
@@ -1654,7 +1654,20 @@ void ScInterpreter::ScPow()
PushIllegalArgument();
}
else
- PushDouble(pow(fVal1,fVal2));
+ {
+ if (fVal1 < 0 && fVal2 != 0.0)
+ {
+ int i = (int) (1 / fVal2 + ((fVal2 < 0) ? -0.5 : 0.5));
+ if (rtl::math::approxEqual(1 / ((double) i), fVal2) && i % 2 != 0)
+ PushDouble(-pow(-fVal1, fVal2));
+ else
+ PushDouble(pow(fVal1, fVal2));
+ }
+ else
+ {
+ PushDouble(pow(fVal1,fVal2));
+ }
+ }
}
namespace {