1 /* complex - Complex number functions */
2 /* Copyright (c) 1990, by Luke Tierney */
13 if (c
.imag
> 0.0) phi
= PI
/ 2;
14 else if (c
.imag
== 0.0) phi
= 0.0;
18 phi
= atan(c
.imag
/ c
.real
);
20 if (c
.imag
> 0.0) phi
+= PI
;
21 else if (c
.imag
< 0.0) phi
-= PI
;
31 return(sqrt(c
.real
* c
.real
+ c
.imag
* c
.imag
));
34 Complex
cart2complex(real
, imag
)
43 static Complex
polar2complex(mod
, phi
)
53 else if (phi
== PI
/ 2) {
61 else if (phi
== -PI
/ 2) {
77 return(cart2complex(c1
.real
+ c2
.real
, c1
.imag
+ c2
.imag
));
83 return(cart2complex(c1
.real
- c2
.real
, c1
.imag
- c2
.imag
));
89 double m1
, m2
, p1
, p2
;
95 return(polar2complex(m1
* m2
, p1
+ p2
));
101 double m1
, m2
, p1
, p2
;
108 return(polar2complex(m1
/ m2
, p1
- p2
));
114 if (x
== 0.0) xlfail("division by zero");