After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 770344 - Reusing a previously used unit shows "unknown variable" error
Reusing a previously used unit shows "unknown variable" error
Status: RESOLVED FIXED
Product: gnome-calculator
Classification: Core
Component: general
3.20.x
Other Linux
: Normal normal
: ---
Assigned To: gcalctool maintainers
gcalctool maintainers
Depends on:
Blocks:
 
 
Reported: 2016-08-24 18:07 UTC by Ankit R Gadiya
Modified: 2017-03-27 19:19 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Screenshot of the situation described above. (18.08 KB, image/png)
2016-08-24 18:07 UTC, Ankit R Gadiya
  Details
Allow much complex conversions in Calculator (26.29 KB, patch)
2017-02-15 20:12 UTC, PioneerAxon
committed Details | Review

Description Ankit R Gadiya 2016-08-24 18:07:18 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'
Comment 1 André Klapper 2016-08-24 18:16:55 UTC
Confirming in for gnome-calculator-3.20.2-1.fc24.x86_64
Comment 2 Robert Roth 2016-10-06 21:15:10 UTC
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.
Comment 3 PioneerAxon 2017-02-15 20:12:18 UTC
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.
Comment 4 PioneerAxon 2017-03-22 18:12:40 UTC
Ping
Comment 5 Robert Roth 2017-03-22 18:24:07 UTC
(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 :)
Comment 6 PioneerAxon 2017-03-23 05:27:50 UTC
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
Comment 7 Robert Roth 2017-03-27 19:19:33 UTC
I finally managed to test and review the patch, understood (mostly) what it does, and it looks and works ok from my initial tests.