2 #include <gsl/gsl_math.h>
3 #include <gsl/gsl_errno.h>
4 #include <gsl/gsl_sum.h>
6 gsl_sum_levin_u_workspace *
7 gsl_sum_levin_u_alloc (size_t n)
9 gsl_sum_levin_u_workspace * w;
13 GSL_ERROR_VAL ("length n must be positive integer", GSL_EDOM, 0);
16 w = (gsl_sum_levin_u_workspace *) malloc(sizeof(gsl_sum_levin_u_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->dq_num = (double *) malloc (n * n * sizeof (double));
44 if (w->dq_num == NULL)
48 free(w) ; /* error in constructor, prevent memory leak */
50 GSL_ERROR_VAL ("failed to allocate space for dq_num", GSL_ENOMEM, 0);
53 w->dq_den = (double *) malloc (n * n * sizeof (double));
55 if (w->dq_den == NULL)
60 free (w) ; /* error in constructor, prevent memory leak */
62 GSL_ERROR_VAL ("failed to allocate space for dq_den", GSL_ENOMEM, 0);
65 w->dsum = (double *) malloc (n * sizeof (double));
73 free (w) ; /* error in constructor, prevent memory leak */
75 GSL_ERROR_VAL ("failed to allocate space for dsum", GSL_ENOMEM, 0);
86 gsl_sum_levin_u_free (gsl_sum_levin_u_workspace * w)