-
Notifications
You must be signed in to change notification settings - Fork 0
/
complex.c
31 lines (26 loc) · 828 Bytes
/
complex.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
#include "complex.h"
ComplexNumber complexSquare(ComplexNumber z) {
return (ComplexNumber) {
(z.real * z.real) - (z.imaginary * z.imaginary),
2 * z.real * z.imaginary
};
}
ComplexNumber complexMultiply(ComplexNumber z, ComplexNumber z1) {
return (ComplexNumber) {
(z.real * z1.real) - (z.imaginary * z1.imaginary),
(z.real * z1.real) + (z.imaginary * z1.imaginary)
};
}
ComplexNumber complexAdd(ComplexNumber z, ComplexNumber z1) {
return (ComplexNumber) {
z.real + z1.real,
z.imaginary + z1.imaginary
};
}
int complexModuloSquared(ComplexNumber z) {
return (int) (z.real * z.real + z.imaginary * z.imaginary);
}
void printComplex(ComplexNumber z) {
printf("%Lf + %Lf \bi\n", z.real, z.imaginary);
}