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

Fix log10 and add log2 functions #47

Closed aaronkollasch closed 1 year ago

aaronkollasch commented 1 year ago

The query "log10()" was broken, as the "log10" string was being converted to "logDecimal(10)" in safe_eval(): https://github.com/wolph/alfred-converter/blob/49f3053932ee4ef13cecdeccc030fa52e5cab4b9/converter/safe_math.py#L209 Thus, the resulting query was "logDecimal(10)()", which produced an error.

This PR prevents replacement of numbers in function names with Decimals, using a negative look-behind to remove decimal matches immediately preceded by letters or numbers. It also adds the math.log2() function.

wolph commented 1 year ago

Nice, thank you!

wolph commented 1 year ago

I've created a new release with your added feature :)