[Upstream] =(-8)^(1/3)

Bug #264345 reported by Fournier Frédéric
10
Affects Status Importance Assigned to Milestone
LibreOffice
Confirmed
Wishlist
OpenOffice
Unknown
Low
libreoffice (Ubuntu)
Fix Released
Medium
Unassigned
openoffice.org (Ubuntu)
Won't Fix
Low
Unassigned

Bug Description

1) lsb_release -rd
Description: Ubuntu 11.04
Release: 11.04

2) apt-cache policy libreoffice-calc
libreoffice-calc:
  Installed: 1:3.3.3-1ubuntu2
  Candidate: 1:3.3.3-1ubuntu2
  Version table:
 *** 1:3.3.3-1ubuntu2 0
        500 http://us.archive.ubuntu.com/ubuntu/ natty-updates/main i386 Packages
        100 /var/lib/dpkg/status
     1:3.3.2-1ubuntu4 0
        500 http://us.archive.ubuntu.com/ubuntu/ natty/main i386 Packages

3) What is expected to happen is when one types in a cell:

=(-8)^(1/3)

one gets -2 as the answer.

4) What happens instead is one receives #VALUE! as the answer.

WORKAROUND: SIGN(X)*ABS(X)^(1/3)

WORKAROUND: Use Excel in WINE.

Microsoft Office Excel 2003 (11.5612.6505)

apt-cache policy wine1.3
wine1.3:
  Installed: 1.3.28-0ubuntu1~ppa1~natty1
  Candidate: 1.3.28-0ubuntu1~ppa1~natty1
  Version table:
 *** 1.3.28-0ubuntu1~ppa1~natty1 0
        500 http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu/ natty/main i386 Packages
        100 /var/lib/dpkg/status
     1.3.15-0ubuntu5 0
        500 http://us.archive.ubuntu.com/ubuntu/ natty/universe i386 Packages

Tags: lo33 natty
Revision history for this message
In , Kmorning (kmorning) wrote :

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.

Revision history for this message
In , Frank-l (frank-l) wrote :

Hi,

it's the same problem as described in Issue 24271. Therefore I close this one as
double.

Frank

*** This issue has been marked as a duplicate of 24271 ***

Revision history for this message
In , Frank-l (frank-l) wrote :

closed double

Revision history for this message
In , Frank-l (frank-l) wrote :

Sorry,

not a double.

Frank

Revision history for this message
In , Frank-l (frank-l) wrote :

Hi Eike,

please have a look.

Frank

Revision history for this message
In , Niklas-nebel (niklas-nebel) wrote :

This should be changed, but it's not inportant enough for target "2.0".

Revision history for this message
In , Cs213006 (cs213006) wrote :

Bug repeated in OOo1.1.3/Linux and 680m74 on WinXP

Revision history for this message
In , Cbx550f (cbx550f) wrote :

Repeated in 2.0.3 Linux

Revision history for this message
In , Rb-henschel (rb-henschel) wrote :

Why do you want to change it? It is dangerous to calculate like (-8)^(1/3)=-2.
Look at this:
(-8)^(1/3)=(-8)^(2/6)=((-8)^2))^(1/6)=64^(1/6)=2

If you use fractions in exponents and want to keep the rules for exponents, than
you cannot allow negative base. And ^ and POWER calculate with exponents.

There are other opinions, but then you are speaking of a cube root, which would
be a new function in Calc.

Revision history for this message
In , Rb-henschel (rb-henschel) wrote :

*** Issue 74782 has been marked as a duplicate of this issue. ***

Revision history for this message
Chris Coulson (chrisccoulson) wrote :

Whats wrong with '(-8)^(1/3)=-2'?

If you work back the other way (ie '(-2)^3'), we get (-2)*(-2)*(-2)=-8, so this is correct

Changed in openoffice.org:
status: New → Incomplete
Revision history for this message
Fournier Frédéric (frederic31-fournier) wrote : Re: [Bug 264345] Re: =(-8)^(1/3)

it just me references: "value" and not -2
translated by Google

