Bug 467418

Summary: Don't require equals sign before common math operations like sqrt() and log()
Product: [Plasma] krunner Reporter: David <david.cortes.rivera>
Component: generalAssignee: Alexander Lohnau <alexander.lohnau>
Status: RESOLVED FIXED    
Severity: wishlist CC: alexander.lohnau, natalie_clarius, nate
Priority: NOR Keywords: usability
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In: 6.0
Sentry Crash Report:

Description David 2023-03-15 20:05:12 UTC
SUMMARY
I want to do simple math with krunner. It doesn't understand something as basic as 'sqrt(2)' or 'log(3)'.

STEPS TO REPRODUCE
1. Press Alt+Space.
2. Type sqrt(2)

OBSERVED RESULT
Offers me to search the web for the square root of 2. In contrast, it understands 2^0.5. The calculator plugin is enabled.

EXPECTED RESULT
1.414214

SOFTWARE/OS VERSIONS
Operating System: Debian GNU/Linux 12
KDE Plasma Version: 5.27.2
KDE Frameworks Version: 5.103.0
Qt Version: 5.15.8
Kernel Version: 6.1.0-6-amd64 (64-bit)
Graphics Platform: X11
Processors: 20 × 12th Gen Intel® Core™ i7-12700H
Memory: 62.5 GiB of RAM
Graphics Processor: Mesa Intel® Graphics
Manufacturer: SLIMBOOK
Product Name: Executive
ADDITIONAL INFORMATION
Comment 1 Natalie Clarius 2023-03-15 23:18:20 UTC
It does understand it if you put a "=" in front. Though I agree it's a little strange that it needs that for some operations but not others.
Comment 2 Nate Graham 2023-04-04 21:44:41 UTC
> In contrast, it understands 2^0.5
So then, it *does* know how to do basic math functions like square root, no? ;)

We can certainly improve the syntax though, as Natalie alludes to.
Comment 3 Alexander Lohnau 2023-04-09 19:01:01 UTC
I did some digging libqualculate has API to check if a string (lets say "sqrt") is a known function name.

If we do some parsing beforehand, we could check if the parsed function name is known to qalculate. If yes, we do not require the "=" in front.
Comment 4 Bug Janitor Service 2023-04-09 19:35:57 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2812
Comment 5 Alexander Lohnau 2023-04-28 17:10:41 UTC
Git commit 4cddacf865585995e8b9421becf2a92cd515b9b3 by Alexander Lohnau.
Committed on 28/04/2023 at 16:58.
Pushed by alex into branch 'master'.

runners/calculator: Do not require "=" prefix for known functions

This utilized the qalculate API to get a function by its name.
In case the function is not known, we get a nullptr and return false in
our helper function.

To avoid unintended results, the syntax of "functionname(<argument>)" is
enforced using a regex.

M  +19   -0    runners/calculator/autotests/calculatorrunnertest.cpp
M  +14   -0    runners/calculator/calculatorrunner.cpp
M  +5    -0    runners/calculator/qalculate_engine.cpp
M  +3    -0    runners/calculator/qalculate_engine.h

https://invent.kde.org/plasma/plasma-workspace/commit/4cddacf865585995e8b9421becf2a92cd515b9b3