Bug 450558 - Inconsistent handling of Numerical Base conversion functions and syntax.
Summary: Inconsistent handling of Numerical Base conversion functions and syntax.
Status: RESOLVED FIXED
Alias: None
Product: krunner
Classification: Plasma
Component: calculator (show other bugs)
Version: 5.24.1
Platform: Gentoo Packages Linux
: NOR minor
Target Milestone: ---
Assignee: Alexander Lohnau
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-02-19 10:48 UTC by aTosser
Modified: 2022-10-19 14:28 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description aTosser 2022-02-19 10:48:50 UTC
There is now hardcoded hex= command handling for converting to hexadecimal, however this is not consistance with other base unit convertion syntax. Currently in krunner if you use the syntax oct=, bin=, or dec=. You get get a reference to qalculate functions oct(), bin(), dec(), which all return a decimal number for the given input. (and do not function using name= syntax.)

Desired results:
handling of oct=, bin=, dec= to be in line with the hex= syntax.
Comment 1 Bug Janitor Service 2022-10-15 08:52:06 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2222
Comment 2 Fushan Wen 2022-10-19 14:28:31 UTC
Git commit 8ea36e077a80a39aa3fec2260f217548f054953d by Fushan Wen, on behalf of Max Ramanouski.
Committed on 19/10/2022 at 14:27.
Pushed by fusionfuture into branch 'master'.

runners/calculator: Improve output base handling

Reimplement krunner base conversion through libqalculate
PrintOptions.base instead of parsing decimal output and converting it to hex.
This approach allows for correct display of multiple solutions
converted to different base, for example:
`hex= x * x = 4` will output `x = 0x2 || x = -0x2`.
Also, this makes it possible to easily implement more bases like
bin, oct, time, roman, etc.

To detect required base findPrefix function was implemented in QalculateEngine,
this function checks are there any common bases like hex, oct, bin,
roman, time, pi and if there is it sets PrintOptions.base to corresponding base,
this common base mappings were taken from libqalculate/src/qalc.cc
set_option function (lines from 747 to 776, libqalcualate commit d767c71).
To handle non-common bases prefix base was implemented, examples:
`base 42=64` results to `1M`,  `base 2**16=123456789` results to `\1883\52501`.
When findPrefix function encounters base keyword in prefix,
it sets base to BASE_CUSTOM, then at QalculateEngine::evaluate
if base is set to BASE_CUSTOM everything in prefix after base keyword
is calculated and set as custom base for main calculation via
CALCULATOR->setCustomOutputBase.

M  +15   -11   runners/calculator/calculatorrunner.cpp
M  +1    -1    runners/calculator/calculatorrunner.h
M  +77   -1    runners/calculator/qalculate_engine.cpp
M  +3    -1    runners/calculator/qalculate_engine.h

https://invent.kde.org/plasma/plasma-workspace/commit/8ea36e077a80a39aa3fec2260f217548f054953d