Bug 166720 - The negative sign written at the beginning of the formula in a cell is not calculated correctly.
Summary: The negative sign written at the beginning of the formula in a cell is not ca...
Status: RESOLVED DUPLICATE of bug 114929
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
25.2.3.2 release
Hardware: x86-64 (AMD64) macOS (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-05-25 10:25 UTC by mathscienceentertainment
Modified: 2025-05-26 01:50 UTC (History)
0 users

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 mathscienceentertainment 2025-05-25 10:25:47 UTC
Description:
If I wrote a negative sign at the beginning of the formula in a cell, the result is unnatural.

Steps to Reproduce:
1. The value in the cell A1 to be 1.
2. The value in the cell A2 to be 2.
3. The formula in the cell A3 to be "=-A1^2+A2^2"

Actual Results:
5

Expected Results:
3


Reproducible: Always


User Profile Reset: No

Additional Info:
Version Information:
Version: 25.2.3.2 (AARCH64) / LibreOffice Community
Build ID: bbb074479178df812d175f709636b368952c2ce3
CPU threads: 8; OS: macOS 15.5; UI render: Skia/Raster; VCL: osx
Locale: ja-JP (ja_JP.UTF-8); UI: ja-JP
Calc: threaded

Additional Information:
- If the formula in cell A3 was refined as "=A2^2-A1^2", the result changed to 3 correctly.
- Same behavior was occured also in Ver. 24.8.4.2 (X86_64).
Comment 1 Mike Kaganski 2025-05-25 10:58:16 UTC
The minus may be either a binary operator (as in your second expression), or unary (as in first). They are different, and have different precedence. An unary minus is applied to the number, not to the result of raising to a power, so your first expression is equivalent to "(-A1)^2+A2^2". That is defined in the standard, so not a bug. However, that is not obvious; there is a request to make such expressions to auto-parenthesise, to remove ambiguity.

*** This bug has been marked as a duplicate of bug 114929 ***
Comment 2 mathscienceentertainment 2025-05-26 01:50:40 UTC
(In reply to Mike Kaganski from comment #1)
> The minus may be either a binary operator (as in your second expression), or
> unary (as in first). They are different, and have different precedence. An
> unary minus is applied to the number, not to the result of raising to a
> power, so your first expression is equivalent to "(-A1)^2+A2^2". That is
> defined in the standard, so not a bug. However, that is not obvious; there
> is a request to make such expressions to auto-parenthesise, to remove
> ambiguity.
> 
> *** This bug has been marked as a duplicate of bug 114929 ***

Thank you, Mr. Mike!
I've gut it.