sc/source/core/tool/interpr5.cxx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
New commits: commit b0fdf6cf11ee46d46925e9cd9fa2768a1b49bb64 Author: Supreme Aryal <supremear...@gmail.com> Date: Tue Dec 9 00:09:39 2014 -0500 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 diff --git a/sc/source/core/tool/interpr5.cxx b/sc/source/core/tool/interpr5.cxx index b6d616e..e6ca138 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 { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits