am-kantox / formulae

A set of function to deal with analytical formulae.
15 stars 2 forks source link

Supporting calculations with Decimals #10

Open dcaixinha opened 1 month ago

dcaixinha commented 1 month ago

Hi! First of all, thanks for this great lib :raised_hands:

Would you accept adding support for calculations with Decimals (namely this Decimal library, the one used by Ecto for the :decimal type)?

In some situations (e.g. dealing with money or other sensitive values), handling floats is dangerous, so it'd be good to have the ability to do math with decimals as well! Thanks :pray:

vlemann commented 1 month ago

Starting with v0.17.0 one might explicitly unimport Kernel functions to prevent clashes with imports.

iex|1> Formulae.compile "div(100, 3)", imports: [Decimal], unimports: [div: 2]
iex|2> Formulae.eval v()
Decimal.new("33.33333333333333333333333333")