wolph / alfred-converter

Alfred unit converter is a smart calculator for Alfred with support for unit conversions to make it a bit comparable to the Google Calculator and Wolfram Alpha.
93 stars 15 forks source link

Operations on results from functions gives broken results #20

Closed zaptm closed 4 years ago

zaptm commented 4 years ago

Hi,

First of all thank you for this little workflow. It's so nice to not have to use google all the time just to convert between meters and feet :)

I've found an issue when to do operations on the result from a function. In a nutshell you either get 0 or the value of the first token depending on if you put spaces around the operator or not.

An example:

Screenshot 2020-03-26 at 12 09 29 Screenshot 2020-03-26 at 12 09 39 Screenshot 2020-03-26 at 12 14 01 Screenshot 2020-03-26 at 12 14 44

I've tried with a couple of different expressions and it seems to consistently behave like this. Expressions without functions are working as expected.

I'm using the latest version from git (downloaded on 2020-03-26). There also doesn't seem to be any useful information in the log.

[12:21:11.450] Logging Started...
[12:21:15.029] Unit converter[Script Filter] Queuing argument 'cos(pi/3) * 2'
[12:21:15.231] Unit converter[Script Filter] Script with argv '(null)' finished
[12:21:15.233] Unit converter[Script Filter] <items><item arg="0.5" uid="0.5" valid="yes"><title>0.5</title><subtitle>Action this item to copy the converted value to the clipboard</subtitle><icon>icons/inv-calculator63.png</icon></item></items>
[12:21:27.517] Unit converter[Script Filter] Queuing argument 'cos(pi/3)*2'
[12:21:27.678] Unit converter[Script Filter] Script with argv '(null)' finished
[12:21:27.681] Unit converter[Script Filter] <items><item arg="0" uid="0" valid="yes"><title>0</title><subtitle>Action this item to copy the converted value to the clipboard</subtitle><icon>icons/inv-calculator63.png</icon></item></items>
wolph commented 4 years ago

It took some effort to track down but effectively it comes down to precision. The math library in Python uses floating point numbers for everything and this library uses Decimal objects for everything. The result is a broken calculation.

Anyhow, I've fixed the isssue in the new release :)

zaptm commented 4 years ago

Awesome, thank you. I think I've run into the same thing... Python. Wonderful language which fails in really odd ways sometimes. ;)