Bug 410988 - Bad math when multiplying
Summary: Bad math when multiplying
Status: RESOLVED FIXED
Alias: None
Product: kdeplasma-addons
Classification: Plasma
Component: calculator (show other bugs)
Version: 5.16.4
Platform: Neon Linux
: VHI normal
Target Milestone: ---
Assignee: Nisarg
URL:
Keywords: junior-jobs
Depends on:
Blocks:
 
Reported: 2019-08-16 14:28 UTC by S. Christian Collins
Modified: 2020-01-15 00:36 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description S. Christian Collins 2019-08-16 14:28:42 UTC
STEPS TO REPRODUCE
1. In the calculator widget, multiply 62 x 1.3.

OBSERVED RESULT
The calculator widget gives the answer "8.06e1".

EXPECTED RESULT
The answer should be "80.6".

SOFTWARE/OS VERSIONS
OS: KDE neon 5.16 User Edition
KDE Plasma Version: 5.16.4
KDE Frameworks Version: 5.61.0
Qt Version: 5.12.3
Comment 1 Nate Graham 2019-08-16 14:50:36 UTC
Wow.
Comment 2 2wxsy58236r3 2019-08-17 03:35:05 UTC
"8.06e1" is theoretically correct (8.06 x 10^1 = 80.6), but it is not necessary to use scientific notation in this case because the widget has enough space to display the number.
Comment 3 Christoph Feck 2019-09-09 14:23:16 UTC
Since it is using binary instead of decimal arithmetic, the result is probably 80.6000000000000001 or something similar. For "long" results, it decides to use scientific notation.

It should always round to 15 significant decimal digits before any further processing, because IEEE double precision is limited.

I haven't checked if number.toString() offers options for precision.

https://cgit.kde.org/kdeplasma-addons.git/tree/applets/calculator/package/contents/ui/calculator.qml#n244
Comment 4 Nisarg 2019-10-03 17:31:12 UTC
Is this issue still on to work on this?
Comment 5 Nate Graham 2019-10-03 18:25:18 UTC
Yes, please feel free to work on this if you'd like!
Comment 6 Nisarg 2019-10-04 04:13:33 UTC
(In reply to Nate Graham from comment #5)
> Yes, please feel free to work on this if you'd like!

Yes I would like to work on this issue. Please assign this issue to me. Thanks!!
Comment 7 Nisarg 2019-10-07 04:34:44 UTC
(In reply to Nate Graham from comment #5)
> Yes, please feel free to work on this if you'd like!

What is the mailing list or IRC Channel for this project where I can discuss my doubts and ask questions?
Comment 8 Nate Graham 2019-10-07 04:42:53 UTC
plasma-devel@kde.org
Comment 9 Nisarg 2019-10-08 13:11:36 UTC
Can I get the link of few resources to learn Qt. Actually I am new to KDE so I have just set up the development environment and I tried to learn Qt, but I can't find some good resources?
Comment 10 Nate Graham 2019-10-08 14:51:13 UTC
(In reply to Nisarg from comment #9)
> Can I get the link of few resources to learn Qt. Actually I am new to KDE so
> I have just set up the development environment and I tried to learn Qt, but
> I can't find some good resources?
https://community.kde.org/Get_Involved/development#New_to_C.2B.2B.2FQt_software_development.3F
Comment 11 David Edmundson 2020-01-14 22:38:54 UTC
>I haven't checked if number.toString() offers options for precision.

No, it doesn't.
Comment 12 David Edmundson 2020-01-15 00:36:18 UTC
Git commit a51086867c0f0f7e19b0dd2b9d59657542c46901 by David Edmundson.
Committed on 15/01/2020 at 00:36.
Pushed by davidedmundson into branch 'master'.

[applets/calculator] Use Qt's in-built number formatting

Summary:
Gets rid of a load of code.
Correctly handles floating point issues.
Results are correct.

Potentially this inadvertedly introduces a behaviour change
of including group separators depending on locale. This could be
considered a good thing, but if it's problematic we can always add a
.replace() at the end of this line.

Test Plan:
62 * 1.3 = 80.6

100000000 * 5000000 = 5e+17
(with whatever the right number of zeroes is)

42 * 1.33333 = 6.6666665

Reviewers: #plasma

Subscribers: plasma-devel

Tags: #plasma

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

M  +2    -18   applets/calculator/package/contents/ui/calculator.qml

https://commits.kde.org/kdeplasma-addons/a51086867c0f0f7e19b0dd2b9d59657542c46901