Bug 507500 - KRunner does not perform PEMDAS math calculations correctly
Summary: KRunner does not perform PEMDAS math calculations correctly
Status: RESOLVED UPSTREAM
Alias: None
Product: krunner
Classification: Plasma
Component: calculator (other bugs)
Version First Reported In: 6.4.3
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL: https://github.com/Qalculate/libqalcu...
Keywords:
Depends on:
Blocks:
 
Reported: 2025-07-26 03:49 UTC by Sad-Interest1972
Modified: 2025-09-23 18:00 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Screenshot showing the discrepancy between KCalc and KRunner's attempts at arithmetic. (109.39 KB, image/jpeg)
2025-07-26 03:49 UTC, Sad-Interest1972
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sad-Interest1972 2025-07-26 03:49:37 UTC
Created attachment 183524 [details]
Screenshot showing the discrepancy between KCalc and KRunner's attempts at arithmetic.

SUMMARY
KRunner does not understand the order of operations, whereas KCalc does.
In KCalc, "6/2(2+1)" correctly returns 9, whereas KRunner returns 1.
KRunner does not seem to be able to read from left-to-right and interprets the problem as "6 divided by (2*3)".
This is simply unacceptable, and wrong.

STEPS TO REPRODUCE
1. Launch KRunner
2.  Enter 6/2(2+1)

OBSERVED RESULT
Ans=1

EXPECTED RESULT
6/2(2+1) = 6/2*3 = 3*3 = 9
Ans=9

SOFTWARE/OS VERSIONS
Linux: Fedora 42 x86_64
KDE Plasma Version: 6.4.3
KDE Frameworks Version: 6.16.0 
Qt Version: 6.9.1
Comment 1 Sad-Interest1972 2025-07-26 05:04:30 UTC
Curiously, KRunner does correctly solve 6/2*(2+1), when there is an asterisk. KRunner seems to have trouble interpreting the implicit multiplication behind unsigned parentheses.
Comment 2 TraceyC 2025-07-30 16:52:00 UTC
Confirmed on git-master

Lowering priority since there's an easy workaround of using KCalc or another calculator app
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging#Set_the_Severity_field
Comment 3 Nate Graham 2025-09-23 18:00:51 UTC
This is issue in the Qalculate library that KRunner uses:

$ qalc "6/2(2+1)"
6 / (2 × (2 + 1)) = 1

Seems to be https://github.com/Qalculate/libqalculate/issues/350.