LAPACK 3.11.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ srotg()

subroutine srotg ( real(wp)  a,
real(wp)  b,
real(wp)  c,
real(wp)  s 
)

SROTG

Purpose:
 The computation uses the formulas
    sigma = sgn(a)    if |a| >  |b|
          = sgn(b)    if |b| >= |a|
    r = sigma*sqrt( a**2 + b**2 )
    c = 1; s = 0      if r = 0
    c = a/r; s = b/r  if r != 0
 The subroutine also computes
    z = s    if |a| > |b|,
      = 1/c  if |b| >= |a| and c != 0
      = 1    if c = 0
 This allows c and s to be reconstructed from z as follows:
    If z = 1, set c = 0, s = 1.
    If |z| < 1, set c = sqrt(1 - z**2) and s = z.
    If |z| > 1, set c = 1/z and s = sqrt( 1 - c**2).
Parameters
[in,out]A
          A is REAL
          On entry, the scalar a.
          On exit, the scalar r.
[in,out]B
          B is REAL
          On entry, the scalar b.
          On exit, the scalar z.
[out]C
          C is REAL
          The scalar c.
[out]S
          S is REAL
          The scalar s.
Author
Edward Anderson, Lockheed Martin
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 92 of file srotg.f90.

93 integer, parameter :: wp = kind(1.e0)
94!
95! -- Reference BLAS level1 routine --
96! -- Reference BLAS is a software package provided by Univ. of Tennessee, --
97! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
98!
99! .. Constants ..
100 real(wp), parameter :: zero = 0.0_wp
101 real(wp), parameter :: one = 1.0_wp
102! ..
103! .. Scaling constants ..
104 real(wp), parameter :: safmin = real(radix(0._wp),wp)**max( &
105 minexponent(0._wp)-1, &
106 1-maxexponent(0._wp) &
107 )
108 real(wp), parameter :: safmax = real(radix(0._wp),wp)**max( &
109 1-minexponent(0._wp), &
110 maxexponent(0._wp)-1 &
111 )
112! ..
113! .. Scalar Arguments ..
114 real(wp) :: a, b, c, s
115! ..
116! .. Local Scalars ..
117 real(wp) :: anorm, bnorm, scl, sigma, r, z
118! ..
119 anorm = abs(a)
120 bnorm = abs(b)
121 if( bnorm == zero ) then
122 c = one
123 s = zero
124 b = zero
125 else if( anorm == zero ) then
126 c = zero
127 s = one
128 a = b
129 b = one
130 else
131 scl = min( safmax, max( safmin, anorm, bnorm ) )
132 if( anorm > bnorm ) then
133 sigma = sign(one,a)
134 else
135 sigma = sign(one,b)
136 end if
137 r = sigma*( scl*sqrt((a/scl)**2 + (b/scl)**2) )
138 c = a/r
139 s = b/r
140 if( anorm > bnorm ) then
141 z = s
142 else if( c /= zero ) then
143 z = one/c
144 else
145 z = one
146 end if
147 a = r
148 b = z
149 end if
150 return
Here is the caller graph for this function: