3
* -- SuperLU routine (version 2.0) --
4
* Univ. of California Berkeley, Xerox Palo Alto Research Center,
5
* and Lawrence Berkeley National Lab.
10
* This file defines common arithmetic operations for complex type.
17
/* Complex Division c = a/b */
18
void c_div(complex *c, complex *a, complex *b)
21
float abr, abi, cr, ci;
23
if( (abr = b->r) < 0.)
25
if( (abi = b->i) < 0.)
29
fprintf(stderr, "z_div.c: division by zero");
33
den = b->i * (1 + ratio*ratio);
34
cr = (a->r*ratio + a->i) / den;
35
ci = (a->i*ratio - a->r) / den;
38
den = b->r * (1 + ratio*ratio);
39
cr = (a->r + a->i*ratio) / den;
40
ci = (a->i - a->r*ratio) / den;
47
/* Returns sqrt(z.r^2 + z.i^2) */
48
double c_abs(complex *z)
54
if (real < 0) real = -real;
55
if (imag < 0) imag = -imag;
61
if ((real+imag) == real) return(real);
64
temp = real*sqrt(1.0 + temp*temp); /*overflow!!*/
69
/* Approximates the abs */
70
/* Returns abs(z.r) + abs(z.i) */
71
double c_abs1(complex *z)
76
if (real < 0) real = -real;
77
if (imag < 0) imag = -imag;
82
/* Return the exponentiation */
83
void c_exp(complex *r, complex *z)
88
r->r = expx * cos(z->i);
89
r->i = expx * sin(z->i);
92
/* Return the complex conjugate */
93
void r_cnjg(complex *r, complex *z)
99
/* Return the imaginary part */
100
double r_imag(complex *z)