Gnome calculator is broken (on Fedora)
So I’m doing some work to double check the arithmetic of our app, and I’m using the gnome calculator. And I notice a bug - what do you think it gives if you type in: 2 * 2 + 2 * 2? So assuming we’ve all done basic primary school maths, the answer is 8 right?
Wrong
According to gnome calculator, its 12!
And not only is it wrong, they have known about it since at least the middle of 2004 and it still has not been fixed. And even then it appears that the broken behaviour is “still an alternate mode with this latest version”. Even if that version exists, it is not a part of Fedora core 3.
So here’s a nice friendly note to the gnome developers: YOU DON’T GET A VOTE ON THE LAWS OF MATHEMATICS. FIX IT. IT IS WRONG.”’
And just to reinfrce it, it does indeed work on the KDE calculator, windows, MacOsX….
Update OK, so it appears that the latest version fixes this problem (2004-11-03). So my question is replaced with “Why did it take them so long” and “Why hasn’t Fedora fixed this yet?”. I have left the main text intact, because it conveys some of the disbelief and frustration at the implementation, and they deserve it for leaving it there so long - and definitely for keeping it as an “alternate mode”. Hi guys - I’ll say it again: There is no alternate mode.
I guess the lesson to take from this is that there are some places where we, as developers, just don’t get a choice. It doesn’t matter if we don’t understand the laws of precedence, they are fixed, and have been in place for at least 400 years. In this case the mathematicians are right. Literally “by definition”.
Update: See also More on Calculators…
February 1st, 2005 at 2:20 pm
They’re emulating a classic mechanical calculator. :) Stack-based calculators are a purely electronic invention; mechanical calculators had to determine the answer at each step.
Essentially, most calculators automatically evaluate the expression as it stands right now, saving you the trouble of hitting equals. For most “kitchen arithmetic” problems, this is the desired behaviour.
It’s the job of the human to enter the values into the calculator in the order of desired evaluation. :) Try it with a $10 pocket calculator for comparison. Oh, and a calculator isn’t a spreadsheet.
The scary question is… why did you need a calculator to work out 2*2+2*2? :)
February 1st, 2005 at 4:58 pm
Oh, and the answer is 12 in the Windows XP calculator in the ’standard’ mode, and 8 in the ’scientific’ mode. Just like you’d expect. :)
February 1st, 2005 at 9:06 pm
First of all, its not wrong. There are no parenthesis in that statement, therefore according to simple mathematics (NOT programming mathematics), all calculations are taken in turn. 2*2 = 4 + 2 = 6 * 2 = 12
Now, 99% of programming languages will do any multiplaction or division first (after evaluating any parentheticals), but really, the Gnome calculator is simply enforcing stricter rules (requiring the 2*2 to be in parenthesis).
Most programming languages actually hijack mathematic principles to correct for programmers not being mathematicians.
February 1st, 2005 at 11:24 pm
Um - beg to differ.
Mathematics has well established rules of precedence and has had since the 1600s (see the link in the blog entry). This is why I can write an equation like ax + by = 2 and don’t have to specify (ax) + (by) = 2
Programming languages are the ones that are inconsistent.
When I learned it in primary school, we called it BODMAS - and it is indeed the universal set of rules for maths - try Googling for it.
FYI: My degree is in Physics and Mathematics :-)