LAPACK  3.9.1
LAPACK: Linear Algebra PACKage
dlartg.f
Go to the documentation of this file.
1 *> \brief \b DLARTG generates a plane rotation with real cosine and real sine.
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download DLARTG + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlartg.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlartg.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlartg.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE DLARTG( F, G, CS, SN, R )
22 *
23 * .. Scalar Arguments ..
24 * DOUBLE PRECISION CS, F, G, R, SN
25 * ..
26 *
27 *
28 *> \par Purpose:
29 * =============
30 *>
31 *> \verbatim
32 *>
33 *> DLARTG generate a plane rotation so that
34 *>
35 *> [ CS SN ] . [ F ] = [ R ] where CS**2 + SN**2 = 1.
36 *> [ -SN CS ] [ G ] [ 0 ]
37 *>
38 *> This is a slower, more accurate version of the BLAS1 routine DROTG,
39 *> with the following other differences:
40 *> F and G are unchanged on return.
41 *> If G=0, then CS=1 and SN=0.
42 *> If F=0 and (G .ne. 0), then CS=0 and SN=1 without doing any
43 *> floating point operations (saves work in DBDSQR when
44 *> there are zeros on the diagonal).
45 *>
46 *> If F exceeds G in magnitude, CS will be positive.
47 *> \endverbatim
48 *
49 * Arguments:
50 * ==========
51 *
52 *> \param[in] F
53 *> \verbatim
54 *> F is DOUBLE PRECISION
55 *> The first component of vector to be rotated.
56 *> \endverbatim
57 *>
58 *> \param[in] G
59 *> \verbatim
60 *> G is DOUBLE PRECISION
61 *> The second component of vector to be rotated.
62 *> \endverbatim
63 *>
64 *> \param[out] CS
65 *> \verbatim
66 *> CS is DOUBLE PRECISION
67 *> The cosine of the rotation.
68 *> \endverbatim
69 *>
70 *> \param[out] SN
71 *> \verbatim
72 *> SN is DOUBLE PRECISION
73 *> The sine of the rotation.
74 *> \endverbatim
75 *>
76 *> \param[out] R
77 *> \verbatim
78 *> R is DOUBLE PRECISION
79 *> The nonzero component of the rotated vector.
80 *>
81 *> This version has a few statements commented out for thread safety
82 *> (machine parameters are computed on each entry). 10 feb 03, SJH.
83 *> \endverbatim
84 *
85 * Authors:
86 * ========
87 *
88 *> \author Univ. of Tennessee
89 *> \author Univ. of California Berkeley
90 *> \author Univ. of Colorado Denver
91 *> \author NAG Ltd.
92 *
93 *> \ingroup OTHERauxiliary
94 *
95 * =====================================================================
96  SUBROUTINE dlartg( F, G, CS, SN, R )
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  DOUBLE PRECISION CS, F, G, R, SN
104 * ..
105 *
106 * =====================================================================
107 *
108 * .. Parameters ..
109  DOUBLE PRECISION ZERO
110  parameter( zero = 0.0d0 )
111  DOUBLE PRECISION ONE
112  parameter( one = 1.0d0 )
113  DOUBLE PRECISION TWO
114  parameter( two = 2.0d0 )
115 * ..
116 * .. Local Scalars ..
117 * LOGICAL FIRST
118  INTEGER COUNT, I
119  DOUBLE PRECISION EPS, F1, G1, SAFMIN, SAFMN2, SAFMX2, SCALE
120 * ..
121 * .. External Functions ..
122  DOUBLE PRECISION DLAMCH
123  EXTERNAL dlamch
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 = dlamch( 'S' )
138  eps = dlamch( 'E' )
139  safmn2 = dlamch( 'B' )**int( log( safmin / eps ) /
140  $ log( dlamch( '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 DLARTG
200 *
201  END
subroutine dlartg(F, G, CS, SN, R)
DLARTG generates a plane rotation with real cosine and real sine.
Definition: dlartg.f:97