Bug 348802 - Calculator doesn't correctly calculate division by zero
Summary: Calculator doesn't correctly calculate division by zero
Status: RESOLVED FIXED
Alias: None
Product: kdeplasma-addons
Classification: Plasma
Component: calculator (show other bugs)
Version: 5.3.90
Platform: Other Linux
: NOR minor
Target Milestone: ---
Assignee: Plasma Bugs List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-06 23:15 UTC by Martin Flöser
Modified: 2023-02-23 15:03 UTC (History)
7 users (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Flöser 2015-06-06 23:15:02 UTC
The calculator applet does not implement division by zero correctly.  The result of division by zero is undefined. Quoting wikipedia (https://en.wikipedia.org/wiki/Division_by_zero ): "In ordinary arithmetic, the expression has no meaning, as there is no number which, multiplied by 0, gives a (assuming a≠0), and so division by zero is undefined"

Reproducible: Always

Steps to Reproduce:
1. Add calculator applet
2. Calculate 1/0
3. Calculate 0/0

Actual Results:  
for 1/0 it results in "Infinity", for 0/0 in "NaN"

Expected Results:  
showing either undefined or what was entered (that's what krunner does)
Comment 1 Kai Uwe Broulik 2015-06-06 23:19:17 UTC
KRunner also shows "Infinity" for 1/0 and "NaN" for 0/0
Comment 2 Martin Flöser 2015-06-07 00:04:16 UTC
(In reply to Kai Uwe Broulik from comment #1)
> KRunner also shows "Infinity" for 1/0 and "NaN" for 0/0

not here: it shows "1/0" and "0/0"
Comment 3 David Edmundson 2015-06-07 07:41:54 UTC
>The result of division by zero is undefined

Then it doesn't matter what the result is. That's the definition of undefined. 
 Infinity or NaN aren't exactly wrong. Personally I'd close this as wontfix. 
Will let calculator maintainer decide.
Comment 4 Martin Flöser 2015-06-07 15:37:31 UTC
NaN could be interpreted as undefined, infinity not. Infinity is not an undefined value, but a pretty clear value. Also NaN as an output is wrong - which non technical user would know that it stands for "Not a Number"?
Comment 5 Ivan Čukić 2015-06-07 17:03:17 UTC
I agree with Martin.

Division by zero is always undefined, it is not infinity nor NaN. It has been defined for IEEE754 to have special values of Infinity and 'I'm Not a Number, I'm a free man' :) because of non-precise floating-point arithmetic.

The most I'd go for is an answer along the lines of
'Not defined (Infinity according to IEEE754 standard)'
but IMO this would be an overkill.

> > The result of division by zero is undefined
> Then it doesn't matter what the result is.
> That's the definition of undefined.

The definition of undefined is that a function is not defined for the provided arguments. Not that it does not matter what the result is.

> Infinity or NaN aren't exactly wrong. 

The *are* exactly wrong. In the same way as using 42 as an answer would be wrong.

p.s. Similar thing also happens for sqrt(-4) - it returns NaN, but it should be 'undefined'.
Comment 6 Justin Zobel 2020-11-12 09:12:57 UTC
Both show nan as the result. Still an issue on kdeplasma-addons from git master.
Comment 7 Bug Janitor Service 2023-01-12 17:21:51 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kdeplasma-addons/-/merge_requests/319
Comment 8 Nate Graham 2023-02-23 15:02:22 UTC
Git commit a4f73ea230ccdffa359dfea69951e95d292b9dfb by Nate Graham, on behalf of Martin Frueh.
Committed on 23/02/2023 at 14:48.
Pushed by ngraham into branch 'master'.

catch division by zero and show correct result (undfined)

M  +10   -0    applets/calculator/package/contents/ui/calculator.qml

https://invent.kde.org/plasma/kdeplasma-addons/commit/a4f73ea230ccdffa359dfea69951e95d292b9dfb