HaskellWiki

Haskell | Wiki community | Recent changes
Random page | Special pages

 

Not logged in
Log in | Help

Sinc function

Categories: Code | Mathematics

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 =
   if abs x >= taylor_n_bound
     then sin x / x
     else 1 - x^2/6 + x^4/120
 where
  taylor_n_bound = sqrt $ sqrt epsilon

Retrieved from "http://haskell.org/haskellwiki/Sinc_function"

This page has been accessed 2,347 times. This page was last modified 16:35, 15 November 2006. Recent content is available under a simple permissive license.