I am trying to graph the function $y=(e^x -1)/x$ for values of $x$ close to zero.
The result should be $y$ close to $1$. Howevere, both in Excel and WolframAlpha the calculated values become very unpredictable for magnitudes of $x$ of the order $-10^{-8}<x<10^{-8}$.
(1) Why is this? (2) Is there a more accurate way to calculate this function when $x$ is close to zero?
When $|x| \ll 1, e^x \approx 1+x+x^2/2$ from the Taylor series. When you subtract $e^x-1$ in a computer, you lose precision. Say your computer stores numbers in decimal with $10$ places (it works the same in binary, but we are used to decimal). In the computer, $e^{10^{-8}} = 1.000000010,$, so $e^{10^{-8}}-1 = 0.000000010$ and only has two places accuracy. For $|x| \ll 1$,it is much more accurate to analytically say $e^x-1 \approx x+x^2/2,$ so $(e^x-1)/x \approx 1+x/2$
This subject is discussed at great length in numerical analysis classes.