218 SUBROUTINE slaln2( LTRANS, NA, NW, SMIN, CA, A, LDA, D1, D2, B,
219 $ ldb, wr, wi, x, ldx, scale, xnorm, info )
228 INTEGER INFO, LDA, LDB, LDX, NA, NW
229 REAL CA, D1, D2, SCALE, SMIN, WI, WR, XNORM
232 REAL A( lda, * ), B( ldb, * ), X( ldx, * )
239 parameter ( zero = 0.0e0, one = 1.0e0 )
241 parameter ( two = 2.0e0 )
245 REAL BBND, BI1, BI2, BIGNUM, BNORM, BR1, BR2, CI21,
246 $ ci22, cmax, cnorm, cr21, cr22, csi, csr, li21,
247 $ lr21, smini, smlnum, temp, u22abs, ui11, ui11r,
248 $ ui12, ui12s, ui22, ur11, ur11r, ur12, ur12s,
249 $ ur22, xi1, xi2, xr1, xr2
252 LOGICAL CSWAP( 4 ), RSWAP( 4 )
253 INTEGER IPIVOT( 4, 4 )
254 REAL CI( 2, 2 ), CIV( 4 ), CR( 2, 2 ), CRV( 4 )
267 equivalence ( ci( 1, 1 ), civ( 1 ) ),
268 $ ( cr( 1, 1 ), crv( 1 ) )
271 DATA cswap / .false., .false., .true., .true. /
272 DATA rswap / .false., .true., .false., .true. /
273 DATA ipivot / 1, 2, 3, 4, 2, 1, 4, 3, 3, 4, 1, 2, 4,
280 smlnum = two*slamch(
'Safe minimum' )
281 bignum = one / smlnum
282 smini = max( smin, smlnum )
302 csr = ca*a( 1, 1 ) - wr*d1
307 IF( cnorm.LT.smini )
THEN
315 bnorm = abs( b( 1, 1 ) )
316 IF( cnorm.LT.one .AND. bnorm.GT.one )
THEN
317 IF( bnorm.GT.bignum*cnorm )
318 $ scale = one / bnorm
323 x( 1, 1 ) = ( b( 1, 1 )*scale ) / csr
324 xnorm = abs( x( 1, 1 ) )
331 csr = ca*a( 1, 1 ) - wr*d1
333 cnorm = abs( csr ) + abs( csi )
337 IF( cnorm.LT.smini )
THEN
346 bnorm = abs( b( 1, 1 ) ) + abs( b( 1, 2 ) )
347 IF( cnorm.LT.one .AND. bnorm.GT.one )
THEN
348 IF( bnorm.GT.bignum*cnorm )
349 $ scale = one / bnorm
354 CALL sladiv( scale*b( 1, 1 ), scale*b( 1, 2 ), csr, csi,
355 $ x( 1, 1 ), x( 1, 2 ) )
356 xnorm = abs( x( 1, 1 ) ) + abs( x( 1, 2 ) )
365 cr( 1, 1 ) = ca*a( 1, 1 ) - wr*d1
366 cr( 2, 2 ) = ca*a( 2, 2 ) - wr*d2
368 cr( 1, 2 ) = ca*a( 2, 1 )
369 cr( 2, 1 ) = ca*a( 1, 2 )
371 cr( 2, 1 ) = ca*a( 2, 1 )
372 cr( 1, 2 ) = ca*a( 1, 2 )
385 IF( abs( crv( j ) ).GT.cmax )
THEN
386 cmax = abs( crv( j ) )
393 IF( cmax.LT.smini )
THEN
394 bnorm = max( abs( b( 1, 1 ) ), abs( b( 2, 1 ) ) )
395 IF( smini.LT.one .AND. bnorm.GT.one )
THEN
396 IF( bnorm.GT.bignum*smini )
397 $ scale = one / bnorm
400 x( 1, 1 ) = temp*b( 1, 1 )
401 x( 2, 1 ) = temp*b( 2, 1 )
410 cr21 = crv( ipivot( 2, icmax ) )
411 ur12 = crv( ipivot( 3, icmax ) )
412 cr22 = crv( ipivot( 4, icmax ) )
415 ur22 = cr22 - ur12*lr21
419 IF( abs( ur22 ).LT.smini )
THEN
423 IF( rswap( icmax ) )
THEN
431 bbnd = max( abs( br1*( ur22*ur11r ) ), abs( br2 ) )
432 IF( bbnd.GT.one .AND. abs( ur22 ).LT.one )
THEN
433 IF( bbnd.GE.bignum*abs( ur22 ) )
437 xr2 = ( br2*scale ) / ur22
438 xr1 = ( scale*br1 )*ur11r - xr2*( ur11r*ur12 )
439 IF( cswap( icmax ) )
THEN
446 xnorm = max( abs( xr1 ), abs( xr2 ) )
450 IF( xnorm.GT.one .AND. cmax.GT.one )
THEN
451 IF( xnorm.GT.bignum / cmax )
THEN
453 x( 1, 1 ) = temp*x( 1, 1 )
454 x( 2, 1 ) = temp*x( 2, 1 )
473 IF( abs( crv( j ) )+abs( civ( j ) ).GT.cmax )
THEN
474 cmax = abs( crv( j ) ) + abs( civ( j ) )
481 IF( cmax.LT.smini )
THEN
482 bnorm = max( abs( b( 1, 1 ) )+abs( b( 1, 2 ) ),
483 $ abs( b( 2, 1 ) )+abs( b( 2, 2 ) ) )
484 IF( smini.LT.one .AND. bnorm.GT.one )
THEN
485 IF( bnorm.GT.bignum*smini )
486 $ scale = one / bnorm
489 x( 1, 1 ) = temp*b( 1, 1 )
490 x( 2, 1 ) = temp*b( 2, 1 )
491 x( 1, 2 ) = temp*b( 1, 2 )
492 x( 2, 2 ) = temp*b( 2, 2 )
502 cr21 = crv( ipivot( 2, icmax ) )
503 ci21 = civ( ipivot( 2, icmax ) )
504 ur12 = crv( ipivot( 3, icmax ) )
505 ui12 = civ( ipivot( 3, icmax ) )
506 cr22 = crv( ipivot( 4, icmax ) )
507 ci22 = civ( ipivot( 4, icmax ) )
508 IF( icmax.EQ.1 .OR. icmax.EQ.4 )
THEN
512 IF( abs( ur11 ).GT.abs( ui11 ) )
THEN
514 ur11r = one / ( ur11*( one+temp**2 ) )
518 ui11r = -one / ( ui11*( one+temp**2 ) )
525 ur22 = cr22 - ur12*lr21
526 ui22 = ci22 - ur12*li21
537 ur22 = cr22 - ur12*lr21 + ui12*li21
538 ui22 = -ur12*li21 - ui12*lr21
540 u22abs = abs( ur22 ) + abs( ui22 )
544 IF( u22abs.LT.smini )
THEN
549 IF( rswap( icmax ) )
THEN
560 br2 = br2 - lr21*br1 + li21*bi1
561 bi2 = bi2 - li21*br1 - lr21*bi1
562 bbnd = max( ( abs( br1 )+abs( bi1 ) )*
563 $ ( u22abs*( abs( ur11r )+abs( ui11r ) ) ),
564 $ abs( br2 )+abs( bi2 ) )
565 IF( bbnd.GT.one .AND. u22abs.LT.one )
THEN
566 IF( bbnd.GE.bignum*u22abs )
THEN
575 CALL sladiv( br2, bi2, ur22, ui22, xr2, xi2 )
576 xr1 = ur11r*br1 - ui11r*bi1 - ur12s*xr2 + ui12s*xi2
577 xi1 = ui11r*br1 + ur11r*bi1 - ui12s*xr2 - ur12s*xi2
578 IF( cswap( icmax ) )
THEN
589 xnorm = max( abs( xr1 )+abs( xi1 ), abs( xr2 )+abs( xi2 ) )
593 IF( xnorm.GT.one .AND. cmax.GT.one )
THEN
594 IF( xnorm.GT.bignum / cmax )
THEN
596 x( 1, 1 ) = temp*x( 1, 1 )
597 x( 2, 1 ) = temp*x( 2, 1 )
598 x( 1, 2 ) = temp*x( 1, 2 )
599 x( 2, 2 ) = temp*x( 2, 2 )
subroutine sladiv(A, B, C, D, P, Q)
SLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.
subroutine slaln2(LTRANS, NA, NW, SMIN, CA, A, LDA, D1, D2, B, LDB, WR, WI, X, LDX, SCALE, XNORM, INFO)
SLALN2 solves a 1-by-1 or 2-by-2 linear system of equations of the specified form.