Hacker News new | past | comments | ask | show | jobs | submit login

expm1 is the modern equivalent. That (plus the related log1p) are probably some of the most underutilized standard library math functions. They can substantially improve the accuracy of tons of calculations.



Can you give an example of a common situation where a programmer should have used expm1 or log1p but didn't? (the way it's common for people to test if something is inside/outside a circle or sphere by comparing the square root of the sum of squares to the radius as opposed to compare the sum of squares to the square of the radius, or use trig functions when linear algebra will do)

I do a reasonable amount of computational programming but to my recollection I've never used either of those functions.


One example I can think of is doing an interest calculation with small interest rates/short periods, where you'd want to know that someone owes you 0.000000001234 dollars in interest today rather than owing you 1.000000001 - 1 dollars.


One common situation is when evaluating CDFs for exponential or weibull probability distributions. The CDF formula for both of those distributions includes a 1 - e^(x) term that can easily be transformed into expm1 for additional precision.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: