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)