Skip to content
Prev Previous commit
Next Next commit
Fix all other Givens rotation routines
  • Loading branch information
weslleyspereira committed Nov 3, 2021
commit 37a1a1e6896a4037fdb1f287ee643f8a57ce679e
37 changes: 15 additions & 22 deletions BLAS/SRC/crotg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ subroutine CROTG( a, b, c, s )
complex(wp) :: a, b, s
! ..
! .. Local Scalars ..
real(wp) :: d, f1, f2, g1, g2, h2, p, u, uu, v, vv, w
real(wp) :: d, f1, f2, g1, g2, h2, u, v, w
complex(wp) :: f, fs, g, gs, r, t
! ..
! .. Intrinsic Functions ..
Expand All @@ -149,19 +149,16 @@ subroutine CROTG( a, b, c, s )
!
! Use unscaled algorithm
!
g2 = ABSSQ( g )
d = sqrt( g2 )
d = abs( g )
s = conjg( g ) / d
r = d
else
!
! Use scaled algorithm
!
u = min( safmax, max( safmin, g1 ) )
uu = one / u
gs = g*uu
g2 = ABSSQ( gs )
d = sqrt( g2 )
gs = g / u
d = abs( gs )
s = conjg( gs ) / d
r = d*u
end if
Expand All @@ -181,35 +178,32 @@ subroutine CROTG( a, b, c, s )
else
d = sqrt( f2 )*sqrt( h2 )
end if
p = 1 / d
c = f2*p
s = conjg( g )*( f*p )
r = f*( h2*p )
c = f2 / d
s = conjg( g )*( f / d )
r = f*( h2 / d )
else
!
! Use scaled algorithm
!
u = min( safmax, max( safmin, f1, g1 ) )
uu = one / u
gs = g*uu
gs = g / u
g2 = ABSSQ( gs )
if( f1*uu < rtmin ) then
if( f1 / u < rtmin ) then
!
! f is not well-scaled when scaled by g1.
! Use a different scaling for f.
!
v = min( safmax, max( safmin, f1 ) )
vv = one / v
w = v * uu
fs = f*vv
w = v / u
fs = f / v
f2 = ABSSQ( fs )
h2 = f2*w**2 + g2
else
!
! Otherwise use the same scaling for f and g.
!
w = one
fs = f*uu
fs = f / u
f2 = ABSSQ( fs )
h2 = f2 + g2
end if
Expand All @@ -218,10 +212,9 @@ subroutine CROTG( a, b, c, s )
else
d = sqrt( f2 )*sqrt( h2 )
end if
p = 1 / d
c = ( f2*p )*w
s = conjg( gs )*( fs*p )
r = ( fs*( h2*p ) )*u
c = ( f2 / d )*w
s = conjg( gs )*( fs / d )
r = ( fs*( h2 / d ) )*u
end if
end if
a = r
Expand Down
37 changes: 15 additions & 22 deletions BLAS/SRC/zrotg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ subroutine ZROTG( a, b, c, s )
complex(wp) :: a, b, s
! ..
! .. Local Scalars ..
real(wp) :: d, f1, f2, g1, g2, h2, p, u, uu, v, vv, w
real(wp) :: d, f1, f2, g1, g2, h2, u, v, w
complex(wp) :: f, fs, g, gs, r, t
! ..
! .. Intrinsic Functions ..
Expand All @@ -149,19 +149,16 @@ subroutine ZROTG( a, b, c, s )
!
! Use unscaled algorithm
!
g2 = ABSSQ( g )
d = sqrt( g2 )
d = abs( g )
s = conjg( g ) / d
r = d
else
!
! Use scaled algorithm
!
u = min( safmax, max( safmin, g1 ) )
uu = one / u
gs = g*uu
g2 = ABSSQ( gs )
d = sqrt( g2 )
gs = g / u
d = abs( gs )
s = conjg( gs ) / d
r = d*u
end if
Expand All @@ -181,35 +178,32 @@ subroutine ZROTG( a, b, c, s )
else
d = sqrt( f2 )*sqrt( h2 )
end if
p = 1 / d
c = f2*p
s = conjg( g )*( f*p )
r = f*( h2*p )
c = f2 / d
s = conjg( g )*( f / d )
r = f*( h2 / d )
else
!
! Use scaled algorithm
!
u = min( safmax, max( safmin, f1, g1 ) )
uu = one / u
gs = g*uu
gs = g / u
g2 = ABSSQ( gs )
if( f1*uu < rtmin ) then
if( f1 / u < rtmin ) then
!
! f is not well-scaled when scaled by g1.
! Use a different scaling for f.
!
v = min( safmax, max( safmin, f1 ) )
vv = one / v
w = v * uu
fs = f*vv
w = v / u
fs = f / v
f2 = ABSSQ( fs )
h2 = f2*w**2 + g2
else
!
! Otherwise use the same scaling for f and g.
!
w = one
fs = f*uu
fs = f / u
f2 = ABSSQ( fs )
h2 = f2 + g2
end if
Expand All @@ -218,10 +212,9 @@ subroutine ZROTG( a, b, c, s )
else
d = sqrt( f2 )*sqrt( h2 )
end if
p = 1 / d
c = ( f2*p )*w
s = conjg( gs )*( fs*p )
r = ( fs*( h2*p ) )*u
c = ( f2 / d )*w
s = conjg( gs )*( fs / d )
r = ( fs*( h2 / d ) )*u
end if
end if
a = r
Expand Down
49 changes: 13 additions & 36 deletions SRC/clartg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -178,33 +178,22 @@ subroutine CLARTG( f, g, c, s, r )
f2 = ABSSQ( f )
g2 = ABSSQ( g )
h2 = f2 + g2
if( f2 > safmin * g2 ) then
d = sqrt( one + g2/f2 )
c = one / d
if( f2 > rtmin .and. h2 < rtmax ) then
s = conjg( g )*( f / sqrt( f2*h2 ) )
else
s = conjg( g )*( f /( f2*d ) )
end if
r = f * d
if( f2 > rtmin .and. h2 < rtmax ) then
d = sqrt( f2*h2 )
else
if( f2 > rtmin .and. h2 < rtmax ) then
d = sqrt( f2*h2 )
else
d = sqrt( f2 )*sqrt( h2 )
end if
c = f2 / d
s = conjg( g )*( f / d )
r = f*( h2 / d )
d = sqrt( f2 )*sqrt( h2 )
end if
c = f2 / d
s = conjg( g )*( f / d )
r = f*( h2 / d )
else
!
! Use scaled algorithm
!
u = min( safmax, max( safmin, f1, g1 ) )
gs = g / u
g2 = ABSSQ( gs )
if( f1 < rtmin * u ) then
if( f1 / u < rtmin ) then
!
! f is not well-scaled when scaled by g1.
! Use a different scaling for f.
Expand All @@ -223,26 +212,14 @@ subroutine CLARTG( f, g, c, s, r )
f2 = ABSSQ( fs )
h2 = f2 + g2
end if
if( f2 > safmin * g2 ) then
! Use a precise algorithm
d = sqrt( w**2 + g2/f2 )
c = w / d
if( f2 > rtmin .and. h2 < rtmax ) then
s = conjg( gs )*( fs / sqrt( f2*h2 ) )
else
s = conjg( gs )*( fs / ( f2*d ) )
end if
r = ( fs * d ) * u
if( f2 > rtmin .and. h2 < rtmax ) then
d = sqrt( f2*h2 )
else
if( f2 > rtmin .and. h2 < rtmax ) then
d = sqrt( f2*h2 )
else
d = sqrt( f2 )*sqrt( h2 )
end if
c = ( f2 / d )*w
s = conjg( gs )*( fs / d )
r = ( fs*( h2 / d ) )*u
d = sqrt( f2 )*sqrt( h2 )
end if
c = ( f2 / d )*w
s = conjg( gs )*( fs / d )
r = ( fs*( h2 / d ) )*u
end if
end if
return
Expand Down
20 changes: 9 additions & 11 deletions SRC/dlartg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ subroutine DLARTG( f, g, c, s, r )
real(wp) :: c, f, g, r, s
! ..
! .. Local Scalars ..
real(wp) :: d, f1, fs, g1, gs, p, u, uu
real(wp) :: d, f1, fs, g1, gs, u
! ..
! .. Intrinsic Functions ..
intrinsic :: abs, sign, sqrt
Expand All @@ -143,20 +143,18 @@ subroutine DLARTG( f, g, c, s, r )
else if( f1 > rtmin .and. f1 < rtmax .and. &
g1 > rtmin .and. g1 < rtmax ) then
d = sqrt( f*f + g*g )
p = one / d
c = f1*p
s = g*sign( p, f )
c = f1 / d
r = sign( d, f )
s = g / r
else
u = min( safmax, max( safmin, f1, g1 ) )
uu = one / u
fs = f*uu
gs = g*uu
fs = f / u
gs = g / u
d = sqrt( fs*fs + gs*gs )
p = one / d
c = abs( fs )*p
s = gs*sign( p, f )
r = sign( d, f )*u
c = abs( fs ) / d
r = sign( d, f )
s = gs / r
r = r * u
end if
return
end subroutine
20 changes: 9 additions & 11 deletions SRC/slartg.f90
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ subroutine SLARTG( f, g, c, s, r )
real(wp) :: c, f, g, r, s
! ..
! .. Local Scalars ..
real(wp) :: d, f1, fs, g1, gs, p, u, uu
real(wp) :: d, f1, fs, g1, gs, u
! ..
! .. Intrinsic Functions ..
intrinsic :: abs, sign, sqrt
Expand All @@ -143,20 +143,18 @@ subroutine SLARTG( f, g, c, s, r )
else if( f1 > rtmin .and. f1 < rtmax .and. &
g1 > rtmin .and. g1 < rtmax ) then
d = sqrt( f*f + g*g )
p = one / d
c = f1*p
s = g*sign( p, f )
c = f1 / d
r = sign( d, f )
s = g / r
else
u = min( safmax, max( safmin, f1, g1 ) )
uu = one / u
fs = f*uu
gs = g*uu
fs = f / u
gs = g / u
d = sqrt( fs*fs + gs*gs )
p = one / d
c = abs( fs )*p
s = gs*sign( p, f )
r = sign( d, f )*u
c = abs( fs ) / d
r = sign( d, f )
s = gs / r
r = r*u
end if
return
end subroutine
Loading