1-- Description of choice of approximation boundaries in sinc function
2module Sinc where
3
4import Numeric.MathFunctions.Constants (m_epsilon)
5
6
7-- Approximations for sinc up to 6th order and "exact" implementation
8f2,f4,f6,f :: Double -> Double
9f2 x = 1 - x*x/6
10f4 x = 1 - x*x/6 + x*x*x*x/120
11f6 x = 1 - x*x/6 + x*x*x*x/120 - x*x*x*x*x*x/5040
12f  x = sin x / x
13
14-- When next term becomes so small that (1-e)==1 we can neglect it:
15e0,e2,e4 :: Double
16e0 = sqrt (6 * m_epsilon / 4)
17e2 = (30   * m_epsilon) ** (1/4) / 2
18e4 = (1260 * m_epsilon) ** (1/6) / 2
19
20test :: IO ()
21test = do
22  print ("e0",e0)
23  print $ f  e0 == 1
24  print $ f2 e0 == 1
25  --
26  print ("e2",e2)
27  print $ f  e2 == f2 e2
28  print $ f2 e2 == f4 e2
29  --
30  print ("e4",e4)
31  print $ f  e4 == f4 e4
32  print $ f4 e4 == f6 e4
33
34