Bug 496343 - Formulas with string expressions are not commutative: "sqrt(2) + 2" works, but "2 + sqrt(2)" fails
Summary: Formulas with string expressions are not commutative: "sqrt(2) + 2" works, bu...
Status: RESOLVED FIXED
Alias: None
Product: krunner
Classification: Plasma
Component: calculator (other bugs)
Version First Reported In: 6.2.3
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-11-16 13:48 UTC by postix
Modified: 2026-04-18 11:55 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In: 6.7.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description postix 2024-11-16 13:48:31 UTC
STEPS TO REPRODUCE
1. Open krunner, type: 1 + sqrt(2) or 1 + sin(2)
2.  Try the same with sqrt(2) + 1 or sin(2) + 1

OBSERVED RESULT
1. It asks to search with $websearchengine 
2. It calculates correctly

Works fine with qalculate-qt, which uses the same lib.

SOFTWARE/OS VERSIONS
Operating System: openSUSE Tumbleweed 20241114
KDE Plasma Version: 6.2.3
KDE Frameworks Version: 6.8.0
Qt Version: 6.8.0
Comment 1 Nate Graham 2024-11-19 19:11:48 UTC
This is an issue in Libqalculate, which is the library we use for mathematical calculations under the hood. Can you report this at https://github.com/Qalculate/libqalculate/issues? Thanks!
Comment 2 postix 2024-11-19 20:37:56 UTC
(In reply to Nate Graham from comment #1)
> This is an issue in Libqalculate, which is the library we use for
> mathematical calculations under the hood. Can you report this at
> https://github.com/Qalculate/libqalculate/issues? Thanks!

As I wrote
> Works fine with qalculate-qt, which uses the same lib.

two things come in my mind: this is either a regression in Libqalculate, no one has reported yet OR this is a parsing error in krunner and I assume it's the latter.
Comment 3 Nate Graham 2024-11-20 20:39:43 UTC
Eek, sorry for missing that part.
Comment 4 Bug Janitor Service 2026-04-15 17:19:54 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/6499
Comment 5 Nate Graham 2026-04-17 14:40:07 UTC
Git commit e7ec6ff1651dc3850c168d13da0166a317d365f5 by Nate Graham, on behalf of Alex Cizinsky.
Committed on 17/04/2026 at 14:08.
Pushed by ngraham into branch 'master'.

runners/calculator: Don’t require math functions to be at the beginning or contain only letters

When the runner query does not start or end with `=`, a regex is used to
try to match math function signatures. Currently this regex requires the
function to be at the beginning of the query and only contain letters.
This causes queries like `1+sqrt(4)`, `log10(1000)` or `atan2(1,2)` to
not display any results.

This change updates the regex to match functions anywhere in the query.
Additionally it also allows matching functions that contain digits
(e.g. log10()).

Note that digits in the function name are allowed only at the end, this
causes functions that have a digit in the middle of their name (according
to the qalculate function list there are only two such functions:
`matrix2vector` and `unix2date`) to still fail to match, however they
still may be used by prefixing the query with `=`. Also trying to match
functions with digits in the middle of their name would just introduce
more complexity.

M  +8    -0    runners/calculator/autotests/calculatorrunnertest.cpp
M  +1    -1    runners/calculator/calculatorrunner.cpp

https://invent.kde.org/plasma/plasma-workspace/-/commit/e7ec6ff1651dc3850c168d13da0166a317d365f5
Comment 6 postix 2026-04-18 11:55:16 UTC
Thank you so much! <3