Debian Codegraph @

external/gsl/gsl_sum__work_u.c

raw
1 #include "gsl__config.h"
2 #include "gsl_math.h"
3 #include "gsl_errno.h"
4 #include "gsl_sum.h"
5
6 gsl_sum_levin_u_workspace *
7 gsl_sum_levin_u_alloc (size_t n)
8 {
9 gsl_sum_levin_u_workspace * w;
10
11 if (n == 0)
12 {
13 GSL_ERROR_VAL ("length n must be positive integer", GSL_EDOM, 0);
14 }
15
16 w = (gsl_sum_levin_u_workspace *) malloc(sizeof(gsl_sum_levin_u_workspace));
17
18 if (w == NULL)
19 {
20 GSL_ERROR_VAL ("failed to allocate struct", GSL_ENOMEM, 0);
21 }
22
23 w->q_num = (double *) malloc (n * sizeof (double));
24
25 if (w->q_num == NULL)
26 {
27 free(w) ; /* error in constructor, prevent memory leak */
28
29 GSL_ERROR_VAL ("failed to allocate space for q_num", GSL_ENOMEM, 0);
30 }
31
32 w->q_den = (double *) malloc (n * sizeof (double));
33
34 if (w->q_den == NULL)
35 {
36 free (w->q_num);
37 free (w) ; /* error in constructor, prevent memory leak */
38
39 GSL_ERROR_VAL ("failed to allocate space for q_den", GSL_ENOMEM, 0);
40 }
41
42 w->dq_num = (double *) malloc (n * n * sizeof (double));
43
44 if (w->dq_num == NULL)
45 {
46 free (w->q_den);
47 free (w->q_num);
48 free(w) ; /* error in constructor, prevent memory leak */
49
50 GSL_ERROR_VAL ("failed to allocate space for dq_num", GSL_ENOMEM, 0);
51 }
52
53 w->dq_den = (double *) malloc (n * n * sizeof (double));
54
55 if (w->dq_den == NULL)
56 {
57 free (w->dq_num);
58 free (w->q_den);
59 free (w->q_num);
60 free (w) ; /* error in constructor, prevent memory leak */
61
62 GSL_ERROR_VAL ("failed to allocate space for dq_den", GSL_ENOMEM, 0);
63 }
64
65 w->dsum = (double *) malloc (n * sizeof (double));
66
67 if (w->dsum == NULL)
68 {
69 free (w->dq_den);
70 free (w->dq_num);
71 free (w->q_den);
72 free (w->q_num);
73 free (w) ; /* error in constructor, prevent memory leak */
74
75 GSL_ERROR_VAL ("failed to allocate space for dsum", GSL_ENOMEM, 0);
76 }
77
78 w->size = n;
79 w->terms_used = 0;
80 w->sum_plain = 0;
81
82 return w;
83 }
84
85 void
86 gsl_sum_levin_u_free (gsl_sum_levin_u_workspace * w)
87 {
88 free (w->dsum);
89 free (w->dq_den);
90 free (w->dq_num);
91 free (w->q_den);
92 free (w->q_num);
93 free (w);
94 }