zlartg.f.html

来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 220 行

HTML
220
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>zlartg.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="ZLARTG.1"></a><a href="zlartg.f.html#ZLARTG.1">ZLARTG</a>( F, G, CS, SN, R )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK auxiliary routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      DOUBLE PRECISION   CS
      COMPLEX*16         F, G, R, SN
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="ZLARTG.15"></a><a href="zlartg.f.html#ZLARTG.1">ZLARTG</a> generates a plane rotation so that
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     [  CS  SN  ]     [ F ]     [ R ]
</span><span class="comment">*</span><span class="comment">     [  __      ]  .  [   ]  =  [   ]   where CS**2 + |SN|**2 = 1.
</span><span class="comment">*</span><span class="comment">     [ -SN  CS  ]     [ G ]     [ 0 ]
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  This is a faster version of the BLAS1 routine ZROTG, except for
</span><span class="comment">*</span><span class="comment">  the following differences:
</span><span class="comment">*</span><span class="comment">     F and G are unchanged on return.
</span><span class="comment">*</span><span class="comment">     If G=0, then CS=1 and SN=0.
</span><span class="comment">*</span><span class="comment">     If F=0, then CS=0 and SN is chosen so that R is real.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  F       (input) COMPLEX*16
</span><span class="comment">*</span><span class="comment">          The first component of vector to be rotated.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  G       (input) COMPLEX*16
</span><span class="comment">*</span><span class="comment">          The second component of vector to be rotated.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  CS      (output) DOUBLE PRECISION
</span><span class="comment">*</span><span class="comment">          The cosine of the rotation.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  SN      (output) COMPLEX*16
</span><span class="comment">*</span><span class="comment">          The sine of the rotation.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  R       (output) COMPLEX*16
</span><span class="comment">*</span><span class="comment">          The nonzero component of the rotated vector.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ======= =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  3-5-96 - Modified with a new algorithm by W. Kahan and J. Demmel
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  This version has a few statements commented out for thread safety
</span><span class="comment">*</span><span class="comment">  (machine parameters are computed on each entry). 10 feb 03, SJH.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      DOUBLE PRECISION   TWO, ONE, ZERO
      PARAMETER          ( TWO = 2.0D+0, ONE = 1.0D+0, ZERO = 0.0D+0 )
      COMPLEX*16         CZERO
      PARAMETER          ( CZERO = ( 0.0D+0, 0.0D+0 ) )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span><span class="comment">*</span><span class="comment">     LOGICAL            FIRST
</span>      INTEGER            COUNT, I
      DOUBLE PRECISION   D, DI, DR, EPS, F2, F2S, G2, G2S, SAFMIN,
     $                   SAFMN2, SAFMX2, SCALE
      COMPLEX*16         FF, FS, GS
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      DOUBLE PRECISION   <a name="DLAMCH.69"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>, <a name="DLAPY2.69"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>
      EXTERNAL           <a name="DLAMCH.70"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>, <a name="DLAPY2.70"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          ABS, DBLE, DCMPLX, DCONJG, DIMAG, INT, LOG,
     $                   MAX, SQRT
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Statement Functions ..
</span>      DOUBLE PRECISION   ABS1, ABSSQ
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Save statement ..
</span><span class="comment">*</span><span class="comment">     SAVE               FIRST, SAFMX2, SAFMIN, SAFMN2
</span><span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Data statements ..
</span><span class="comment">*</span><span class="comment">     DATA               FIRST / .TRUE. /
</span><span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Statement Function definitions ..
</span>      ABS1( FF ) = MAX( ABS( DBLE( FF ) ), ABS( DIMAG( FF ) ) )
      ABSSQ( FF ) = DBLE( FF )**2 + DIMAG( FF )**2
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     IF( FIRST ) THEN
</span>         SAFMIN = <a name="DLAMCH.92"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>( <span class="string">'S'</span> )
         EPS = <a name="DLAMCH.93"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>( <span class="string">'E'</span> )
         SAFMN2 = <a name="DLAMCH.94"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>( <span class="string">'B'</span> )**INT( LOG( SAFMIN / EPS ) /
     $            LOG( <a name="DLAMCH.95"></a><a href="dlamch.f.html#DLAMCH.1">DLAMCH</a>( <span class="string">'B'</span> ) ) / TWO )
         SAFMX2 = ONE / SAFMN2
