From f353cab3926cd3fa0e5c9952917677e31b6fc6bc Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 17 Mar 2020 10:46:38 +0000 Subject: [PATCH] [fun-gen] prepare for complex coefficients --- fun-gen.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fun-gen.c b/fun-gen.c index ddd5260..62cd5ef 100644 --- a/fun-gen.c +++ b/fun-gen.c @@ -15,6 +15,7 @@ #define _DEFAULT_SOURCE #endif +#include #include #include #include @@ -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"); } }