~ubuntu-branches/ubuntu/lucid/igraph/lucid

« back to all changes in this revision

Viewing changes to src/lapack/dlaln2.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathieu Malaterre
  • Date: 2009-11-16 18:12:42 UTC
  • Revision ID: james.westby@ubuntu.com-20091116181242-mzv9p5fz9uj57xd1
Tags: upstream-0.5.3
ImportĀ upstreamĀ versionĀ 0.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  -- translated by f2c (version 20050501).
 
2
   You must link the resulting object file with libf2c:
 
3
        on Microsoft Windows system, link with libf2c.lib;
 
4
        on Linux or Unix systems, link with .../path/to/libf2c.a -lm
 
5
        or, if you install libf2c.a in a standard place, with -lf2c -lm
 
6
        -- in that order, at the end of the command line, as in
 
7
                cc *.o -lf2c -lm
 
8
        Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
 
9
 
 
10
                http://www.netlib.org/f2c/libf2c.zip
 
11
*/
 
12
 
 
13
#include "config.h"
 
14
#include "arpack_internal.h"
 
15
#include "f2c.h"
 
16
 
 
17
/* Subroutine */ int igraphdlaln2_(logical *ltrans, integer *na, integer *nw, 
 
18
        doublereal *smin, doublereal *ca, doublereal *a, integer *lda, 
 
19
        doublereal *d1, doublereal *d2, doublereal *b, integer *ldb, 
 
20
        doublereal *wr, doublereal *wi, doublereal *x, integer *ldx, 
 
21
        doublereal *scale, doublereal *xnorm, integer *info)
 
