Bug 460232 - Kalk Does Bad Math
Summary: Kalk Does Bad Math
Status: RESOLVED FIXED
Alias: None
Product: Kalk
Classification: Applications
Component: General (show other bugs)
Version: unspecified
Platform: Flatpak Linux
: NOR normal
Target Milestone: ---
Assignee: hanyoung
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-11 08:57 UTC by BT
Modified: 2022-10-14 06:13 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Kalk History of Recent Bad Math (20.48 KB, image/png)
2022-10-11 08:57 UTC, BT
Details

Note You need to log in before you can comment on or make changes to this bug.
Description BT 2022-10-11 08:57:02 UTC
Created attachment 152697 [details]
Kalk History of Recent Bad Math

SUMMARY
When I use Kalk, I get bad math results sometimes.  See attached screenshot.

STEPS TO REPRODUCE
1. Install Kalk Flatpak.
2. Do math.
3. Get weird results.

OBSERVED RESULT
Not exact result.  Lots of unnecessary decimal places due to result reported.

EXPECTED RESULT
Exact result when doing math.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma:  Fedora 36 KDE Spin
KDE Plasma Version:  5.25.5
KDE Frameworks Version:  5.98.0
Qt Version:  5.15.6

ADDITIONAL INFORMATION
Kalk is the Flathub version.  ABOUT says Calculator 22.09.  It would be nice to have a KDE calculator identical to the Windows 10/11 Calculator App which is one program I do miss from Windows.
Comment 1 hanyoung 2022-10-12 13:59:20 UTC
Git commit 6d7498b88ab84811607ad30138cffacea38cbf2b by Han Young.
Committed on 12/10/2022 at 13:59.
Pushed by hanyoung into branch 'master'.

use mpfr_init2 to ensure the precision isn't lost on string to float conversion

M  +13   -13   knumber/knumber_float.cpp

https://invent.kde.org/plasma-mobile/kalk/commit/6d7498b88ab84811607ad30138cffacea38cbf2b
Comment 2 hanyoung 2022-10-12 14:05:01 UTC
Turns out string to knumber's float variant conversion uses GNU MPFR's old init function, thus lost the precision from user input to internal representation. I changed the init function to "mpfr_init2" with 1024 bit precision. Should be fixed now. 

A similar change will be applied to KCalc, since that's where Kalk's knumber from. :)
Comment 3 BT 2022-10-14 06:13:14 UTC
Thanks!  I'll wait for the update to come from Flathub.