/* * Some useful declarations for complex arithmetic. * A point in the plane may be considered complex once * we define arithmetic on it. */ /* * cpoint represents a point in the plane with * x and y coordinates * */ struct cpoint { double x, y; }; /* * cplus implements complex addition * * parameters: * z1 and z2 are complex points * * return: * a new complex point which is the vector * sum of the parameters */ extern struct cpoint cplus(struct cpoint z1, struct cpoint z2); /* * ctimes implements complex multiplication * * parameters: * z1 and z2 are complex points * * return: * a new complex point which the the complex product of * complex points z1 and z2. Defined by the formula: * z1 * z1 == z1.x * z2.x - z1.y * z2.y (new x component) * z1.x * z2.y + z2.y * z1.x (new y component) * */ extern struct cpoint ctimes(struct cpoint z1, struct cpoint z2); /* * mag returns the magnitude (modulus) of a complex point * * parameter: z is a complex point * * return: The magnitude of z is define by: * |z| == sqrt(z.x**2 + z.y**2) */ extern double mag(struct cpoint z); /* * conj returns the complex conjugate of a complex point * * parameter: z is a complex point * * return: The conjugate of z has the same x component, and * the negation of the y component */ extern struct cpoint conj(struct cpoint z); /* * cdiv implements complex multiplication * * parameters: * z1 and z2 are complex points * * return: * a new complex number z1/z2 which is defined by the * formula: * z1/z2 == ctimes(z1 , conj(z2)) / mag(z2)**2 * (where / is floating point division). * Not defined when mag(z2) == 0 */ extern struct cpoint cdiv(struct cpoint z1, struct cpoint z2);