[fun-gen] prepare for complex coefficients
This commit is contained in:
parent
78fa2ba50a
commit
f353cab392
10
fun-gen.c
10
fun-gen.c
@ -15,6 +15,7 @@
|
||||
#define _DEFAULT_SOURCE
|
||||
#endif
|
||||
|
||||
#include <complex.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -29,14 +30,14 @@
|
||||
|
||||
struct poly {
|
||||
int degree;
|
||||
double *coefs;
|
||||
double complex *coefs;
|
||||
const char *expr;
|
||||
};
|
||||
|
||||
static void
|
||||
poly_init(struct poly *p, unsigned int degree, const char *expr)
|
||||
{
|
||||
if ((p->coefs = malloc((degree + 1) * sizeof(double))) == NULL)
|
||||
if ((p->coefs = malloc((degree + 1) * sizeof(*p->coefs))) == NULL)
|
||||
errx(1, "out of memory");
|
||||
|
||||
p->degree = degree;
|
||||
@ -107,9 +108,10 @@ print_fun_body(size_t n, struct poly *polys)
|
||||
printf("\ta *= z;\n");
|
||||
for (j = n; j > i; j--)
|
||||
if (polys[j - 1].coefs[d] != 0.0L)
|
||||
printf("\t%s += %.20f * a;\n",
|
||||
printf("\t%s += (%.20f + I * %.20f) * a;\n",
|
||||
polys[j - 1].expr,
|
||||
polys[j - 1].coefs[d]);
|
||||
creal(polys[j - 1].coefs[d]),
|
||||
cimag(polys[j - 1].coefs[d]));
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user