I'm implementing a function $f(x_1, x_2, \dots x_n)$ given by the ratio of two closed form equations. $$ f(x_1, x_2, \dots, x_n) = \frac{g(x_1, x_2, \dots, x_n)}{h(x_1, x_2, \dots, x_n)} $$
Unfortunately, when $x_1 = 0$, both $g$ and $h$ are $0$. However there is a well-defined limit $$ k (x_2, x_3, \dots x_n) = \lim_{x_1 \to 0} f(x_1, x_2, \dots x_n) $$
What is a sensible way of implementing this? I was thinking of
if |x_1| > cutoff:
return f(x_1, ..., x_n)/g(x_1, ..., x_n)
else:
return k(x_2, ... x_n)
How do I determine a suitable cutoff?
I have tried to research this question and I came across Higham's book on Accuracy and Stability of Numerical Algorithms.
I found a relevant example in section 1.14.1 where he discusses $f(x) = (e^x-1)/x$. His solution to the instability is different from my naive approach above; he uses a change of coordinates $y = e^x$ that somehow reduce the inaccuracy.
I would appreciate any suggestions/references on how to tackle this problem.