LAPACK  3.10.0
LAPACK: Linear Algebra PACKage

◆ dlartg()

subroutine dlartg ( real(wp)  f,
real(wp)  g,
real(wp)  c,
real(wp)  s,
real(wp)  r 
)

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

Purpose:
 DLARTG generates a plane rotation so that

    [  C  S  ]  .  [ F ]  =  [ R ]
    [ -S  C  ]     [ G ]     [ 0 ]

 where C**2 + S**2 = 1.

 The mathematical formulas used for C and S are
    R = sign(F) * sqrt(F**2 + G**2)
    C = F / R
    S = G / R
 Hence C >= 0. The algorithm used to compute these quantities
 incorporates scaling to avoid overflow or underflow in computing the
 square root of the sum of squares.

 This version is discontinuous in R at F = 0 but it returns the same
 C and S as ZLARTG for complex inputs (F,0) and (G,0).

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

 If F exceeds G in magnitude, C will be positive.

 Below, wp=>dp stands for double precision from LA_CONSTANTS module.
Parameters
[in]F
          F is REAL(wp)
          The first component of vector to be rotated.
[in]G
          G is REAL(wp)
          The second component of vector to be rotated.
[out]C
          C is REAL(wp)
          The cosine of the rotation.
[out]S
          S is REAL(wp)
          The sine of the rotation.
[out]R
          R is REAL(wp)
          The nonzero component of the rotated vector.
Author
Edward Anderson, Lockheed Martin
Date
July 2016
Contributors:
Weslley Pereira, University of Colorado Denver, USA
Further Details:
  Anderson E. (2017)
  Algorithm 978: Safe Scaling in the Level 1 BLAS
  ACM Trans Math Softw 44:1--28
  https://doi.org/10.1145/3061665

Definition at line 112 of file dlartg.f90.

113  use la_constants, &
114  only: wp=>dp, zero=>dzero, half=>dhalf, one=>done, &
115  rtmin=>drtmin, rtmax=>drtmax, safmin=>dsafmin, safmax=>dsafmax
116 !
117 ! -- LAPACK auxiliary routine (version 3.10.0) --
118 ! -- LAPACK is a software package provided by Univ. of Tennessee, --
119 ! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
120 ! February 2021
121 !
122 ! .. Scalar Arguments ..
123  real(wp) :: c, f, g, r, s
124 ! ..
125 ! .. Local Scalars ..
126  real(wp) :: d, f1, fs, g1, gs, p, u, uu
127 ! ..
128 ! .. Intrinsic Functions ..
129  intrinsic :: abs, sign, sqrt
130 ! ..
131 ! .. Executable Statements ..
132 !
133  f1 = abs( f )
134  g1 = abs( g )
135  if( g == zero ) then
136  c = one
137  s = zero
138  r = f
139  else if( f == zero ) then
140  c = zero
141  s = sign( one, g )
142  r = g1
143  else if( f1 > rtmin .and. f1 < rtmax .and. &
144  g1 > rtmin .and. g1 < rtmax ) then
145  d = sqrt( f*f + g*g )
146  p = one / d
147  c = f1*p
148  s = g*sign( p, f )
149  r = sign( d, f )
150  else
151  u = min( safmax, max( safmin, f1, g1 ) )
152  uu = one / u
153  fs = f*uu
154  gs = g*uu
155  d = sqrt( fs*fs + gs*gs )
156  p = one / d
157  c = abs( fs )*p
158  s = gs*sign( p, f )
159  r = sign( d, f )*u
160  end if
161  return
real(dp), parameter dhalf
real(dp), parameter dzero
real(dp), parameter drtmax
real(dp), parameter dsafmin
integer, parameter dp
real(dp), parameter drtmin
real(dp), parameter done
real(dp), parameter dsafmax
LA_CONSTANTS is a module for the scaling constants for the compiled Fortran single and double precisi...
Here is the caller graph for this function: