https://bugs.documentfoundation.org/show_bug.cgi?id=121398

            Bug ID: 121398
           Summary: Powers of negative numbers highly inconsistent
           Product: LibreOffice
           Version: 6.0.5.2 release
          Hardware: x86-64 (AMD64)
                OS: Linux (All)
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: Calc
          Assignee: [email protected]
          Reporter: [email protected]

Description:
(-1)^(1/3)   --> -1
(-1)^(2/3)   --> Error
(-1)^(1/5)   --> -1
(-1)^(3/5)   --> Error
(-1)^(6004799503160661/2^54) --> -1

>From a purely mathematical (ie., using the mathematical concept of Reals) the
correct results are -1, +1, -1, -1, and Error.

>From a floating-point view (i.e, using ieee-854 base-2 floating-point numbers,
round-to-nearest and operations in the order dictated by parentheses) the
correct results are Error, Error, Error, Error, and Error.

In other words, the results are inconsistent with both mathematical and
floating-point views.  Looking at the code, this comes from a na\"ive attempt
at identifying certain floating-point numbers as odd-denominator fractions.

Suggestion: implement Gnumeric's 3-argument POWER, e.g. POWER(-1,1,3).  That
avoids trying to interpret floating-point numbers as fractions, a highly
error-prone business.

Steps to Reproduce:
Enter this into A1:A5

=(-1)^(1/3)
=(-1)^(2/3)
=(-1)^(1/5)
=(-1)^(3/5)
=(-1)^(6004799503160661/2^54)


Actual Results:
Actual: -1, #NUM!, -1, #NUM!, and -1.


Expected Results:
Expected: 5 x #NUM!
or
Expected: -1, 1, -1, -1, #NUM!



Reproducible: Always


User Profile Reset: No



Additional Info:
The constants in (-1)^(6004799503160661/2^54) are carefully chosen such that
there is no floating-point rounding errors at any point in the calculation. 
The exponent is what you get from 1/3 after rounding to nearest double.

The code is at https://docs.libreoffice.org/sc/html/interpr5_8cxx_source.html
near line 1588.  As an aside, the static_cast<int> is undefined behaviour for
cases like (-1)^(2^-64).

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to