Say I have this function:
$$f(x)=\frac{\text{e}^x-x}{\sin(x)}$$
And I want to reduce the error when $x\approx0$ and find a stable way to compute the function. More accurate wording, how can the function be written in such a way that the error is reduced?
Near $0$ you need to expand all terms (into the Taylor series) and cancel $x$: $$ \frac{\text{e}^x-1}{\sin(x)}=\frac{x+\frac{x^2}{2}+\frac{x^3}{6}+\dots}{x-\frac{x^3}{6}+\dots}=\frac{1+\frac{x}{2}+\frac{x^2}{6}+\dots}{1-\frac{x^2}{6}+\dots} $$ This formula can be numerically evaluated without problems. If you need a code evaluating this function for any value, then you need this expansion for $x\in[-\varepsilon,\varepsilon]$, where $\varepsilon$ can be explicitly determined (for the required accuracy), and the original formula for $x$ outside of this interval.