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
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.
> 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.
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.
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2812
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