LAPACK  3.9.1
LAPACK: Linear Algebra PACKage

◆ slartg()

subroutine slartg ( real  F,
real  G,
real  CS,
real  SN,
real  R 
)

SLARTG generates a plane rotation with real cosine and real sine.

Download SLARTG + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 SLARTG generate a plane rotation so that

    [  CS  SN  ]  .  [ F ]  =  [ R ]   where CS**2 + SN**2 = 1.
    [ -SN  CS  ]     [ G ]     [ 0 ]

 This is a slower, more accurate version of the BLAS1 routine SROTG,
 with the following other differences:
    F and G are unchanged on return.
    If G=0, then CS=1 and SN=0.
    If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any
       floating point operations (saves work in SBDSQR when
       there are zeros on the diagonal).

 If F exceeds G in magnitude, CS will be positive.
Parameters
[in]F
          F is REAL
          The first component of vector to be rotated.
[in]G
          G is REAL
          The second component of vector to be rotated.
[out]CS
          CS is REAL
          The cosine of the rotation.
[out]SN
          SN is REAL
          The sine of the rotation.
[out]R
          R is REAL
          The nonzero component of the rotated vector.

  This version has a few statements commented out for thread safety
  (machine parameters are computed on each entry). 10 feb 03, SJH.
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 96 of file slartg.f.

97 *
98 * -- LAPACK auxiliary routine --
99 * -- LAPACK is a software package provided by Univ. of Tennessee, --
100 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
101 *
102 * .. Scalar Arguments ..
103  REAL CS, F, G, R, SN
104 * ..
105 *
106 * =====================================================================
107 *
108 * .. Parameters ..
109  REAL ZERO
110  parameter( zero = 0.0e0 )
111  REAL ONE
112  parameter( one = 1.0e0 )
113  REAL TWO
114  parameter( two = 2.0e0 )
115 * ..
116 * .. Local Scalars ..
117 * LOGICAL FIRST
118  INTEGER COUNT, I
119  REAL EPS, F1, G1, SAFMIN, SAFMN2, SAFMX2, SCALE
120 * ..
121 * .. External Functions ..
122  REAL SLAMCH
123  EXTERNAL slamch
124 * ..
125 * .. Intrinsic Functions ..
126  INTRINSIC abs, int, log, max, sqrt
127 * ..
128 * .. Save statement ..
129 * SAVE FIRST, SAFMX2, SAFMIN, SAFMN2
130 * ..
131 * .. Data statements ..
132 * DATA FIRST / .TRUE. /
133 * ..
134 * .. Executable Statements ..
135 *
136 * IF( FIRST ) THEN
137  safmin = slamch( 'S' )
138  eps = slamch( 'E' )
139  safmn2 = slamch( 'B' )**int( log( safmin / eps ) /
140  $ log( slamch( 'B' ) ) / two )
141  safmx2 = one / safmn2
142 * FIRST = .FALSE.
143 * END IF
144  IF( g.EQ.zero ) THEN
145  cs = one
146  sn = zero
147  r = f
148  ELSE IF( f.EQ.zero ) THEN
149  cs = zero
150  sn = one
151  r = g
152  ELSE
153  f1 = f
154  g1 = g
155  scale = max( abs( f1 ), abs( g1 ) )
156  IF( scale.GE.safmx2 ) THEN
157  count = 0
158  10 CONTINUE
159  count = count + 1
160  f1 = f1*safmn2
161  g1 = g1*safmn2
162  scale = max( abs( f1 ), abs( g1 ) )
163  IF( scale.GE.safmx2 .AND. count .LT. 20)
164  $ GO TO 10
165  r = sqrt( f1**2+g1**2 )
166  cs = f1 / r
167  sn = g1 / r
168  DO 20 i = 1, count
169  r = r*safmx2
170  20 CONTINUE
171  ELSE IF( scale.LE.safmn2 ) THEN
172  count = 0
173  30 CONTINUE
174  count = count + 1
175  f1 = f1*safmx2
176  g1 = g1*safmx2
177  scale = max( abs( f1 ), abs( g1 ) )
178  IF( scale.LE.safmn2 )
179  $ GO TO 30
180  r = sqrt( f1**2+g1**2 )
181  cs = f1 / r
182  sn = g1 / r
183  DO 40 i = 1, count
184  r = r*safmn2
185  40 CONTINUE
186  ELSE
187  r = sqrt( f1**2+g1**2 )
188  cs = f1 / r
189  sn = g1 / r
190  END IF
191  IF( abs( f ).GT.abs( g ) .AND. cs.LT.zero ) THEN
192  cs = -cs
193  sn = -sn
194  r = -r
195  END IF
196  END IF
197  RETURN
198 *
199 * End of SLARTG
200 *
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:68
Here is the caller graph for this function: