# Sinc function

(Difference between revisions)
 Revision as of 23:46, 14 November 2006 (edit)m (Mathify 0/0)← Previous diff Revision as of 16:34, 15 November 2006 (edit) (undo) (Category:Mathematics)Next diff → Line 1: Line 1: - The sinc function, $\frac{sin(x)}{x}$, is a useful function that is a little tricky to implement because it becomes $\frac{0}{0}$ as x approaches $0$. Here is an implementation taken from the [http://www.boost.org/boost/math/special_functions/sinc.hpp Boost] library. + The sinc function, $\frac{\sin(x)}{x}$, is a useful function that is a little tricky to implement because it becomes $\frac{0}{0}$ as x approaches $0$. Here is an implementation taken from the [http://www.boost.org/boost/math/special_functions/sinc.hpp Boost] library. -
+
epsilon :: RealFloat a => a                                                                                                                                                                                                                                                                                                                                                                            epsilon :: RealFloat a => a
epsilon = encodeFloat 1 (fromIntegral $1-floatDigits epsilon) epsilon = encodeFloat 1 (fromIntegral$ 1-floatDigits epsilon)
Line 11:                                                                                                                                                                                                                                                                                                                                                                                     Line 11:
where                                                                                                                                                                                                                                                                                                                                                                                                  where
taylor_n_bound = sqrt $sqrt epsilon taylor_n_bound = sqrt$ sqrt epsilon
-
+ + + [[Category:Mathematics]]

## Revision as of 16:34, 15 November 2006

The sinc function, $\frac{\sin(x)}{x}$, is a useful function that is a little tricky to implement because it becomes $\frac{0}{0}$ as x approaches 0. Here is an implementation taken from the Boost library.

epsilon :: RealFloat a => a
epsilon = encodeFloat 1 (fromIntegral $1-floatDigits epsilon) {- Boosted from Boost http://www.boost.org/boost/math/special_functions/sinc.hpp -} sinc :: (RealFloat a) => a -> a sinc x | (abs x) >= taylor_n_bound = (sin x)/x | otherwise = 1 - (x^2/6) + (x^4/120) where taylor_n_bound = sqrt$ sqrt epsilon