ericmj / decimal

Arbitrary precision decimal arithmetic

Home Page:https://hexdocs.pm/decimal/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Does it make sense to have a inv/1 function?

apr94 opened this issue · comments

A lot of times, I find myself doing the following:

D.new(1)
|> D.div(num) 

to calculate the inverse of sum. Normally this is fine, but when sum is piped in from preceding ops, I am not able to cleanly calculate its inverse through pipes and I need to capture the value.

Having an inv/1 function would solve this, does it make sense to add it to the library?

If the problem is we can't pipe something, the usual solution is to introduce a function that can be used in a pipe, e.g.:

defp inverse(decimal), do: Decimal.div(1, decimal)

For this reason, I'd personally prefer to not include it to keep the API smaller and we can always add it later.