Numerically stable sinc function
Question
Implement the function so that it returns sensible values for every real input.
Short answer
Special-case small with a Taylor series. At the formula is although the limit is , and very near zero the ratio loses accuracy. Below a small threshold return ; otherwise compute directly. The function is even, and for large the direct formula is fine.
Adapted from Joshi, Denson & Downes, Quant Job Interview Questions and Answers, Q5.8, p.158; question and answer rewritten by SelfMadeQuant.com.
See the hint and the full worked solution in the question bank (free account).
Open the worked solution