Error in formula exp() function

I noticed that there is an error in the EXP formula calculation in Libreoffice Calc.

If I calculate EXP(-2^2) Calc reports 54.598 but if I calculate EXP(0-2^2) it gives the correct answer of 0.018 But they should both be 0.018. Calc does not follow BEDMAS in this instance.

Has this been noticed as a bug? Or is this by design?

Vesion info:
Version: 7.3.2.2 (x64) / LibreOffice Community
Build ID: 49f2b1bff42cfccbd8f788c8dc32c1c309559be0
CPU threads: 8; OS: Windows 10.0 Build 19044; UI render: Skia/Raster; VCL: win
Locale: en-CA (en_CA); UI: en-US
Calc: CL

-2^2  != -(2^2)
1 Like

Note that - in your formula is not subtraction, and even not an operation of negation, but a part of a number name - namely, the name of a negative number -2.

See also tdf#114929.

mmh… “my” school math tells me: the unary operator should evaluated first, but for example python does the other way:

-2**2 == (-2)**2   #→ False

From Welcome to the LibreOffice Writer Help

Interesting that I never knew that and I’ve used spreadsheets for many years for many complicated things and math programs disagree and so do programming languages:
image
and python is the same (disagrees with spreadsheets too)


and Wolfram Alpha is the same:

1 Like

The bad and ambiguous treatment of the “minus” in mathematical context has a long tradition, mainly being perpetuated by bad teaching. Basically the character is used in three roles:

  1. digit-like as the leading element when transmitting a value in a representation for the human ear or eye, but also (recoded somehow) in IT-files nowadays (case “number name” as @mikekaganski used the term),

  2. as unary operator meaning “change sign” (often CHS on pocket calculators),

  3. as the binary operator for “calculate the difference”.

As any “overloaded notation” the minus needs context-sensitive interpretation, and people tend to have a preferred approach. In the given case the first role seems to be rarely teached in a clear way, and the second and third role are treated as “basically the same” using the think-around with “0 -”. Trying to consistently apply this approach to the first role would, however, require to abandon any means to communicate negative numbers as genuine entities. The actually transmitted number would always be >=0, and the minus an operator needing to be applied subsequently. I would call this an obviously inconsistent approach falling back to the times when negative numbers were disesteemed even in math.

Calc didn’t go this way, but regards the first role as a relevant one. However the way it tries to implement this is inconsistent again because it requires in many cases to use parentheses to force the interpretation of another “-” as the “unary” operator (second role). Even the “equivalence” of the uinary minus with the “0 -” doesn’t survive as @sikkema demonstrated.

A syntactically sufficiently clean way to resolve the siuation would be to apply the first role only if the “-” is not separated in any way from the leading character of the unsigned numeric literal following it. This can’t be implemented, however, after a long time of having it done differently. And very few users will be interested in the related questions. In addition: I don’t know and nobody mentioned how Excel handles the cases. I would suppose they do it the same way. And incompatibility with Excel on that level would be inacceptable for most users.
Thus: Bear with the inconsistencies.