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