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 z_div(doublecomplex *c, doublecomplex *a, doublecomplex *b)
21
double 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;
46
/* Returns sqrt(z.r^2 + z.i^2) */
47
double z_abs(doublecomplex *z)
53
if (real < 0) real = -real;
54
if (imag < 0) imag = -imag;
60
if ((real+imag) == real) return(real);
63
temp = real*sqrt(1.0 + temp*temp); /*overflow!!*/
68
/* Approximates the abs */
69
/* Returns abs(z.r) + abs(z.i) */
70
double z_abs1(doublecomplex *z)
75
if (real < 0) real = -real;
76
if (imag < 0) imag = -imag;
81
/* Return the exponentiation */
82
void z_exp(doublecomplex *r, doublecomplex *z)
87
r->r = expx * cos(z->i);
88
r->i = expx * sin(z->i);
91
/* Return the complex conjugate */
92
void d_cnjg(doublecomplex *r, doublecomplex *z)
98
/* Return the imaginary part */
99
double d_imag(doublecomplex *z)