Bug 443276 - KCalc v19.12.3 - 500+200*2=1000
Summary: KCalc v19.12.3 - 500+200*2=1000
Status: RESOLVED FIXED
Alias: None
Product: kcalc
Classification: Applications
Component: general (show other bugs)
Version: 19.12
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Gabriel Barrantes
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-04 03:01 UTC by vmelkon
Modified: 2024-01-25 17:27 UTC (History)
3 users (show)

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


Attachments
A video showing the issue using middle-click paste (1.18 MB, video/mp4)
2021-12-07 17:14 UTC, Niklas Freund
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vmelkon 2021-10-04 03:01:50 UTC
SUMMARY
I have KCalc v19.12.3 on Kubuntu 20.04
If I do
500 (pasted) + 200 (pasted) * 2
I get 1000.

If I do
500(pasted) + 2 * 200 (pasted)
I get 900.

STEPS TO REPRODUCE
1. Into KCalc, I paste 500
2. then, I click +
3. I paste 200
4. then, I click *
5. then, I click 2
6. then, I click =
7. KCalc shows 1000

OBSERVED RESULT
If I do
500 (pasted) + 200 (pasted) * 2
I get 1000.


EXPECTED RESULT
900

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: Kubuntu 20.04
(available in About System)
KDE Plasma Version: 5.18.5
KDE Frameworks Version: 5.68.0
Qt Version: 5.12.8

ADDITIONAL INFORMATION
Comment 1 nl.smart 2021-10-04 18:41:57 UTC
Hi,

On my side Kclac 21.08.1, no issue with Kclac, I reproduced your steps.

Operating System: Manjaro 21.1.4 Pahvo
KDE Plasma Version: 5.22.5
KDE Frameworks Version: 5.86.0
Qt Version: 5.15.2
Kernel Version: x86_64 Linux 5.13.19-2-MANJARO
OS Type: 64-bit
Processors: Intel Celeron J4105
Memory: 7.6 GiB of RAM
Graphics Processor: Mesa Intel(R) UHD Graphics 600 (GLK 2)
Comment 2 vmelkon 2021-10-04 21:16:57 UTC
MORE INFO:
OK I tested
With KCalc 17.12.3 on Kubuntu 18.04, it works fine.
With KCalc 20.12.3 on Kubuntu 21.04, it works fine.
Comment 3 Niklas Freund 2021-12-07 17:14:00 UTC
Created attachment 144314 [details]
A video showing the issue using middle-click paste

I can reproduce the issue when using middle click to paste.
Curiously, everything works fine if I use Ctrl+C and Ctrl+V.

KCalc Version: 21.08.3
Operating System: Manjaro Linux
KDE Plasma Version: 5.23.3
KDE Frameworks Version: 5.88.0
Qt Version: 5.15.2
Kernel Version: 5.15.2-2-MANJARO (64-bit)
Graphics Platform: X11
Processors: 12 × AMD Ryzen 5 2600 Six-Core Processor
Memory: 15.6 GiB of RAM
Graphics Processor: NVIDIA GeForce GTX 1060 6GB/PCIe/SSE2
Comment 4 nl.smart 2021-12-17 08:58:22 UTC
Hi,

thanks for your feedback and your movie.
I can't reproduce your copy past, Kcalc display an error
nan

the OS is up to date, no issue with kcalc 21.12.0

[nls@lap ~]$ pamac search --installed kcalc
kcalc                                        21.12.0-1  extra 
    Scientific Calculator
Comment 5 vmelkon 2022-09-07 01:12:46 UTC
I am running Kubuntu 22.04 and KCalc 21.12.3
I was able to reproduce what Niklas Freund is describing.


