Bug 407318 - Finish MPFR support
Summary: Finish MPFR support
Status: RESOLVED FIXED
Alias: None
Product: kcalc
Classification: Applications
Component: general (other bugs)
Version First Reported In: 19.04
Platform: Other Linux
: NOR task
Target Milestone: ---
Assignee: Evan Teran
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-05-08 01:03 UTC by Aaron Williams
Modified: 2019-06-23 10:22 UTC (History)
2 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Aaron Williams 2019-05-08 01:03:47 UTC
SUMMARY
When I do ACOS(-1) in radians I should get PI, but the value is wrong when set to 33 digits.

KCalc: 3.14159265358979311599796346854419
BC:    3.14159265358979323846264338327950

STEPS TO REPRODUCE
1. Put in scientific mode and configure the number of digits to 33
2. Calculate ACOS of -1

OBSERVED RESULT
3.14159265358979311599796346854419


EXPECTED RESULT
3.14159265358979323846264338327950

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: OpenSUSE 15.0
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION
Note that I'm wearing my Pi Rat shirt which is also correct. My memory of Pi is also more accurate. (I was bored in high school where they had Pi to 40 digits so I memorized it).
Comment 1 Christoph Feck 2019-05-21 19:02:01 UTC
Is your KCalc compiled using MPFR dependency? You can find out by using 'ldd' command in Konsole:

    ldd /usr/bin/kcalc | grep mp

This should show both 'libgmp' as well as 'libmpfr'.
Comment 2 Christoph Feck 2019-05-21 19:07:24 UTC
Never mind; MPFR support was disabled with https://commits.kde.org/kcalc/9e1dd53d4cda09d2d395dbd5caa9f403d36c9b03
Comment 3 Aaron Williams 2019-05-21 19:20:17 UTC
ldd /usr/bin/kcalc | grep mp
        libgmp.so.10 => /usr/lib64/libgmp.so.10 (0x00007fb0a9875000)
        libKF5Completion.so.5 => /usr/lib64/libKF5Completion.so.5 (0x00007fb0a09dc000)

This is the version supplied by OpenSUSE in their latest up-to-date repository (not the standard repository).

According to a friend of mine who developed his own calculator, he says that libgmp has a lot of accuracy bugs so he is using a different library.  I can find out which one he uses.  His calculator did give the correct answer.
Comment 4 Aaron Williams 2019-05-22 02:16:21 UTC
My coworker suggests using libarb instead of libgmp since libgmp cannot guarantee precision. See http://arblib.org

He ran into the same issue when he developed his calculator app using libgmp as I ran into with KCalc and he switched to libarb to solve that problem.
Comment 5 Evan Teran 2019-05-22 02:19:42 UTC
I wrote the knumber library that wraps gmp in kcalc. It is definitely in need of some modernization and perhaps arblib is worth looking into as a replacement for it's big number capabilities.

I'll look into it!
Comment 6 Marcelo Mariano 2019-06-04 14:22:38 UTC
Add review request https://phabricator.kde.org/D21495.
Comment 7 Christoph Feck 2019-06-23 10:22:49 UTC
Git commit 2a05545830fdc9a2fe6a1d249d9eff52c53b7d1f by Christoph Feck, on behalf of Marcelo Mariano.
Committed on 23/06/2019 at 10:21.
Pushed by cfeck into branch 'master'.

Use MPFR in knumber_float in order to improve floating-point precision
Related: bug 132158, bug 148357
FIXED-IN: 19.08.0

Differential Revision: https://phabricator.kde.org/D21495

M  +8    -0    CMakeLists.txt
M  +2    -2    knumber/knumber.cpp
M  +0    -3    knumber/knumber_base.h
M  +80   -415  knumber/knumber_float.cpp
M  +14   -8    knumber/knumber_float.h
M  +8    -1    knumber/knumber_integer.cpp
M  +3    -2    knumber/tests/CMakeLists.txt

https://commits.kde.org/kcalc/2a05545830fdc9a2fe6a1d249d9eff52c53b7d1f