<span class="comment">*</span><span class="comment">        FIRST = .FALSE.
</span><span class="comment">*</span><span class="comment">     END IF
</span>      SCALE = MAX( ABS1( F ), ABS1( G ) )
      FS = F
      GS = G
      COUNT = 0
      IF( SCALE.GE.SAFMX2 ) THEN
   10    CONTINUE
         COUNT = COUNT + 1
         FS = FS*SAFMN2
         GS = GS*SAFMN2
         SCALE = SCALE*SAFMN2
         IF( SCALE.GE.SAFMX2 )
     $      GO TO 10
      ELSE IF( SCALE.LE.SAFMN2 ) THEN
         IF( G.EQ.CZERO ) THEN
            CS = ONE
            SN = CZERO
            R = F
            RETURN
         END IF
   20    CONTINUE
         COUNT = COUNT - 1
         FS = FS*SAFMX2
         GS = GS*SAFMX2
         SCALE = SCALE*SAFMX2
         IF( SCALE.LE.SAFMN2 )
     $      GO TO 20
      END IF
      F2 = ABSSQ( FS )
      G2 = ABSSQ( GS )
      IF( F2.LE.MAX( G2, ONE )*SAFMIN ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        This is a rare case: F is very small.
</span><span class="comment">*</span><span class="comment">
</span>         IF( F.EQ.CZERO ) THEN
            CS = ZERO
            R = <a name="DLAPY2.134"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>( DBLE( G ), DIMAG( G ) )
<span class="comment">*</span><span class="comment">           Do complex/real division explicitly with two real divisions
</span>            D = <a name="DLAPY2.136"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>( DBLE( GS ), DIMAG( GS ) )
            SN = DCMPLX( DBLE( GS ) / D, -DIMAG( GS ) / D )
            RETURN
         END IF
         F2S = <a name="DLAPY2.140"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>( DBLE( FS ), DIMAG( FS ) )
<span class="comment">*</span><span class="comment">        G2 and G2S are accurate
</span><span class="comment">*</span><span class="comment">        G2 is at least SAFMIN, and G2S is at least SAFMN2
</span>         G2S = SQRT( G2 )
<span class="comment">*</span><span class="comment">        Error in CS from underflow in F2S is at most
</span><span class="comment">*</span><span class="comment">        UNFL / SAFMN2 .lt. sqrt(UNFL*EPS) .lt. EPS
</span><span class="comment">*</span><span class="comment">        If MAX(G2,ONE)=G2, then F2 .lt. G2*SAFMIN,
</span><span class="comment">*</span><span class="comment">        and so CS .lt. sqrt(SAFMIN)
</span><span class="comment">*</span><span class="comment">        If MAX(G2,ONE)=ONE, then F2 .lt. SAFMIN
</span><span class="comment">*</span><span class="comment">        and so CS .lt. sqrt(SAFMIN)/SAFMN2 = sqrt(EPS)
</span><span class="comment">*</span><span class="comment">        Therefore, CS = F2S/G2S / sqrt( 1 + (F2S/G2S)**2 ) = F2S/G2S
</span>         CS = F2S / G2S
<span class="comment">*</span><span class="comment">        Make sure abs(FF) = 1
</span><span class="comment">*</span><span class="comment">        Do complex/real division explicitly with 2 real divisions
</span>         IF( ABS1( F ).GT.ONE ) THEN
            D = <a name="DLAPY2.155"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>( DBLE( F ), DIMAG( F ) )
            FF = DCMPLX( DBLE( F ) / D, DIMAG( F ) / D )
         ELSE
            DR = SAFMX2*DBLE( F )
            DI = SAFMX2*DIMAG( F )
            D = <a name="DLAPY2.160"></a><a href="dlapy2.f.html#DLAPY2.1">DLAPY2</a>( DR, DI )
            FF = DCMPLX( DR / D, DI / D )
         END IF
         SN = FF*DCMPLX( DBLE( GS ) / G2S, -DIMAG( GS ) / G2S )
         R = CS*F + SN*G
      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        This is the most common case.
</span><span class="comment">*</span><span class="comment">        Neither F2 nor F2/G2 are less than SAFMIN
</span><span class="comment">*</span><span class="comment">        F2S cannot overflow, and it is accurate
</span><span class="comment">*</span><span class="comment">
</span>         F2S = SQRT( ONE+G2 / F2 )
<span class="comment">*</span><span class="comment">        Do the F2S(real)*FS(complex) multiply with two real multiplies
</span>         R = DCMPLX( F2S*DBLE( FS ), F2S*DIMAG( FS ) )
         CS = ONE / F2S
         D = F2 + G2
<span class="comment">*</span><span class="comment">        Do complex/real division explicitly with two real divisions
</span>         SN = DCMPLX( DBLE( R ) / D, DIMAG( R ) / D )
         SN = SN*DCONJG( GS )
         IF( COUNT.NE.0 ) THEN
            IF( COUNT.GT.0 ) THEN
               DO 30 I = 1, COUNT
                  R = R*SAFMX2
   30          CONTINUE
            ELSE
               DO 40 I = 1, -COUNT
                  R = R*SAFMN2
   40          CONTINUE
            END IF
         END IF
      END IF
      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="ZLARTG.193"></a><a href="zlartg.f.html#ZLARTG.1">ZLARTG</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?