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)
KRunner also shows "Infinity" for 1/0 and "NaN" for 0/0
(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"
>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.
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"?
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'.
Both show nan as the result. Still an issue on kdeplasma-addons from git master.
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kdeplasma-addons/-/merge_requests/319
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