stdlib_srotg 子程序

public pure subroutine stdlib_srotg(a, b, c, s)

计算使用以下公式:sigma = sgn(a) 如果 |a| > |b| = sgn(b) 如果 |b| >= |a| r = sigma*sqrt( a*a + b*b ) c = 1; s = 0 如果 r = 0 c = a/r; s = b/r 如果 r != 0 子程序还计算 z = s 如果 |a| > |b|,= 1/c 如果 |b| >= |a| 且 c != 0 = 1 如果 c = 0 这允许从 z 中重建 c 和 s,如下所示:如果 z = 1,则设置 c = 0,s = 1。如果 |z| < 1,则设置 c = sqrt(1 - z*z) 和 s = z。如果 |z| > 1,则设置 c = 1/z 和 s = sqrt( 1 - c*c)。

参数

类型 意图可选 属性 名称
real(kind=sp), intent(inout) :: a
real(kind=sp), intent(inout) :: b
real(kind=sp), intent(out) :: c
real(kind=sp), intent(out) :: s

源代码

     pure subroutine stdlib_srotg( a, b, c, s )
     !! 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).
        ! -- reference blas level1 routine --
        ! -- reference blas is a software package provided by univ. of tennessee,    --
        ! -- univ. of california berkeley, univ. of colorado denver and nag ltd..--
        ! Constants 
        integer, parameter :: wp = kind(1._sp)
        ! Scaling Constants 
        ! Scalar Arguments 
        real(sp), intent(inout) :: a, b
        real(sp), intent(out) :: c, s
        ! Local Scalars 
        real(sp) :: anorm, bnorm, scl, sigma, r, z
        anorm = abs(a)
        bnorm = abs(b)
        if( bnorm == zero ) then
           c = one
           s = zero
           b = zero
        else if( anorm == zero ) then
           c = zero
           s = one
           a = b
           b = one
        else
           scl = min( safmax, max( safmin, anorm, bnorm ) )
           if( anorm > bnorm ) then
              sigma = sign(one,a)
           else
              sigma = sign(one,b)
           end if
           r = sigma*( scl*sqrt((a/scl)**2 + (b/scl)**2) )
           c = a/r
           s = b/r
           if( anorm > bnorm ) then
              z = s
           else if( c /= zero ) then
              z = one/c
           else
              z = one
           end if
           a = r
           b = z
        end if
        return
     end subroutine stdlib_srotg