GNOME Bugzilla – Bug 770344
Reusing a previously used unit shows "unknown variable" error
Last modified: 2017-03-27 19:19:37 UTC
Created attachment 334094 [details] Screenshot of the situation described above. When in keyboard mode, after converting a specific unit into other,we get an answer. And when the same answer is used again its says unknown variable <unit>. Let me elaborate with an example: 1 hour in minute *Press enter* 60 Now use this same digit without erasing: 60 minute in second *Press enter* Unknown variable 'minute'
Confirming in for gnome-calculator-3.20.2-1.fc24.x86_64
Technically this happens because the equation parser does handle the 'number + unit + "in" + unit' case, but does not handle the 'variable + unit + "in" + unit' case, and the "reused" answer is handled as a variable called 'ans'. Other calculations however do work with the 'ans' variable. Patches are welcome, I have tried to do it, but somehow the resulting ParseTree failed to solve, and I can't find the reason.
Created attachment 345870 [details] [review] Allow much complex conversions in Calculator This patch rewrites the part of parser that handles conversions. With the new code, it's possible to convert variables, as well as complex equations. With this patch, the following computations are possible: 10×20 m² in acres 1000+500 GB in GiB ((10 inch in cm) × (1 feet in cm)) cm² in m² 2π radians in degrees 3π + π÷2 radians in degrees This is perticularly useful for people working with multiple units at the same time. e.g. Calculating Gravitational force between a 0.25 pound bag of chips and 1.25kg laptop that are 17 feet away from each other.
Ping
(In reply to PioneerAxon from comment #4) > Ping Pong PioneerAxon :) I haven't forgotten this, I just didn't manage to get it in 3.24.0, your patch has appeared relatively late, and is not a trivial one :) I have just released 3.24.0 yesterday, and my plans for this week included pushing this :)
Sure, Robert Roth. I didn't see the e-mail for 3.24 release of Calculator. So was not sure what happened. Sorry for the huge patch. Take your time. :) Hopefully this will make life easy for a lot of users in general. O:) It'll also make the code more readable as a lot of code is removed from parser (aka. the bowl of spaghetti). :P
I finally managed to test and review the patch, understood (mostly) what it does, and it looks and works ok from my initial tests.