From 5ee2288399f69a32fb4b8233f9ad30936bd018ae Mon Sep 17 00:00:00 2001 From: Mark Jenkinson <mark@fmrib.ox.ac.uk> Date: Thu, 24 Jul 2003 15:02:40 +0000 Subject: [PATCH] Added sinc --- miscmaths.cc | 18 ++++++++++++++++++ miscmaths.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/miscmaths.cc b/miscmaths.cc index 01fcb8f..6a58ebb 100644 --- a/miscmaths.cc +++ b/miscmaths.cc @@ -26,6 +26,24 @@ namespace MISCMATHS { // using std::pow; using std::atan2; + + float Sinc(const float x) { + if (fabs(x)<1e-9) { + return 1-x*x*M_PI*M_PI/6.0; + } else { + return sin(M_PI*x)/(M_PI*x); + } + } + + double Sinc(const double x) { + if (fabs(x)<1e-9) { + return 1-x*x*M_PI*M_PI/6.0; + } else { + return sin(M_PI*x)/(M_PI*x); + } + } + + // General string/IO functions bool isnum(const string& str) diff --git a/miscmaths.h b/miscmaths.h index 5574c00..e6f10a2 100644 --- a/miscmaths.h +++ b/miscmaths.h @@ -85,6 +85,9 @@ namespace MISCMATHS { inline double sqrt(int x) { return std::sqrt((double) x); } inline double log(int x) { return std::log((double) x); } + float Sinc(const float x); + double Sinc(const double x); + int periodicclamp(int x, int x1, int x2); template<class S, class T> -- GitLab