GNOME Bugzilla – Bug 775789
Taking the zeroth root of a number freezes GNOME Calculator
Last modified: 2017-02-13 16:48:43 UTC
Entering ₀√2 into the calculator results in a freeze. This is probably because GNOME Calculator isn't trapping a division by zero somewhere because ₀√2 = 2^(1/0). GNOME Calculator really should print out an error like "Division by zero is undefined," or better yet, "The zeroth root of a number is undefined." :)
This problem has been fixed in the unstable development version. The fix will be available in the next major software release. You may need to upgrade your Linux distribution to obtain that newer version.
Created attachment 342865 [details] [review] Highlight the 0th root token when 0th root is calculated. This patch adds code that highlights the part of equation representing 0th root of the calculation.
Hi Robert, I know that this bug is closed. But can we get the fix above checked in? It's important to highlight the correct part of the input for an error. Right now, it highlights "2" in ₀√2 while complaining about "0th root". The patch above fixes this and highlights "₀" instead. The patch also is a generic improvement over the previous code, as it allows detection of 0th root from parsed Node rather than relying on the error from MPFR wrapper.
Comment on attachment 342865 [details] [review] Highlight the 0th root token when 0th root is calculated. Thanks, I'm not sure how I missed the patch. I have tested it, and indeed, it improves the situation. Highlight should be on the 0 when we are complaining about the zeroth root. Pushing.
Created attachment 345645 [details] [review] Highlight 0th root error token when 0th root is calculated. Highlight 0th root error token when 0th root is calculated. This also prevents overwriting errors when perser object has error code set. As a side-effect of this, now we return correct error (Unknown variable) when a function is invoked with invalid variable as argument. e.g. f(x) = x + 2 f(x) will result in "Unknown variable x", instead of generic "Malformed expression" error.
The new patch is supposed to fix the unit test breakage. I just noticed that you already pushed the previous patch. Since it's one line change, it's okay if you just create local fix and push that instead of whole revert-apply-push cycle.
Attachment 345645 [details] pushed as 9cea9c1 - Highlight 0th root error token when 0th root is calculated.