00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016 int dlag2_(doublereal *a, integer *lda, doublereal *b,
00017 integer *ldb, doublereal *safmin, doublereal *scale1, doublereal *
00018 scale2, doublereal *wr1, doublereal *wr2, doublereal *wi)
00019 {
00020
00021 integer a_dim1, a_offset, b_dim1, b_offset;
00022 doublereal d__1, d__2, d__3, d__4, d__5, d__6;
00023
00024
00025 double sqrt(doublereal), d_sign(doublereal *, doublereal *);
00026
00027
00028 doublereal r__, c1, c2, c3, c4, c5, s1, s2, a11, a12, a21, a22, b11, b12,
00029 b22, pp, qq, ss, as11, as12, as22, sum, abi22, diff, bmin, wbig,
00030 wabs, wdet, binv11, binv22, discr, anorm, bnorm, bsize, shift,
00031 rtmin, rtmax, wsize, ascale, bscale, wscale, safmax, wsmall;
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 a_dim1 = *lda;
00132 a_offset = 1 + a_dim1;
00133 a -= a_offset;
00134 b_dim1 = *ldb;
00135 b_offset = 1 + b_dim1;
00136 b -= b_offset;
00137
00138
00139 rtmin = sqrt(*safmin);
00140 rtmax = 1. / rtmin;
00141 safmax = 1. / *safmin;
00142
00143
00144
00145
00146 d__5 = (d__1 = a[a_dim1 + 1], abs(d__1)) + (d__2 = a[a_dim1 + 2], abs(
00147 d__2)), d__6 = (d__3 = a[(a_dim1 << 1) + 1], abs(d__3)) + (d__4 =
00148 a[(a_dim1 << 1) + 2], abs(d__4)), d__5 = max(d__5,d__6);
00149 anorm = max(d__5,*safmin);
00150 ascale = 1. / anorm;
00151 a11 = ascale * a[a_dim1 + 1];
00152 a21 = ascale * a[a_dim1 + 2];
00153 a12 = ascale * a[(a_dim1 << 1) + 1];
00154 a22 = ascale * a[(a_dim1 << 1) + 2];
00155
00156
00157
00158 b11 = b[b_dim1 + 1];
00159 b12 = b[(b_dim1 << 1) + 1];
00160 b22 = b[(b_dim1 << 1) + 2];
00161
00162 d__1 = abs(b11), d__2 = abs(b12), d__1 = max(d__1,d__2), d__2 = abs(b22),
00163 d__1 = max(d__1,d__2);
00164 bmin = rtmin * max(d__1,rtmin);
00165 if (abs(b11) < bmin) {
00166 b11 = d_sign(&bmin, &b11);
00167 }
00168 if (abs(b22) < bmin) {
00169 b22 = d_sign(&bmin, &b22);
00170 }
00171
00172
00173
00174
00175 d__1 = abs(b11), d__2 = abs(b12) + abs(b22), d__1 = max(d__1,d__2);
00176 bnorm = max(d__1,*safmin);
00177
00178 d__1 = abs(b11), d__2 = abs(b22);
00179 bsize = max(d__1,d__2);
00180 bscale = 1. / bsize;
00181 b11 *= bscale;
00182 b12 *= bscale;
00183 b22 *= bscale;
00184
00185
00186
00187
00188
00189 binv11 = 1. / b11;
00190 binv22 = 1. / b22;
00191 s1 = a11 * binv11;
00192 s2 = a22 * binv22;
00193 if (abs(s1) <= abs(s2)) {
00194 as12 = a12 - s1 * b12;
00195 as22 = a22 - s1 * b22;
00196 ss = a21 * (binv11 * binv22);
00197 abi22 = as22 * binv22 - ss * b12;
00198 pp = abi22 * .5;
00199 shift = s1;
00200 } else {
00201 as12 = a12 - s2 * b12;
00202 as11 = a11 - s2 * b11;
00203 ss = a21 * (binv11 * binv22);
00204 abi22 = -ss * b12;
00205 pp = (as11 * binv11 + abi22) * .5;
00206 shift = s2;
00207 }
00208 qq = ss * as12;
00209 if ((d__1 = pp * rtmin, abs(d__1)) >= 1.) {
00210
00211 d__1 = rtmin * pp;
00212 discr = d__1 * d__1 + qq * *safmin;
00213 r__ = sqrt((abs(discr))) * rtmax;
00214 } else {
00215
00216 d__1 = pp;
00217 if (d__1 * d__1 + abs(qq) <= *safmin) {
00218
00219 d__1 = rtmax * pp;
00220 discr = d__1 * d__1 + qq * safmax;
00221 r__ = sqrt((abs(discr))) * rtmin;
00222 } else {
00223
00224 d__1 = pp;
00225 discr = d__1 * d__1 + qq;
00226 r__ = sqrt((abs(discr)));
00227 }
00228 }
00229
00230
00231
00232
00233
00234
00235
00236 if (discr >= 0. || r__ == 0.) {
00237 sum = pp + d_sign(&r__, &pp);
00238 diff = pp - d_sign(&r__, &pp);
00239 wbig = shift + sum;
00240
00241
00242
00243 wsmall = shift + diff;
00244
00245 d__1 = abs(wsmall);
00246 if (abs(wbig) * .5 > max(d__1,*safmin)) {
00247 wdet = (a11 * a22 - a12 * a21) * (binv11 * binv22);
00248 wsmall = wdet / wbig;
00249 }
00250
00251
00252
00253
00254 if (pp > abi22) {
00255 *wr1 = min(wbig,wsmall);
00256 *wr2 = max(wbig,wsmall);
00257 } else {
00258 *wr1 = max(wbig,wsmall);
00259 *wr2 = min(wbig,wsmall);
00260 }
00261 *wi = 0.;
00262 } else {
00263
00264
00265
00266 *wr1 = shift + pp;
00267 *wr2 = *wr1;
00268 *wi = r__;
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283 c1 = bsize * (*safmin * max(1.,ascale));
00284 c2 = *safmin * max(1.,bnorm);
00285 c3 = bsize * *safmin;
00286 if (ascale <= 1. && bsize <= 1.) {
00287
00288 d__1 = 1., d__2 = ascale / *safmin * bsize;
00289 c4 = min(d__1,d__2);
00290 } else {
00291 c4 = 1.;
00292 }
00293 if (ascale <= 1. || bsize <= 1.) {
00294
00295 d__1 = 1., d__2 = ascale * bsize;
00296 c5 = min(d__1,d__2);
00297 } else {
00298 c5 = 1.;
00299 }
00300
00301
00302
00303 wabs = abs(*wr1) + abs(*wi);
00304
00305
00306 d__3 = c4, d__4 = max(wabs,c5) * .5;
00307 d__1 = max(*safmin,c1), d__2 = (wabs * c2 + c3) * 1.0000100000000001,
00308 d__1 = max(d__1,d__2), d__2 = min(d__3,d__4);
00309 wsize = max(d__1,d__2);
00310 if (wsize != 1.) {
00311 wscale = 1. / wsize;
00312 if (wsize > 1.) {
00313 *scale1 = max(ascale,bsize) * wscale * min(ascale,bsize);
00314 } else {
00315 *scale1 = min(ascale,bsize) * wscale * max(ascale,bsize);
00316 }
00317 *wr1 *= wscale;
00318 if (*wi != 0.) {
00319 *wi *= wscale;
00320 *wr2 = *wr1;
00321 *scale2 = *scale1;
00322 }
00323 } else {
00324 *scale1 = ascale * bsize;
00325 *scale2 = *scale1;
00326 }
00327
00328
00329
00330 if (*wi == 0.) {
00331
00332
00333
00334 d__5 = abs(*wr2);
00335 d__3 = c4, d__4 = max(d__5,c5) * .5;
00336 d__1 = max(*safmin,c1), d__2 = (abs(*wr2) * c2 + c3) *
00337 1.0000100000000001, d__1 = max(d__1,d__2), d__2 = min(d__3,
00338 d__4);
00339 wsize = max(d__1,d__2);
00340 if (wsize != 1.) {
00341 wscale = 1. / wsize;
00342 if (wsize > 1.) {
00343 *scale2 = max(ascale,bsize) * wscale * min(ascale,bsize);
00344 } else {
00345 *scale2 = min(ascale,bsize) * wscale * max(ascale,bsize);
00346 }
00347 *wr2 *= wscale;
00348 } else {
00349 *scale2 = ascale * bsize;
00350 }
00351 }
00352
00353
00354
00355 return 0;
00356 }