Le mercredi 03 septembre 2008 à 14:56 +0000, Chris Coulson a écrit :
> Whats wrong with '(-8)^(1/3)=-2'?
>
> If you work back the other way (ie '(-2)^3'), we get (-2)*(-2)*(-2)=-8,
> so this is correct
>
> ** Changed in: openoffice.org (Ubuntu)
> Status: New => Incomplete
>

Revision history for this message
Chris Coulson (chrisccoulson) wrote : Re: =(-8)^(1/3)

I understand now! I can confirm this behaviour too, but I want to see if it is a documented limitation of the software.

Changed in openoffice.org:
status: Incomplete → New
Revision history for this message
Martin Kretzschmar (martink) wrote : Re: [Bug 264345] Re: =(-8)^(1/3)

I'm not an expert on computer arithmetic, but I would guess that this
can only be solved using symbolic algebra, or by storing rational
numbers as rationals, or by using complex arithmetic. Openoffice.org
most likely uses plain floating point arithmetic, so cannot solve
this.

Revision history for this message
Fournier Frédéric (frederic31-fournier) wrote :

no, what should be done on a mathematical point of view, if you want to
calculate x ^ (n / m), is to do a test of parity on m:
if m is even then if x <0 I can not calculate x ^ (n / m) because
complex
if m is odd then if X <0 then the calculation becomes (-x) ^ (n / m)

Apply this method manually in Openoffice.org, you will see it works.

Le mercredi 03 septembre 2008 à 16:04 +0000, Martin Kretzschmar a
écrit :
> I'm not an expert on computer arithmetic, but I would guess that this
> can only be solved using symbolic algebra, or by storing rational
> numbers as rationals, or by using complex arithmetic. Openoffice.org
> most likely uses plain floating point arithmetic, so cannot solve
> this.
>

Revision history for this message
Fournier Frédéric (frederic31-fournier) wrote :

Le jeudi 04 septembre 2008 à 17:58 +0000, Fournier Frédéric a écrit :
>
> no, what should be done on a mathematical point of view, if you want to
> calculate x ^ (n / m), is to do a test of parity on m:
> if m is even then if x <0 I can not calculate x ^ (n / m) because
> complex
> if m is odd then if X <0 then the calculation becomes (-x) ^ (n / m)
erratum (-(-x)^(1/m))^n
>
> Apply this method manually in Openoffice.org, you will see it works.
>
>
> Le mercredi 03 septembre 2008 à 16:04 +0000, Martin Kretzschmar a
> écrit :
> > I'm not an expert on computer arithmetic, but I would guess that this
> > can only be solved using symbolic algebra, or by storing rational
> > numbers as rationals, or by using complex arithmetic. Openoffice.org
> > most likely uses plain floating point arithmetic, so cannot solve
> > this.
> >
>

Revision history for this message
Fournier Frédéric (frederic31-fournier) wrote : Re: [Bug 264345] Re: =(-8)^(1/3) algo floating...

Here is an algorithm that gives you the smallest denominator of a floating number written in the form of fraction.
with that you can solve the problem even if in the calculation of x ^
(n / m), n / m is transformed into a floating because you can
find something iteration.

I use that frac referrals factionnaire part of a number:
frac(1.255)=0.255;

is a recursive function:

function d=donominateur(x)
  if (frac(x)>-0.000001 and frac(x)<0.000001)
     then d=1/x;
  else d=1/x*donominateur(1/x);
end if
end function

I have one. ods of this algorithm to show that the algorithm works, we
can show mathematically a recurrence but is a long time.
The only flaw of this algorithm is the accuracy of the test: "frac
(x)>-esp and frac (x) <eps." the accuracy of x must be less than esp.
I just send this. Ods on the list if you want?

Le mercredi 03 septembre 2008 à 16:04 +0000, Martin Kretzschmar a écrit :
> I'm not an expert on computer arithmetic, but I would guess that this
> can only be solved using symbolic algebra, or by storing rational
> numbers as rationals, or by using complex arithmetic. Openoffice.org
> most likely uses plain floating point arithmetic, so cannot solve
> this.
>

Revision history for this message
Fournier Frédéric (frederic31-fournier) wrote :

