#include #include #include #include "complex.h" struct complex { double x; double y; }; complex complex_new(double x, double y) { complex z = malloc(sizeof(struct complex)); z->x = x; z->y = y; return z; } complex inject(double x) { return complex_new(x,0.0); } complex cclone(complex z) { return complex_new(z->x,z->y); } void cdelete(complex z) { free(z); } double real_part(complex z) { return z->x; } double imag_part(complex z) { return z->y; } complex cadd(complex z1,complex z2) { return complex_new(z1->x + z2->x, z1->y + z2->y); } complex cmul(complex z1,complex z2) { return complex_new(z1->x * z2->x - z1->y * z2->y, z1->x * z2->y + z1->y * z2->x); } double module(complex z) { return sqrt(z-> x * z -> x + z-> y * z -> y); }