00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "f2c.h"
00014 #include "blaswrap.h"
00015
00016 int slag2_(real *a, integer *lda, real *b, integer *ldb,
00017 real *safmin, real *scale1, real *scale2, real *wr1, real *wr2, real *
00018 wi)
00019 {
00020
00021 integer a_dim1, a_offset, b_dim1, b_offset;
00022 real r__1, r__2, r__3, r__4, r__5, r__6;
00023
00024
00025 double sqrt(doublereal), r_sign(real *, real *);
00026
00027
00028 real r__, c1, c2, c3, c4, c5, s1, s2, a11, a12, a21, a22, b11, b12, b22,
00029 pp, qq, ss, as11, as12, as22, sum, abi22, diff, bmin, wbig, wabs,
00030 wdet, binv11, binv22, discr, anorm, bnorm, bsize, shift, rtmin,
00031 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.f / rtmin;
00141 safmax = 1.f / *safmin;
00142
00143
00144
00145
00146 r__5 = (r__1 = a[a_dim1 + 1], dabs(r__1)) + (r__2 = a[a_dim1 + 2], dabs(
00147 r__2)), r__6 = (r__3 = a[(a_dim1 << 1) + 1], dabs(r__3)) + (r__4 =
00148 a[(a_dim1 << 1) + 2], dabs(r__4)), r__5 = max(r__5,r__6);
00149 anorm = dmax(r__5,*safmin);
00150 ascale = 1.f / 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 r__1 = dabs(b11), r__2 = dabs(b12), r__1 = max(r__1,r__2), r__2 = dabs(
00163 b22), r__1 = max(r__1,r__2);
00164 bmin = rtmin * dmax(r__1,rtmin);
00165 if (dabs(b11) < bmin) {
00166 b11 = r_sign(&bmin, &b11);
00167 }
00168 if (dabs(b22) < bmin) {
00169 b22 = r_sign(&bmin, &b22);
00170 }
00171
00172
00173
00174
00175 r__1 = dabs(b11), r__2 = dabs(b12) + dabs(b22), r__1 = max(r__1,r__2);
00176 bnorm = dmax(r__1,*safmin);
00177
00178 r__1 = dabs(b11), r__2 = dabs(b22);
00179 bsize = dmax(r__1,r__2);
00180 bscale = 1.f / bsize;
00181 b11 *= bscale;
00182 b12 *= bscale;
00183 b22 *= bscale;
00184
00185
00186
00187
00188
00189 binv11 = 1.f / b11;
00190 binv22 = 1.f / b22;
00191 s1 = a11 * binv11;
00192 s2 = a22 * binv22;
00193 if (dabs(s1) <= dabs(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 * .5f;
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) * .5f;
00206 shift = s2;
00207 }
00208 qq = ss * as12;
00209 if ((r__1 = pp * rtmin, dabs(r__1)) >= 1.f) {
00210
00211 r__1 = rtmin * pp;
00212 discr = r__1 * r__1 + qq * *safmin;
00213 r__ = sqrt((dabs(discr))) * rtmax;
00214 } else {
00215
00216 r__1 = pp;
00217 if (r__1 * r__1 + dabs(qq) <= *safmin) {
00218
00219 r__1 = rtmax * pp;
00220 discr = r__1 * r__1 + qq * safmax;
00221 r__ = sqrt((dabs(discr))) * rtmin;
00222 } else {
00223
00224 r__1 = pp;
00225 discr = r__1 * r__1 + qq;
00226 r__ = sqrt((dabs(discr)));
00227 }
00228 }
00229
00230
00231
00232
00233
00234
00235
00236 if (discr >= 0.f || r__ == 0.f) {
00237 sum = pp + r_sign(&r__, &pp);
00238 diff = pp - r_sign(&r__, &pp);
00239 wbig = shift + sum;
00240
00241
00242
00243 wsmall = shift + diff;
00244
00245 r__1 = dabs(wsmall);
00246 if (dabs(wbig) * .5f > dmax(r__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 = dmin(wbig,wsmall);
00256 *wr2 = dmax(wbig,wsmall);
00257 } else {
00258 *wr1 = dmax(wbig,wsmall);
00259 *wr2 = dmin(wbig,wsmall);
00260 }
00261 *wi = 0.f;
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 * dmax(1.f,ascale));
00284 c2 = *safmin * dmax(1.f,bnorm);
00285 c3 = bsize * *safmin;
00286 if (ascale <= 1.f && bsize <= 1.f) {
00287
00288 r__1 = 1.f, r__2 = ascale / *safmin * bsize;
00289 c4 = dmin(r__1,r__2);
00290 } else {
00291 c4 = 1.f;
00292 }
00293 if (ascale <= 1.f || bsize <= 1.f) {
00294
00295 r__1 = 1.f, r__2 = ascale * bsize;
00296 c5 = dmin(r__1,r__2);
00297 } else {
00298 c5 = 1.f;
00299 }
00300
00301
00302
00303 wabs = dabs(*wr1) + dabs(*wi);
00304
00305
00306 r__3 = c4, r__4 = dmax(wabs,c5) * .5f;
00307 r__1 = max(*safmin,c1), r__2 = (wabs * c2 + c3) * 1.0000100000000001f,
00308 r__1 = max(r__1,r__2), r__2 = dmin(r__3,r__4);
00309 wsize = dmax(r__1,r__2);
00310 if (wsize != 1.f) {
00311 wscale = 1.f / wsize;
00312 if (wsize > 1.f) {
00313 *scale1 = dmax(ascale,bsize) * wscale * dmin(ascale,bsize);
00314 } else {
00315 *scale1 = dmin(ascale,bsize) * wscale * dmax(ascale,bsize);
00316 }
00317 *wr1 *= wscale;
00318 if (*wi != 0.f) {
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.f) {
00331
00332
00333
00334 r__5 = dabs(*wr2);
00335 r__3 = c4, r__4 = dmax(r__5,c5) * .5f;
00336 r__1 = max(*safmin,c1), r__2 = (dabs(*wr2) * c2 + c3) *
00337 1.0000100000000001f, r__1 = max(r__1,r__2), r__2 = dmin(r__3,
00338 r__4);
00339 wsize = dmax(r__1,r__2);
00340 if (wsize != 1.f) {
00341 wscale = 1.f / wsize;
00342 if (wsize > 1.f) {
00343 *scale2 = dmax(ascale,bsize) * wscale * dmin(ascale,bsize);
00344 } else {
00345 *scale2 = dmin(ascale,bsize) * wscale * dmax(ascale,bsize);
00346 }
00347 *wr2 *= wscale;
00348 } else {
00349 *scale2 = ascale * bsize;
00350 }
00351 }
00352
00353
00354
00355 return 0;
00356 }