NFFT Logo 3.2.2
sinc.c
00001 /*
00002  * Copyright (c) 2002, 2012 Jens Keiner, Stefan Kunis, Daniel Potts
00003  *
00004  * This program is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but WITHOUT
00010  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00012  * details.
00013  *
00014  * You should have received a copy of the GNU General Public License along with
00015  * this program; if not, write to the Free Software Foundation, Inc., 51
00016  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00017  */
00018 
00019 /* $Id: util.c 3483 2010-04-23 19:02:34Z keiner $ */
00020 
00021 #include "infft.h"
00022 
00023 R X(sinc)(const R x)
00024 {
00025   /* Based on sinc function from Boost C++ library. */
00026   const R b =  EPSILON;
00027   const R bs = SQRT(b);
00028   const R bs2 = SQRT(bs);
00029 
00030   if (FABS(x) >= bs2)
00031     return SIN(x)/x;
00032   else
00033   {
00034     R r = K(1.0);
00035 
00036     if (FABS(x) >= b)
00037     {
00038       const R x2 = x * x;
00039       r -= x2 / K(6.0);
00040 
00041       if (FABS(x) >= bs)
00042         r += (x2 * x2) / K(120.0);
00043     }
00044 
00045     return r;
00046   }
00047 }

Generated on Fri Oct 12 2012 by Doxygen 1.8.0-20120409