2 #include <gsl/gsl_math.h>
3 #include <gsl/gsl_errno.h>
4 #include <gsl/gsl_sum.h>
6 gsl_sum_levin_utrunc_workspace *
7 gsl_sum_levin_utrunc_alloc (size_t n)
9 gsl_sum_levin_utrunc_workspace * w;
13 GSL_ERROR_VAL ("length n must be positive integer", GSL_EDOM, 0);
16 w = (gsl_sum_levin_utrunc_workspace *) malloc(sizeof(gsl_sum_levin_utrunc_workspace));
20 GSL_ERROR_VAL ("failed to allocate struct", GSL_ENOMEM, 0);
23 w->q_num = (double *) malloc (n * sizeof (double));
27 free(w) ; /* error in constructor, prevent memory leak */
29 GSL_ERROR_VAL ("failed to allocate space for q_num", GSL_ENOMEM, 0);
32 w->q_den = (double *) malloc (n * sizeof (double));
37 free (w) ; /* error in constructor, prevent memory leak */
39 GSL_ERROR_VAL ("failed to allocate space for q_den", GSL_ENOMEM, 0);
42 w->dsum = (double *) malloc (n * sizeof (double));
48 free (w) ; /* error in constructor, prevent memory leak */
50 GSL_ERROR_VAL ("failed to allocate space for dsum", GSL_ENOMEM, 0);
61 gsl_sum_levin_utrunc_free (gsl_sum_levin_utrunc_workspace * w)