From 0f5c62013c0210e1f9806342eb1271674f735d7d Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Sun, 3 Feb 2008 17:28:23 +0100 Subject: [PATCH] Add a much better sinc() implementation. --- qscale.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) 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) -- 2.39.2