1 /* complex - Complex number functions */
2 /* Copyright (c) 1990, by Luke Tierney */
4 /* patched up and semi-ansified, (c) 2006, AJ Rossini, blindglobe@gmail.com */
9 extern void xlfail(char *);
18 if (c
.imag
> 0.0) phi
= PI
/ 2;
19 else if (c
.imag
== 0.0) phi
= 0.0;
22 phi
= atan(c
.imag
/ c
.real
);
41 return(sqrt(c
.real
* c
.real
+ c
.imag
* c
.imag
));
45 cart2complex(double real
, double imag
)
54 polar2complex(double mod
, double phi
)
90 return(cart2complex(c1
.real
+ c2
.real
, c1
.imag
+ c2
.imag
));
97 return(cart2complex(c1
.real
- c2
.real
, c1
.imag
- c2
.imag
));
101 cmul(Complex c1
, Complex c2
)
103 double m1
, m2
, p1
, p2
;
109 return(polar2complex(m1
* m2
, p1
+ p2
));
116 xlfail("division by zero");
121 cdiv(Complex c1
, Complex c2
)
123 double m1
, m2
, p1
, p2
;
130 return(polar2complex(m1
/ m2
, p1
- p2
));