| 1 |
/* poly/zsolve_init.c |
| 2 |
* |
| 3 |
* Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough |
| 4 |
* |
| 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This program is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program; if not, write to the Free Software |
| 17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include "gsl__config.h" |
| 21 |
#include <math.h> |
| 22 |
#include "gsl_math.h" |
| 23 |
#include "gsl_complex.h" |
| 24 |
#include "gsl_poly.h" |
| 25 |
#include "gsl_errno.h" |
| 26 |
|
| 27 |
gsl_poly_complex_workspace * |
| 28 |
gsl_poly_complex_workspace_alloc (size_t n) |
| 29 |
{ |
| 30 |
size_t nc ; |
| 31 |
|
| 32 |
gsl_poly_complex_workspace * w ; |
| 33 |
|
| 34 |
if (n == 0) |
| 35 |
{ |
| 36 |
GSL_ERROR_VAL ("matrix size n must be positive integer", GSL_EDOM, 0); |
| 37 |
} |
| 38 |
|
| 39 |
w = (gsl_poly_complex_workspace *) |
| 40 |
malloc (sizeof(gsl_poly_complex_workspace)); |
| 41 |
|
| 42 |
if (w == 0) |
| 43 |
{ |
| 44 |
GSL_ERROR_VAL ("failed to allocate space for struct", GSL_ENOMEM, 0); |
| 45 |
} |
| 46 |
|
| 47 |
nc = n - 1; |
| 48 |
|
| 49 |
w->nc = nc; |
| 50 |
|
| 51 |
w->matrix = (double *) malloc (nc * nc * sizeof(double)); |
| 52 |
|
| 53 |
if (w->matrix == 0) |
| 54 |
{ |
| 55 |
free (w) ; /* error in constructor, avoid memory leak */ |
| 56 |
|
| 57 |
GSL_ERROR_VAL ("failed to allocate space for workspace matrix", |
| 58 |
GSL_ENOMEM, 0); |
| 59 |
} |
| 60 |
|
| 61 |
return w ; |
| 62 |
} |
| 63 |
|
| 64 |
void |
| 65 |
gsl_poly_complex_workspace_free (gsl_poly_complex_workspace * w) |
| 66 |
{ |
| 67 |
free(w->matrix) ; |
| 68 |
free(w); |
| 69 |
} |