The garden has frozen over and I have caught a cold. It is hard to do difficult work. Thus I continue to find fast approximations of transcendental functions. This is more fun than solving crossword puzzles.
What is the accuracy? The exponential function varies strongly and it is more reasonable to look at its relative error. Using a table of 1000 elements for exp(x), we get a relative error of 0.00025 for the simple nearest point approximation. The linear interpolation is better with an error of only 6e-8. That’s good enough for most calculations. Because (d²exp(x)/dx²)=exp(x) we can again improve the linear interpolation to get a quadratic approximation. Its error is only 4e-12.
The timing for 100 million function evaluations is again very interesting. Chrome seems to be a bit faster than Chromium. It takes about 1 second for the empty loop. Evaluating the original Mat.exp() function takes additional 10 seconds. Our approximations are about four times faster. The simple approximation takes 2.1 seconds, the linear interpolation 2.4 seconds and the “quadratic” approximation 2.6 seconds.
Again, Firefox is faster. Doing the empty loop takes only 0.3 seconds. The Math.exp() needs only 2.5 seconds more and is four times faster than in Chrome! The approximations are five times faster. The simple approximation takes 0.3 seconds, the linear interpolation 0.5 seconds and the “quadratic” approximation 0.7 seconds.
It seems best to use Firefox and the linear approximation.