Le vendredi 05 septembre 2008 à 08:14 +0000, Fournier Frédéric a écrit :
>
> Here is an algorithm that gives you the smallest denominator of a floating number written in the form of fraction.
> with that you can solve the problem even if in the calculation of x ^
> (n / m), n / m is transformed into a floating because you can
> find something iteration.
>
> I use that frac referrals factionnaire part of a number:
> frac(1.255)=0.255;
>
> is a recursive function:
>
> function d=donominateur(x)
> if (frac(x)>-0.000001 and frac(x)<0.000001)
> then d=1/x;
eratum then d=1;
> else d=1/x*donominateur(1/x);
> end if
> end function
>
>
> I have one. ods of this algorithm to show that the algorithm works, we
> can show mathematically a recurrence but is a long time.
> The only flaw of this algorithm is the accuracy of the test: "frac
> (x)>-esp and frac (x) <eps." the accuracy of x must be less than esp.
> I just send this. Ods on the list if you want?
>
>
>
> Le mercredi 03 septembre 2008 à 16:04 +0000, Martin Kretzschmar a écrit :
> > I'm not an expert on computer arithmetic, but I would guess that this
> > can only be solved using symbolic algebra, or by storing rational
> > numbers as rationals, or by using complex arithmetic. Openoffice.org
> > most likely uses plain floating point arithmetic, so cannot solve
> > this.
> >
>

Revision history for this message
Neil Munro (neilmunro-deactivatedaccount) wrote : Re: =(-8)^(1/3)

Thanks for your bug report, I have tested this under Ubuntu 8.04 with openoffice 2.4.1 and I can confirm this happens, please find attached a screenshot of this occurring.

Changed in openoffice.org:
status: New → Confirmed
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

FWIW, this works correctly in Excel. I'll forward this upstream when I get home tonight.

Changed in openoffice.org:
importance: Undecided → Low
Revision history for this message
Chris Coulson (chrisccoulson) wrote :

This is reported upstream

Changed in openoffice.org:
status: Confirmed → Triaged
Revision history for this message
In , Rb-henschel (rb-henschel) wrote :

*** Issue 94487 has been marked as a duplicate of this issue. ***

Changed in openoffice:
status: Unknown → Confirmed
Revision history for this message
In , Mikekaganski (mikekaganski) wrote :

The bug persists in OOo 3.0.1/WinXP.

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) [only if you calculate 2/6 _before_ you
calculate the exponent] != ((-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).

As it can be seen in Issue 24271 (that was erroneously treated as duplicate to
this one), the OOo team makes it's best to maintain compatibility with its main
competitor. This approach has very strong base and is honored sometimes even if
there's a mistake in th MS Office to let users migrate painlessly. But in this
case you refuse to make changes that not only consistent with MS Excel, but
also mathematically correct!

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

Revision history for this message
Björn Michaelsen (bjoern-michaelsen) wrote :

No new OOo releases in Ubuntu => Wont fix
Needs upstream bug reference in LibreOffice => Incomplete

Changed in libreoffice (Ubuntu):
status: New → Won't Fix
Changed in df-libreoffice:
status: New → Incomplete
Changed in openoffice.org (Ubuntu):
status: Triaged → Won't Fix
Revision history for this message
penalvch (penalvch) wrote :

Fournier Frédéric, the issue you are reporting is an upstream one and it would be nice if somebody having it could send the bug to the developers of the software by following the instructions at http://wiki.documentfoundation.org/BugReport . If you have done so, please tell us the number of the upstream bug (or the link), so we can add a bugwatch that will inform us about its status. Thanks in advance.

description: updated
tags: added: lo33 natty
removed: ooo-calc
Changed in libreoffice (Ubuntu):
importance: Undecided → Medium
status: Won't Fix → Triaged
Revision history for this message
In , Markus Mohrhard (moggi) wrote :

Setting this to enhancement. We need to write our own Power function for this. At the moment we are using the c++ standard library functionn which results in an error for negative base and a non integral exponent.

Code pointers:

http://opengrok.libreoffice.org/xref/core/sc/source/core/tool/interpr5.cxx#1687

Revision history for this message
Björn Michaelsen (bjoern-michaelsen) wrote :

wont fix as per upstream

Changed in df-libreoffice:
importance: Undecided → Unknown
status: Incomplete → Unknown
Changed in libreoffice (Ubuntu):
status: Triaged → Won't Fix
Changed in df-libreoffice:
importance: Unknown → Undecided
status: Unknown → New
Revision history for this message
In , Björn Michaelsen (bjoern-michaelsen) wrote :

1) lsb_release -rd
Description: Ubuntu 11.04
Release: 11.04

