pub fn eval<const N_COEFFICIENTS: usize>(
coefficients: &[Finite<f64>; N_COEFFICIENTS],
x: Finite<f64>,
) -> ApproxExpand description
Chebyshev series/polynomial approximation.
ยงOriginal C code
struct cheb_series_struct {
double * c; /* coefficients */
int order; /* order of expansion */
double a; /* lower interval point */
double b; /* upper interval point */
int order_sp; /* effective single precision order */
};
typedef struct cheb_series_struct cheb_series;
// ...
static inline int
cheb_eval_e(const cheb_series * cs,
const double x,
gsl_sf_result * result)
{
int j;
double d = 0.0;
double dd = 0.0;
double y = (2.0*x - cs->a - cs->b) / (cs->b - cs->a);
double two_x = 2.0 * y;
double e = 0.0;
for(j = cs->order; j>=1; j--) {
double temp = d;
d = two_x*d - dd + cs->c[j];
e += fabs(two_x*temp) + fabs(dd) + fabs(cs->c[j]);
dd = temp;
}
{
double temp = d;
d = y*d - dd + 0.5 * cs->c[0];
e += fabs(y*temp) + fabs(dd) + 0.5 * fabs(cs->c[0]);
}
result->val = d;
result->err = GSL_DBL_EPSILON * e + fabs(cs->c[cs->order]);
return GSL_SUCCESS;
}