#include <u.h>
#include <stdio.h>
#include <libc.h>
#include "../config.h"
#include "../sys/gsl_sys.h"
#include "../gsl_machine.h"
#include "../gsl_types.h"
#include "../gsl_precision.h"
#include "../gsl_nan.h"
#include "../gsl_pow_int.h"
#include "../gsl_math.h"
#include "../gsl_mode.h"
#include "../err/gsl_errno.h"

#include "gsl_sf_result.h"
#include "gsl_sf_exp.h"
#include "gsl_sf_log.h"
#include "gsl_sf_psi.h"
#include "gsl_sf_gamma.h"
#include "error.h"
#include "chebyshev.h"


static  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 y2 = 2.0 * y;

  double e = 0.0;

  for(j = cs->order; j>=1; j--) {
    double temp = d;
    d = y2*d - dd + cs->c[j];
    e += fabs(y2*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;
}