KCalc Version: 21.12.3
Operating System: Kubuntu 22.04
KDE Plasma Version: 5.24.6
KDE Frameworks Version: 5.92.0
Qt Version: 5.15.3
Kernel Version: 5.15.0-47-generic (64-bit)
Graphics Platform: X11
Processors: 12 × AMD Ryzen 5 3600 Six-Core Processor
Memory: 24 GB of RAM
Graphics Processor: NVIDIA GeForce GTX 980 6GB/PCIe/SSE2 4 GB
Comment 6 Bug Janitor Service 2023-11-03 02:25:28 UTC
A possibly relevant merge request was started @ https://invent.kde.org/utilities/kcalc/-/merge_requests/67
Comment 7 Carl Schwan 2024-01-25 17:27:56 UTC
Git commit c7864e9547b2ef2e9e318a88c78ba51f10fbc5e3 by Carl Schwan, on behalf of Gabriel Barrantes.
Committed on 25/01/2024 at 18:27.
Pushed by carlschwan into branch 'master'.

Add display for user's input

Add display to keep the user's entries visible during the whole calculation process, this allows editing the expression at any point to make any correction the user considers opportune. This display allows coping/pasting an expression to be calculated, that can also be edited as required.

All currently implemented functions are supported and also was added support for 0x, 0b and 0 as prefixes for hex, binary and octal numbers.

Before:![image.png](/uploads/bfd53d4ddb462c995181547c24f3ecbc/image.png){width="225" height="211"}

After:

![image.png](/uploads/0b1e83cff41409c5d925e8014cf6f988/image.png){width="258" height="258"}![image.png](/uploads/e6cb88f4492ca0b98f9ebb08e669bc9f/image.png){width=262 height=262}

New classes added:

* KCalcToken: contains a given valid token such as an operation (+, -, ...), a function (cos, ln, ...), a parenthesis or a number.
* KCalcParser: provides an API to convert a given string (for example "1+cos(4.5)") to a Queue of KCalcToken objects.
* KCalcInputDisplay: this is a customized QLineEdit widget, it holds the user's input.
* KCalcDisplayFrame: holds the input display, result display and some labels.
* CalcEngine_p: encapsulates the functionality that used to be available in CalcEngine class, to be only visible for KCalcToken objects.

Modified classes:

* CalcEngine: added the main algorithm to process the calculation, based on common Operator-precedence parsers.

@teams/qa @teams/vdg @teams/usability
Related: bug 461010, bug 470371, bug 470591, bug 142728, bug 459999, bug 447347, bug 454835

M  +17   -1    CMakeLists.txt
A  +20   -0    autotests/CMakeLists.txt
A  +239  -0    autotests/kcalc_parser_core_test.cpp     [License: GPL(v2.0+)]
M  +352  -363  kcalc.cpp
M  +39   -19   kcalc.h
M  +600  -300  kcalc.ui
M  +1    -19   kcalc_const_menu.cpp
M  +2    -1    kcalc_const_menu.h
M  +411  -828  kcalc_core.cpp
M  +24   -107  kcalc_core.h
A  +713  -0    kcalc_core_p.cpp     [License: GPL(v2.0+)]
A  +92   -0    kcalc_core_p.h     [License: GPL(v2.0+)]
A  +57   -0    kcalc_display_frame.cpp     [License: GPL(v2.0+)]
A  +24   -0    kcalc_display_frame.h     [License: GPL(v2.0+)]
A  +101  -0    kcalc_input_display.cpp     [License: GPL(v2.0+)]
A  +36   -0    kcalc_input_display.h     [License: GPL(v2.0+)]
A  +776  -0    kcalc_parser.cpp     [License: GPL(v2.0+)]
A  +155  -0    kcalc_parser.h     [License: GPL(v2.0+)]
A  +64   -0    kcalc_priority_levels_p.h     [License: GPL(v2.0+)]
A  +412  -0    kcalc_token.cpp     [License: GPL(v2.0+)]
A  +175  -0    kcalc_token.h     [License: GPL(v2.0+)]
M  +3    -72   kcalcdisplay.cpp
M  +0    -1    kcalcdisplay.h
M  +1    -42   kcalchistory.cpp
M  +0    -3    kcalchistory.h
M  +9    -1    knumber/knumber.cpp
M  +2    -0    knumber/knumber.h
M  +4    -4    scienceconstants.xml

https://invent.kde.org/utilities/kcalc/-/commit/c7864e9547b2ef2e9e318a88c78ba51f10fbc5e3