152 SUBROUTINE dlag2( A, LDA, B, LDB, SAFMIN, SCALE1, SCALE2, WR1,
161 DOUBLE PRECISION SAFMIN, SCALE1, SCALE2, WI, WR1, WR2
164 DOUBLE PRECISION A( LDA, * ), B( LDB, * )
170 DOUBLE PRECISION ZERO, ONE, TWO
171 parameter( zero = 0.0d+0, one = 1.0d+0, two = 2.0d+0 )
172 DOUBLE PRECISION HALF
173 parameter( half = one / two )
174 DOUBLE PRECISION FUZZY1
175 parameter( fuzzy1 = one+1.0d-5 )
178 DOUBLE PRECISION A11, A12, A21, A22, ABI22, ANORM, AS11, AS12,
179 $ as22, ascale, b11, b12, b22, binv11, binv22,
180 $ bmin, bnorm, bscale, bsize, c1, c2, c3, c4, c5,
181 $ diff, discr, pp, qq, r, rtmax, rtmin, s1, s2,
182 $ safmax, shift, ss, sum, wabs, wbig, wdet,
183 $ wscale, wsize, wsmall
186 INTRINSIC abs, max, min, sign, sqrt
190 rtmin = sqrt( safmin )
192 safmax = one / safmin
196 anorm = max( abs( a( 1, 1 ) )+abs( a( 2, 1 ) ),
197 $ abs( a( 1, 2 ) )+abs( a( 2, 2 ) ), safmin )
199 a11 = ascale*a( 1, 1 )
200 a21 = ascale*a( 2, 1 )
201 a12 = ascale*a( 1, 2 )
202 a22 = ascale*a( 2, 2 )
209 bmin = rtmin*max( abs( b11 ), abs( b12 ), abs( b22 ), rtmin )
210 IF( abs( b11 ).LT.bmin )
211 $ b11 = sign( bmin, b11 )
212 IF( abs( b22 ).LT.bmin )
213 $ b22 = sign( bmin, b22 )
217 bnorm = max( abs( b11 ), abs( b12 )+abs( b22 ), safmin )
218 bsize = max( abs( b11 ), abs( b22 ) )
232 IF( abs( s1 ).LE.abs( s2 ) )
THEN
235 ss = a21*( binv11*binv22 )
236 abi22 = as22*binv22 - ss*b12
242 ss = a21*( binv11*binv22 )
244 pp = half*( as11*binv11+abi22 )
248 IF( abs( pp*rtmin ).GE.one )
THEN
249 discr = ( rtmin*pp )**2 + qq*safmin
250 r = sqrt( abs( discr ) )*rtmax
252 IF( pp**2+abs( qq ).LE.safmin )
THEN
253 discr = ( rtmax*pp )**2 + qq*safmax
254 r = sqrt( abs( discr ) )*rtmin
257 r = sqrt( abs( discr ) )
267 IF( discr.GE.zero .OR. r.EQ.zero )
THEN
268 sum = pp + sign( r, pp )
269 diff = pp - sign( r, pp )
274 wsmall = shift + diff
275 IF( half*abs( wbig ).GT.max( abs( wsmall ), safmin ) )
THEN
276 wdet = ( a11*a22-a12*a21 )*( binv11*binv22 )
283 IF( pp.GT.abi22 )
THEN
284 wr1 = min( wbig, wsmall )
285 wr2 = max( wbig, wsmall )
287 wr1 = max( wbig, wsmall )
288 wr2 = min( wbig, wsmall )
312 c1 = bsize*( safmin*max( one, ascale ) )
313 c2 = safmin*max( one, bnorm )
315 IF( ascale.LE.one .AND. bsize.LE.one )
THEN
316 c4 = min( one, ( ascale / safmin )*bsize )
320 IF( ascale.LE.one .OR. bsize.LE.one )
THEN
321 c5 = min( one, ascale*bsize )
328 wabs = abs( wr1 ) + abs( wi )
329 wsize = max( safmin, c1, fuzzy1*( wabs*c2+c3 ),
330 $ min( c4, half*max( wabs, c5 ) ) )
331 IF( wsize.NE.one )
THEN
333 IF( wsize.GT.one )
THEN
334 scale1 = ( max( ascale, bsize )*wscale )*
335 $ min( ascale, bsize )
337 scale1 = ( min( ascale, bsize )*wscale )*
338 $ max( ascale, bsize )
341 IF( wi.NE.zero )
THEN
347 scale1 = ascale*bsize
353 IF( wi.EQ.zero )
THEN
354 wsize = max( safmin, c1, fuzzy1*( abs( wr2 )*c2+c3 ),
355 $ min( c4, half*max( abs( wr2 ), c5 ) ) )
356 IF( wsize.NE.one )
THEN
358 IF( wsize.GT.one )
THEN
359 scale2 = ( max( ascale, bsize )*wscale )*
360 $ min( ascale, bsize )
362 scale2 = ( min( ascale, bsize )*wscale )*
363 $ max( ascale, bsize )
367 scale2 = ascale*bsize