How to compute Soft Absolute Function in a numerically stable way?

103 Views Asked by At

I want to evaluate $$f(x) = x \frac{\exp(ax)+\exp(-ax)}{\exp(ax)-\exp(-ax)}$$

This is a function approximate absolute value of $x$. However,as $a$ goes to large, the better approximation it gets. But this leads to numerical overflow as it will be an exponential function of something big

Any trick to avoid this ?