APL/APL1.2/TP02/complexes.c

36 lines
593 B
C
Raw Normal View History

2021-11-30 13:54:37 +01:00
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
struct nb_complex {
float real;
float imaginary;
};
typedef struct nb_complex complex;
float module(complex z) {
return sqrt(pow(z.real, 2) + pow(z.imaginary, 2));
}
complex conjugate(complex z) {
z.imaginary = -z.imaginary;
return z;
}
complex inverse(complex z) {
float a = z.real;
float b = z.imaginary;
z.real = a/(pow(a, 2) + pow(b, 2));
z.imaginary = -b/(pow(a, 2) + pow(b, 2));
return z;
}
int main(int argc, char * argv[]) {
complex a = {1.0f, 1.0f};
printf("%f\n", module(inverse(a)));
return EXIT_SUCCESS;
}