22
{
 
23
    /* Initialized data */
 
24
 
 
25
    static logical zswap[4] = { FALSE_,FALSE_,TRUE_,TRUE_ };
 
26
    static logical rswap[4] = { FALSE_,TRUE_,FALSE_,TRUE_ };
 
27
    static integer ipivot[16]   /* was [4][4] */ = { 1,2,3,4,2,1,4,3,3,4,1,2,
 
28
            4,3,2,1 };
 
29
 
 
30
    /* System generated locals */
 
31
    integer a_dim1, a_offset, b_dim1, b_offset, x_dim1, x_offset;
 
32
    doublereal d__1, d__2, d__3, d__4, d__5, d__6;
 
33
    static doublereal equiv_0[4], equiv_1[4];
 
34
 
 
35
    /* Local variables */
 
36
    static integer j;
 
37
#define ci (equiv_0)
 
38
#define cr (equiv_1)
 
39
    static doublereal bi1, bi2, br1, br2, xi1, xi2, xr1, xr2, ci21, ci22, 
 
40
            cr21, cr22, li21, csi, ui11, lr21, ui12, ui22;
 
41
#define civ (equiv_0)
 
42
    static doublereal csr, ur11, ur12, ur22;
 
43
#define crv (equiv_1)
 
44
    static doublereal bbnd, cmax, ui11r, ui12s, temp, ur11r, ur12s, u22abs;
 
45
    static integer icmax;
 
46
    static doublereal bnorm, cnorm, smini;
 
47
    extern doublereal igraphdlamch_(char *);
 
48
    extern /* Subroutine */ int igraphdladiv_(doublereal *, doublereal *, 
 
49
            doublereal *, doublereal *, doublereal *, doublereal *);
 
50
    static doublereal bignum, smlnum;
 
51
 
 
52
 
 
53
/*  -- LAPACK auxiliary routine (version 3.0) -- */
 
54
/*     Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., */
 
55
/*     Courant Institute, Argonne National Lab, and Rice University */
 
56
/*     October 31, 1992 */
 
57
 
 
58
/*     .. Scalar Arguments .. */
 
59
/*     .. */
 
60
/*     .. Array Arguments .. */
 
61
/*     .. */
 
62
 
 
63
/*  Purpose */
 
64
/*  ======= */
 
65
 
 
66
/*  DLALN2 solves a system of the form  (ca A - w D ) X = s B */
 
67
/*  or (ca A' - w D) X = s B   with possible scaling ("s") and */
 
68
/*  perturbation of A.  (A' means A-transpose.) */
 
69
 
 
70
/*  A is an NA x NA real matrix, ca is a real scalar, D is an NA x NA */
 
71
/*  real diagonal matrix, w is a real or complex value, and X and B are */
 
72
/*  NA x 1 matrices -- real if w is real, complex if w is complex.  NA */
 
73
/*  may be 1 or 2. */
 
74
 
 
75
/*  If w is complex, X and B are represented as NA x 2 matrices, */
 
76
/*  the first column of each being the real part and the second */
 
77
/*  being the imaginary part. */
 
78
 
 
79
/*  "s" is a scaling factor (.LE. 1), computed by DLALN2, which is */
 
80
/*  so chosen that X can be computed without overflow.  X is further */
 
81
/*  scaled if necessary to assure that norm(ca A - w D)*norm(X) is less */
 
82
/*  than overflow. */
 
83
 
 
84
/*  If both singular values of (ca A - w D) are less than SMIN, */
 
85
/*  SMIN*identity will be used instead of (ca A - w D).  If only one */
 
86
/*  singular value is less than SMIN, one element of (ca A - w D) will be */
 
87
/*  perturbed enough to make the smallest singular value roughly SMIN. */
 
88
/*  If both singular values are at least SMIN, (ca A - w D) will not be */
 
89
/*  perturbed.  In any case, the perturbation will be at most some small */
 
90
/*  multiple of max( SMIN, ulp*norm(ca A - w D) ).  The singular values */
 
91
/*  are computed by infinity-norm approximations, and thus will only be */
 
92
/*  correct to a factor of 2 or so. */
 
93
 
 
94
/*  Note: all input quantities are assumed to be smaller than overflow */
 
95
/*  by a reasonable factor.  (See BIGNUM.) */
 
96
 
 
97
/*  Arguments */
 
98
/*  ========== */
 
99
 
 
100
/*  LTRANS  (input) LOGICAL */
 
101
/*          =.TRUE.:  A-transpose will be used. */
 
102
/*          =.FALSE.: A will be used (not transposed.) */
 
103
 
 
104
/*  NA      (input) INTEGER */
 
105
/*          The size of the matrix A.  It may (only) be 1 or 2. */
 
106
 
 
107
/*  NW      (input) INTEGER */
 
108
/*          1 if "w" is real, 2 if "w" is complex.  It may only be 1 */
 
109
/*          or 2. */
 
110
 
 
111
/*  SMIN    (input) DOUBLE PRECISION */
 
112
/*          The desired lower bound on the singular values of A.  This */
 
113
/*          should be a safe distance away from underflow or overflow, */
 
114
/*          say, between (underflow/machine precision) and  (machine */
 
115
/*          precision * overflow ).  (See BIGNUM and ULP.) */
 
116
 
 
117
/*  CA      (input) DOUBLE PRECISION */
 
118
/*          The coefficient c, which A is multiplied by. */
 
119
 
 
120
/*  A       (input) DOUBLE PRECISION array, dimension (LDA,NA) */
 
121
/*          The NA x NA matrix A. */
 
122
 
 
123
/*  LDA     (input) INTEGER */
 
124
/*          The leading dimension of A.  It must be at least NA. */
 
125
 
 
126
/*  D1      (input) DOUBLE PRECISION */
 
127
/*          The 1,1 element in the diagonal matrix D. */
 
128
 
 
129
/*  D2      (input) DOUBLE PRECISION */
 
130
/*          The 2,2 element in the diagonal matrix D.  Not used if NW=1. */
 
131
 
 
132
/*  B       (input) DOUBLE PRECISION array, dimension (LDB,NW) */
 
133
/*          The NA x NW matrix B (right-hand side).  If NW=2 ("w" is */
 
134
/*          complex), column 1 contains the real part of B and column 2 */
 
135
/*          contains the imaginary part. */
 
136
 
 
137
/*  LDB     (input) INTEGER */
 
138
/*          The leading dimension of B.  It must be at least NA. */
 
139
 
 
140
/*  WR      (input) DOUBLE PRECISION */
 
141
/*          The real part of the scalar "w". */
 
142
 
 
143
/*  WI      (input) DOUBLE PRECISION */
 
144
/*          The imaginary part of the scalar "w".  Not used if NW=1. */
 
145
 
 
146
/*  X       (output) DOUBLE PRECISION array, dimension (LDX,NW) */
 
147
/*          The NA x NW matrix X (unknowns), as computed by DLALN2. */
 
148
/*          If NW=2 ("w" is complex), on exit, column 1 will contain */
 
149
/*          the real part of X and column 2 will contain the imaginary */
 
150
/*          part. */
 
151
 
 
152
/*  LDX     (input) INTEGER */
 
153
/*          The leading dimension of X.  It must be at least NA. */
 
154
 
 
155
/*  SCALE   (output) DOUBLE PRECISION */
 
156
/*          The scale factor that B must be multiplied by to insure */
 
157
/*          that overflow does not occur when computing X.  Thus, */
 
158
/*          (ca A - w D) X  will be SCALE*B, not B (ignoring */
 
159
/*          perturbations of A.)  It will be at most 1. */
 
160
 
 
161
/*  XNORM   (output) DOUBLE PRECISION */
 
162
/*          The infinity-norm of X, when X is regarded as an NA x NW */
 
163
/*          real matrix. */
 
164
 
 
165
/*  INFO    (output) INTEGER */
 
166
/*          An error flag.  It will be set to zero if no error occurs, */
 
167
/*          a negative number if an argument is in error, or a positive */
 
168
/*          number if  ca A - w D  had to be perturbed. */
 
169
/*          The possible values are: */
 
170
/*          = 0: No error occurred, and (ca A - w D) did not have to be */
 
171
/*                 perturbed. */
 
172
/*          = 1: (ca A - w D) had to be perturbed to make its smallest */
 
173
/*               (or only) singular value greater than SMIN. */
 
174
/*          NOTE: In the interests of speed, this routine does not */
 
175
/*                check the inputs for errors. */
 
176
 
 
177
/* ===================================================================== */
 
178
 
 
179
/*     .. Parameters .. */
 
180
/*     .. */
 
181
/*     .. Local Scalars .. */
 
182
/*     .. */
 
183
/*     .. Local Arrays .. */
 
184
/*     .. */
 
185
/*     .. External Functions .. */
 
186
/*     .. */
 
187
/*     .. External Subroutines .. */
 
188
/*     .. */
 
189
/*     .. Intrinsic Functions .. */
 
190
/*     .. */
 
191
/*     .. Equivalences .. */
 
192
/*     .. */
 
193
/*     .. Data statements .. */
 
194
    /* Parameter adjustments */
 
195
    a_dim1 = *lda;
 
196
    a_offset = 1 + a_dim1;
 
197
    a -= a_offset;
 
198
    b_dim1 = *ldb;
 
199
    b_offset = 1 + b_dim1;
 
200
    b -= b_offset;
 
201
    x_dim1 = *ldx;
 
202
    x_offset = 1 + x_dim1;
 
203
    x -= x_offset;
 
204
 
 
205
    /* Function Body */
 
206
/*     .. */
 
207
/*     .. Executable Statements .. */
 
208
 
 
209
/*     Compute BIGNUM */
 
210
 
 
211
    smlnum = 2. * igraphdlamch_("Safe minimum");
 
212
    bignum = 1. / smlnum;
 
213
    smini = max(*smin,smlnum);
 
214
 
 
215
/*     Don't check for input errors */
 
216
 
 
217
    *info = 0;
 
218
 
 
219
/*     Standard Initializations */
 
220
 
 
221
    *scale = 1.;
 
222
 
 
223
    if (*na == 1) {
 
224
 
 
225
/*        1 x 1  (i.e., scalar) system   C X = B */
 
226
 
 
227
        if (*nw == 1) {
 
228
 
 
229
/*           Real 1x1 system. */
 
230
 
 
231
/*           C = ca A - w D */
 
232
 
 
233
            csr = *ca * a[a_dim1 + 1] - *wr * *d1;
 
234
            cnorm = abs(csr);
 
235
 
 
236
/*           If | C | < SMINI, use C = SMINI */
 
237
 
 
238
            if (cnorm < smini) {
 
239
                csr = smini;
 
240
                cnorm = smini;
 
241
                *info = 1;
 
242
            }
 
243
 
 
244
/*           Check scaling for  X = B / C */
 
245
 
 
246
            bnorm = (d__1 = b[b_dim1 + 1], abs(d__1));
 
247
            if (cnorm < 1. && bnorm > 1.) {
 
248
                if (bnorm > bignum * cnorm) {
 
249
                    *scale = 1. / bnorm;
 
250
                }
 
251
            }
 
252
 
 
253
/*           Compute X */
 
254
 
 
255
            x[x_dim1 + 1] = b[b_dim1 + 1] * *scale / csr;
 
256
            *xnorm = (d__1 = x[x_dim1 + 1], abs(d__1));
 
257
        } else {
 
258
 
 
259
/*           Complex 1x1 system (w is complex) */
 
260
 
 
261
/*           C = ca A - w D */
 
262
 
 
263
            csr = *ca * a[a_dim1 + 1] - *wr * *d1;
 
264
            csi = -(*wi) * *d1;
 
265
            cnorm = abs(csr) + abs(csi);
 
266
 
 
267
/*           If | C | < SMINI, use C = SMINI */
 
268
 
 
269
            if (cnorm < smini) {
 
270
                csr = smini;
 
271
                csi = 0.;
 
272
                cnorm = smini;
 
273
                *info = 1;
 
274
            }
 
275
 
 
276
/*           Check scaling for  X = B / C */
 
277
 
 
278
            bnorm = (d__1 = b[b_dim1 + 1], abs(d__1)) + (d__2 = b[(b_dim1 << 
 
279
                    1) + 1], abs(d__2));
 
280
            if (cnorm < 1. && bnorm > 1.) {
 
281
                if (bnorm > bignum * cnorm) {
 
282
                    *scale = 1. / bnorm;
 
283
                }
 
284
            }
 
285
 
 
286
/*           Compute X */
 
287
 
 
288
            d__1 = *scale * b[b_dim1 + 1];
 
289
            d__2 = *scale * b[(b_dim1 << 1) + 1];
 
290
            igraphdladiv_(&d__1, &d__2, &csr, &csi, &x[x_dim1 + 1], &x[(x_dim1 << 1)
 
291
                     + 1]);
 
292
            *xnorm = (d__1 = x[x_dim1 + 1], abs(d__1)) + (d__2 = x[(x_dim1 << 
 
293
                    1) + 1], abs(d__2));
 
294
        }
 
295
 
 
296
    } else {
 
297
 
 
298
/*        2x2 System */
 
299
 
 
300
/*        Compute the real part of  C = ca A - w D  (or  ca A' - w D ) */
 
301
 
 
302
        cr[0] = *ca * a[a_dim1 + 1] - *wr * *d1;
 
303
        cr[3] = *ca * a[(a_dim1 << 1) + 2] - *wr * *d2;
 
304
        if (*ltrans) {
 
305
            cr[2] = *ca * a[a_dim1 + 2];
 
306
            cr[1] = *ca * a[(a_dim1 << 1) + 1];
 
307
        } else {
 
308
            cr[1] = *ca * a[a_dim1 + 2];
 
309
            cr[2] = *ca * a[(a_dim1 << 1) + 1];
 
310
        }
 
311
 
 
312
        if (*nw == 1) {
 
313
 
 
314
/*           Real 2x2 system  (w is real) */
 
315
 
 
316
/*           Find the largest element in C */
 
317
 
 
318
            cmax = 0.;
 
319
            icmax = 0;
 
320
 
 
321
            for (j = 1; j <= 4; ++j) {
 
322
                if ((d__1 = crv[j - 1], abs(d__1)) > cmax) {
 
323
                    cmax = (d__1 = crv[j - 1], abs(d__1));
 
324
                    icmax = j;
 
325
                }
 
326
/* L10: */
 
327
            }
 
328
 
 
329
/*           If norm(C) < SMINI, use SMINI*identity. */
 
330
 
 
331
            if (cmax < smini) {
 
332
/* Computing MAX */
 
333
                d__3 = (d__1 = b[b_dim1 + 1], abs(d__1)), d__4 = (d__2 = b[
 
334
                        b_dim1 + 2], abs(d__2));
 
335
                bnorm = max(d__3,d__4);
 
336
                if (smini < 1. && bnorm > 1.) {
 
337
                    if (bnorm > bignum * smini) {
 
338
                        *scale = 1. / bnorm;
 
339
                    }
 
340
                }
 
341
                temp = *scale / smini;
 
342
                x[x_dim1 + 1] = temp * b[b_dim1 + 1];
 
343
                x[x_dim1 + 2] = temp * b[b_dim1 + 2];
 
344
                *xnorm = temp * bnorm;
 
345
                *info = 1;
 
346
                return 0;
 
347
            }
 
348
 
 
349
/*           Gaussian elimination with complete pivoting. */
 
350
 
 
351
            ur11 = crv[icmax - 1];
 
352
            cr21 = crv[ipivot[(icmax << 2) - 3] - 1];
 
353
            ur12 = crv[ipivot[(icmax << 2) - 2] - 1];
 
354
            cr22 = crv[ipivot[(icmax << 2) - 1] - 1];
 
355
            ur11r = 1. / ur11;
 
356
            lr21 = ur11r * cr21;
 
357
            ur22 = cr22 - ur12 * lr21;
 
358
 
 
359
/*           If smaller pivot < SMINI, use SMINI */
 
360
 
 
361
            if (abs(ur22) < smini) {
 
362
                ur22 = smini;
 
363
                *info = 1;
 
364
            }
 
365
            if (rswap[icmax - 1]) {
 
366
                br1 = b[b_dim1 + 2];
 
367
                br2 = b[b_dim1 + 1];
 
368
            } else {
 
369
                br1 = b[b_dim1 + 1];
 
370
                br2 = b[b_dim1 + 2];
 
371
            }
 
372
            br2 -= lr21 * br1;
 
373
/* Computing MAX */
 
374
            d__2 = (d__1 = br1 * (ur22 * ur11r), abs(d__1)), d__3 = abs(br2);
 
375
            bbnd = max(d__2,d__3);
 
376
            if (bbnd > 1. && abs(ur22) < 1.) {
 
377
                if (bbnd >= bignum * abs(ur22)) {
 
378
                    *scale = 1. / bbnd;
 
379
                }
 
380
            }
 
381
 
 
382
            xr2 = br2 * *scale / ur22;
 
383
            xr1 = *scale * br1 * ur11r - xr2 * (ur11r * ur12);
 
384
            if (zswap[icmax - 1]) {
 
385
                x[x_dim1 + 1] = xr2;
 
386
                x[x_dim1 + 2] = xr1;
 
387
            } else {
 
388
                x[x_dim1 + 1] = xr1;
 
389
                x[x_dim1 + 2] = xr2;
 
390
            }
 
391
/* Computing MAX */
 
392
            d__1 = abs(xr1), d__2 = abs(xr2);
 
393
            *xnorm = max(d__1,d__2);
 
394
 
 
395
/*           Further scaling if  norm(A) norm(X) > overflow */
 
396
 
 
397
            if (*xnorm > 1. && cmax > 1.) {
 
398
                if (*xnorm > bignum / cmax) {
 
399
                    temp = cmax / bignum;
 
400
                    x[x_dim1 + 1] = temp * x[x_dim1 + 1];
 
401
                    x[x_dim1 + 2] = temp * x[x_dim1 + 2];
 
402
                    *xnorm = temp * *xnorm;
 
403
                    *scale = temp * *scale;
 
404
                }
 
405
            }
 
406
        } else {
 
407
 
 
408
/*           Complex 2x2 system  (w is complex) */
 
409
 
 
410
/*           Find the largest element in C */
 
411
 
 
412
            ci[0] = -(*wi) * *d1;
 
413
            ci[1] = 0.;
 
414
            ci[2] = 0.;
 
415
            ci[3] = -(*wi) * *d2;
 
416
            cmax = 0.;
 
417
            icmax = 0;
 
418
 
 
419
            for (j = 1; j <= 4; ++j) {
 
420
                if ((d__1 = crv[j - 1], abs(d__1)) + (d__2 = civ[j - 1], abs(
 
421
                        d__2)) > cmax) {
 
422
                    cmax = (d__1 = crv[j - 1], abs(d__1)) + (d__2 = civ[j - 1]
 
423
                            , abs(d__2));
 
424
                    icmax = j;
 
425
                }
 
426
/* L20: */
 
427
            }
 
428
 
 
429
/*           If norm(C) < SMINI, use SMINI*identity. */
 
430
 
 
431
            if (cmax < smini) {
 
432
/* Computing MAX */
 
433
                d__5 = (d__1 = b[b_dim1 + 1], abs(d__1)) + (d__2 = b[(b_dim1 
 
434
                        << 1) + 1], abs(d__2)), d__6 = (d__3 = b[b_dim1 + 2], 
 
435
                        abs(d__3)) + (d__4 = b[(b_dim1 << 1) + 2], abs(d__4));
 
436
                bnorm = max(d__5,d__6);
 
437
                if (smini < 1. && bnorm > 1.) {
 
438
                    if (bnorm > bignum * smini) {
 
439
                        *scale = 1. / bnorm;
 
440
                    }
 
441
                }
 
442
                temp = *scale / smini;
 
443
                x[x_dim1 + 1] = temp * b[b_dim1 + 1];
 
444
                x[x_dim1 + 2] = temp * b[b_dim1 + 2];
 
445
                x[(x_dim1 << 1) + 1] = temp * b[(b_dim1 << 1) + 1];
 
446
                x[(x_dim1 << 1) + 2] = temp * b[(b_dim1 << 1) + 2];
 
447
                *xnorm = temp * bnorm;
 
448
                *info = 1;
 
449
                return 0;
 
450
            }
 
451
 
 
452
/*           Gaussian elimination with complete pivoting. */
 
453
 
 
454
            ur11 = crv[icmax - 1];
 
455
            ui11 = civ[icmax - 1];
 
456
            cr21 = crv[ipivot[(icmax << 2) - 3] - 1];
 
457
            ci21 = civ[ipivot[(icmax << 2) - 3] - 1];
 
458
            ur12 = crv[ipivot[(icmax << 2) - 2] - 1];
 
459
            ui12 = civ[ipivot[(icmax << 2) - 2] - 1];
 
460
            cr22 = crv[ipivot[(icmax << 2) - 1] - 1];
 
461
            ci22 = civ[ipivot[(icmax << 2) - 1] - 1];
 
462
            if (icmax == 1 || icmax == 4) {
 
463
 
 
464
/*              Code when off-diagonals of pivoted C are real */
 
465
 
 
466
                if (abs(ur11) > abs(ui11)) {
 
467
                    temp = ui11 / ur11;
 
468
/* Computing 2nd power */
 
469
                    d__1 = temp;
 
470
                    ur11r = 1. / (ur11 * (d__1 * d__1 + 1.));
 
471
                    ui11r = -temp * ur11r;
 
472
                } else {
 
473
                    temp = ur11 / ui11;
 
474
/* Computing 2nd power */
 
475
                    d__1 = temp;
 
476
                    ui11r = -1. / (ui11 * (d__1 * d__1 + 1.));
 
477
                    ur11r = -temp * ui11r;
 
478
                }
 
479
                lr21 = cr21 * ur11r;
 
480
                li21 = cr21 * ui11r;
 
481
                ur12s = ur12 * ur11r;
 
482
                ui12s = ur12 * ui11r;
 
483
                ur22 = cr22 - ur12 * lr21;
 
484
                ui22 = ci22 - ur12 * li21;
 
485
            } else {
 
486
 
 
487
/*              Code when diagonals of pivoted C are real */
 
488
 
 
489
                ur11r = 1. / ur11;
 
490
                ui11r = 0.;
 
491
                lr21 = cr21 * ur11r;
 
492
                li21 = ci21 * ur11r;
 
493
                ur12s = ur12 * ur11r;
 
494
                ui12s = ui12 * ur11r;
 
495
                ur22 = cr22 - ur12 * lr21 + ui12 * li21;
 
496
                ui22 = -ur12 * li21 - ui12 * lr21;
 
497
            }
 
498
            u22abs = abs(ur22) + abs(ui22);
 
499
 
 
500
/*           If smaller pivot < SMINI, use SMINI */
 
501
 
 
502
            if (u22abs < smini) {
 
503
                ur22 = smini;
 
504
                ui22 = 0.;
 
505
                *info = 1;
 
506
            }
 
507
            if (rswap[icmax - 1]) {
 
508
                br2 = b[b_dim1 + 1];
 
509
                br1 = b[b_dim1 + 2];
 
510
                bi2 = b[(b_dim1 << 1) + 1];
 
511
                bi1 = b[(b_dim1 << 1) + 2];
 
512
            } else {
 
513
                br1 = b[b_dim1 + 1];
 
514
                br2 = b[b_dim1 + 2];
 
515
                bi1 = b[(b_dim1 << 1) + 1];
 
516
                bi2 = b[(b_dim1 << 1) + 2];
 
517
            }
 
518
            br2 = br2 - lr21 * br1 + li21 * bi1;
 
519
            bi2 = bi2 - li21 * br1 - lr21 * bi1;
 
520
/* Computing MAX */
 
521
            d__1 = (abs(br1) + abs(bi1)) * (u22abs * (abs(ur11r) + abs(ui11r))
 
522
                    ), d__2 = abs(br2) + abs(bi2);
 
523
            bbnd = max(d__1,d__2);
 
524
            if (bbnd > 1. && u22abs < 1.) {
 
525
                if (bbnd >= bignum * u22abs) {
 
526
                    *scale = 1. / bbnd;
 
527
                    br1 = *scale * br1;
 
528
                    bi1 = *scale * bi1;
 
529
                    br2 = *scale * br2;
 
530
                    bi2 = *scale * bi2;
 
531
                }
 
532
            }
 
533
 
 
534
            igraphdladiv_(&br2, &bi2, &ur22, &ui22, &xr2, &xi2);
 
535
            xr1 = ur11r * br1 - ui11r * bi1 - ur12s * xr2 + ui12s * xi2;
 
536
            xi1 = ui11r * br1 + ur11r * bi1 - ui12s * xr2 - ur12s * xi2;
 
537
            if (zswap[icmax - 1]) {
 
538
                x[x_dim1 + 1] = xr2;
 
539
                x[x_dim1 + 2] = xr1;
 
540
                x[(x_dim1 << 1) + 1] = xi2;
 
541
                x[(x_dim1 << 1) + 2] = xi1;
 
542
            } else {
 
543
                x[x_dim1 + 1] = xr1;
 
544
                x[x_dim1 + 2] = xr2;
 
545
                x[(x_dim1 << 1) + 1] = xi1;
 
546
                x[(x_dim1 << 1) + 2] = xi2;
 
547
            }
 
548
/* Computing MAX */
 
549
            d__1 = abs(xr1) + abs(xi1), d__2 = abs(xr2) + abs(xi2);
 
550
            *xnorm = max(d__1,d__2);
 
551
 
 
552
/*           Further scaling if  norm(A) norm(X) > overflow */
 
553
 
 
554
            if (*xnorm > 1. && cmax > 1.) {
 
555
                if (*xnorm > bignum / cmax) {
 
556
                    temp = cmax / bignum;
 
557
                    x[x_dim1 + 1] = temp * x[x_dim1 + 1];
 
558
                    x[x_dim1 + 2] = temp * x[x_dim1 + 2];
 
559
                    x[(x_dim1 << 1) + 1] = temp * x[(x_dim1 << 1) + 1];
 
560
                    x[(x_dim1 << 1) + 2] = temp * x[(x_dim1 << 1) + 2];
 
561
                    *xnorm = temp * *xnorm;
 
562
                    *scale = temp * *scale;
 
563
                }
 
564
            }
 
565
        }
 
566
    }
 
567
 
 
568
    return 0;
 
569
 
 
570
/*     End of DLALN2 */
 
571
 
 
572
} /* igraphdlaln2_ */
 
573
 
 
574
#undef crv
 
575
#undef civ
 
576
#undef cr
 
577
#undef ci
 
578
 
 
579