2) apt-cache policy libreoffice-calc
libreoffice-calc:
  Installed: 1:3.3.3-1ubuntu2
  Candidate: 1:3.3.3-1ubuntu2
  Version table:
 *** 1:3.3.3-1ubuntu2 0
        500 http://us.archive.ubuntu.com/ubuntu/ natty-updates/main i386 Packages
        100 /var/lib/dpkg/status
     1:3.3.2-1ubuntu4 0
        500 http://us.archive.ubuntu.com/ubuntu/ natty/main i386 Packages

3) What is expected to happen is when one types in a cell:

=(-8)^(1/3)

one gets -2 as the answer.

4) What happens instead is one receives #VALUE! as the answer.

WORKAROUND: Use Excel in WINE.

Microsoft Office Excel 2003 (11.5612.6505)

apt-cache policy wine1.3
wine1.3:
  Installed: 1.3.28-0ubuntu1~ppa1~natty1
  Candidate: 1.3.28-0ubuntu1~ppa1~natty1
  Version table:
 *** 1.3.28-0ubuntu1~ppa1~natty1 0
        500 http://ppa.launchpad.net/ubuntu-wine/ppa/ubuntu/ natty/main i386 Packages
        100 /var/lib/dpkg/status
     1.3.15-0ubuntu5 0
        500 http://us.archive.ubuntu.com/ubuntu/ natty/universe i386 Packages

Changed in df-libreoffice:
importance: Undecided → Unknown
status: New → Unknown
Changed in libreoffice (Ubuntu):
status: Won't Fix → Triaged
Changed in df-libreoffice:
importance: Unknown → Medium
status: Unknown → New
Revision history for this message
In , Markus Mohrhard (moggi) wrote :

Hm after an additional thought I'm not sure if it is really that simple to implement. At the point where we calculate the power we no longer have the information that we had a fraction as exponent.

I wonder how excel solves this problem. I suspect that we would have the same problem with ixion.

Changed in df-libreoffice:
importance: Medium → Wishlist
status: New → Confirmed
Revision history for this message
In , Rb-henschel (rb-henschel) wrote :

The problem has been discussed in OOo too; https://issues.apache.org/ooo/show_bug.cgi?id=37129

If you will keep rule a^(r*s) = (a^r)^s you cannot allow negative basis a.

Excel does not allow arbitrary fractions but tests only for unit fraction. That is not difficult. The highest such converted number is 1/(2^31-3) in Excel; 1/(2^31-1) fails.

So the question is, whether LO should implement Excels behavior for easier converting from Excel. ODF1.2 says "POWER(a,b), where a<=0 and INT(b)!=b, is implementation-defined." in chapter 6.16.46. So the standard allows such solution.

If you want to use arbitrary fractions, the class TOOLS_DLLPUBLIC Fraction from fract.hxx in tools might be useful.

penalvch (penalvch)
Changed in openoffice:
status: Confirmed → Unknown
penalvch (penalvch)
description: updated
Revision history for this message
In , penalvch (penalvch) wrote :

WORKAROUND: SIGN(X)*ABS(X)^(1/3)

summary: - =(-8)^(1/3)
+ [Upstream] =(-8)^(1/3)
Revision history for this message
In , Markus Mohrhard (moggi) wrote :

*** Bug 50596 has been marked as a duplicate of this bug. ***

Changed in openoffice:
importance: Unknown → Low
Revision history for this message
penalvch (penalvch) wrote :

Confirmed resolved in at least LO 6.1.3.2.

Changed in libreoffice (Ubuntu):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.