Download it now!
Bug 69293 - Error taking Cube Root of Negative Number
Summary: Error taking Cube Root of Negative Number
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: Other All
: medium normal
Assignee: supremearyal
URL:
Whiteboard: target:4.5.0
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-12 21:41 UTC by Mike Kaganski
Modified: 2018-11-15 14:37 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2013-09-12 21:41:31 UTC
This is a long-standing problem inherited from OOo. I cannot find a dupe for it in this issue tracker, so here it goes.
See https://issues.apache.org/ooo/show_bug.cgi?id=37129 for discussion.

Quoting the abovementioned issue:
"It looks like calc is unable to evaluate odd roots (a number raised to the power of 1/3,1/5,1/7,...etc).  For instance if you type in as a formula -8^(1/3), calc returns #VALUE when the answer should be -2.  It looks like any negative number you raise to a fractional exponent can't be evaluated. For even roots this should be expected since imaginary values would result, however odd roots should result in real values."

"It leads to incompatibility with MS Excel and thus, to difficulties in migration.

The general math rule says that "For odd values of n, every negative number has a real negative nth root" (http://en.wikipedia.org/wiki/Nth_root). And it's not correct to spaculate that "(-8)^(1/3)=(-8)^(2/6)=((-8)^2))^(1/6)=64^(1/6)=2". This speculation is a sort of sophism that masks the fact that there are more than one nth roots. When you make any transformations of powers you must take into account the possible loss of some roots or introduction of new roots. The correct result of "sqrt(x)" should be a multitude of two (possibly complex) numbers, not a single number. As we cannot return such a result in a spreadsheet we agree to see only positive answer, but it doesn't mean that we don't deserve to get correct negative real number as a cube root of a negative number.

To be specific: x != sqrt(x^2), because, strictly speaking, sqrt(x^2) = {x, -x}. So (-8)^(1/3) = (-8)^(2/6) [because you calculate 2/6 _before_ you calculate the exponent - brackets specify the order] != ((-8)^2))^(1/6), because here in the last case the base is raised to 2nd power and then the 6th root is taken, and the extra "2" brings new roots here (positive ones).

[Workaround] for those who want to find the cube root:
SIGN(X)*ABS(X)^(1/3)"

Still present in LO 4.1.2.1 under Win7x64.
Comment 1 tommy27 2013-09-26 19:15:25 UTC
set status to NEW because of confirmation in old OOo bug report cited in previous comment.
Comment 2 Commit Notification 2015-02-13 10:58:33 UTC
Supreme Aryal committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=b0fdf6cf11ee46d46925e9cd9fa2768a1b49bb64

Compute n-th root of negative numbers where n is odd. (tdf#69293)

It will be available in 4.5.0.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.