From: sgunderson@bigfoot.com <> Date: Sun, 3 Feb 2008 16:28:23 +0000 (+0100) Subject: Add a much better sinc() implementation. X-Git-Url: https://git.sesse.net/?p=qscale;a=commitdiff_plain;h=0f5c62013c0210e1f9806342eb1271674f735d7d Add a much better sinc() implementation. --- diff --git a/qscale.c b/qscale.c index 6d529bc..1b3ab57 100644 --- a/qscale.c +++ b/qscale.c @@ -9,11 +9,18 @@ double sinc(double x) { - // This is bad for very small x, should use power series instead. - if (x == 0.0) - return 1.0; - else + static const double eps = 2.22045e-016; + static const double cutoff = sqrt(sqrt(eps)); + + if (abs(x) < cutoff) { + // For small |x|, use Taylor series instead + const double x2 = x * x; + const double x4 = x2 * x2; + + return 1.0 - x2 / 6.0 + x4 / 120.0; + } else { return sin(x) / x; + } } double lanczos_tap(double x)