GNOME Bugzilla – Bug 694864
Doing too large of a calculation results in '0' with no error shown
Last modified: 2014-12-22 20:26:52 UTC
gnome-calculator 3.7.90 on Ubuntu 13.04 amd64. Entering 2²²²² results in 0 with no error displayed. For certain calculations I get the error 'Overflow: the result couldn't be calculated' so this error should at least be shown here. It looks like the limit is somewhere around 2^1342 (or 9*10^403). With gcalctool 6.6.2, although it takes a while to calculate, I still get results from 2 squared 7 times (which is 3*10^688955) which is a significantly higher limit.
Is 2^2^2^2^2 equivalent to 2^256 = 1.157920892×10⁷⁷ ???
Sorry, 2^2^2^2^2 equivalent to 2^65536 ?
Created attachment 269295 [details] [review] Displays error for very large power calculation instead of zero. As stated by the reporter , it seems that 2^1342 is the limit of of Power Calculation. This patch displays error "Power Calculation out of range" when x is raised to a very high power y instead of zero.Kindly review the patch let me know if this patch could be a possible solution for this bug. Thankyou.
Created attachment 269513 [details] [review] Corrected patch: Displays error for very large power calculation instead of zero. This patch displays error for very large power calculation instead of zero considering the fact that 2^1342 is the limit of power calculations.
Review of attachment 269513 [details] [review]: Thank you for the patch. I don't think this is the best way to fix this issue. A better way to fix this would be to detect an overflow while calculating the value, and set the error.
Created attachment 270043 [details] [review] bitwise instead of arithmetic operator This patch wont solve the bug but I think it will slightly speed up the process . if ((n&1) == 1) instead of n%2 == 1 and n>>=1 instead of n=n/2
Review of attachment 270043 [details] [review]: Thank you for the patch. I don't think this will help the execution speed much, as most of these optimizations are already being done by the underlying C compiler. Second thing is that the code readability is really important. So, changing these statements is not a good choice. ::: number_org.vala @@ -913,8 +913,0 @@ - /* 0^0 is indeterminate */ - if (is_zero () && n == 0) - { ... 5 more ... First of all, why are you trying to revert someone else's changes? You should check the diff before committing and before submitting the patch.
ok . Thank you . Will do diff properly .
Created attachment 270458 [details] [review] fix for calculation of large powers and large factorials and also ln(e^x) gving error for x>3 Although this patch fixes the 3 issues mentioned above , I haven't substituted the if condition by any other condition to check overflow as I am not very sure in which case the if condition was supposed to be applicable. Kindly let me know the exact application of the if condition so that I can make the required changes in the patch. Thankyou.
Also I apologize for the above patch being quite incomplete and perhaps directly removing a part of the code without substituting it with any other code is not allowed. Hence if this patch with some modification could possibly be a fix for the three bugs , I would like to work on it.
Created attachment 271114 [details] [review] This patch removed the while(true) , remove break , remove >> and made the code more readable. The patch that I have submitted improves readabilty without affecting the work speed or flow of the gnome calculator .
Review of attachment 270458 [details] [review]: The patch doesn't fix the actual problem, and might end up crashing the Calculator. This bug will be automatically fixed when we replace the back-end of Calculator, as it is directly related to how the overflow is detected and how the calculations are performed.
Review of attachment 271114 [details] [review]: The patch neither fixes the issue, nor is it related to the bug.
Jeremy, Thank you for th report. The bug has been fixed in master branch. Now you can either get the correct result, or a message saying "Precision error". Also, the back-end is capable of calculating numbers upto 2²⁰¹⁹. However, if more precision is needed, the fix is as simple as increasing the back-end precision value using dconf. It will slow down calculations, but if you gotta have more precision, you gotta pay the cost.. :P Reference commit : https://git.gnome.org/browse/gnome-calculator/commit/?id=0e863eeb121d670d8f5266a82b6152e98b2428ea Hope this helps..