Open ZippyMagician opened 4 years ago
I have no plans to do this. I did introduce a logarithm function to bignumber.js so non-integer powers could be calculated, but it required so many changes that I instead released it as a separate library, decimal.js.
Dr Ron Knott, author of the excellent Dr Ron Knott's web pages on Mathematics, created a bignumberLIB.js library which adds a log function. See A BigNumber.js Library of Mathematical Constants and Functions.
It uses the older bignumber.js API, but I have worked around that and converted it to a module:
It still needs some work though as can be seen from running node test.mjs
, but it is not something I will be working on in the near future.
If one day you want to consider it again, these are my arguments:
ln
and exp
exp(sum(ln(n))/count(n))
)decimal.js
cannot be used in finance because it rounds by precision and not by decimal positions.
@emilioplatzer
Okay, I'll reconsider adding those functions.
Thanks for your input.
any update on this ? @MikeMcl
Even 3 years later it is needed.
help us @MikeMcl 🙂
I would like to add these functions but my time is very limited at the moment.
What is the maximum number of decimal places that would be required for ln
and exp
, as implementing them would be considerably simpler if that number was limited rather than arbitrarily large?
@MikeMcl your question is excelent. I think that the decimal places can be a parameter of the function (may be an optional one that by default is the default of the lib). For all, but in special for the ln
function
In my use case (geometric average = exp(sum(ln(n))/count(n))
) for be acurated its needed that ln
has more decimals than the normal calculations. If you are calculating amounts in dolars most operations need to be with 2 decimal places (+, *, -, exp) and other need to have more(/, ln).
The reason is the unit of the magnitud. dolar + dolar = dolar, dolar - dolar = dolar, but dolar/dolar = real (without unit), that may be a factor, then there is needed more decimal places. But if you are dividing a total in parts you have dolar / real = dolar (that needs 2 decimal places). ln(dolar)
is of type ln of dolar
need many decimal places, and when it goes to exp(a)
(if a = sum(ln(dolar))
) we need only 2 decimal places to exp
bacause exp(ln of dolar)
has the unit dolar
.
I like a lot your lib. If you add exp
with de normal decimal places and ln
with 8 or programable decimal places I be very happy. Or may be you can have 2 default, one for normal operations, other for ln
and div
.
Will a logarithm/natural logarithm function be introduced at some point? I am aware
decimal.js
supports these functions, but I prefer the base parsing of this library over the former.