SUBROUTINE CLARTG( F, G, CS, SN, R ) * * -- LAPACK auxiliary routine (version 2.0) -- * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., * Courant Institute, Argonne National Lab, and Rice University * September 30, 1994 * 9-15-00: New version continuous in R (eca) * 12-4-00: Give D the sign of Re(f) for |g| > |f| (eca) * * .. Scalar Arguments .. REAL CS COMPLEX F, G, R, SN * .. * * Purpose * ======= * * CLARTG generates a plane rotation so that * * [ CS SN ] . [ F ] = [ R ] * [ -conjg(SN) CS ] [ G ] [ 0 ] * * where CS**2 + |SN|**2 = 1 and Re(R) >= 0. * * The mathematical formulas used for CS and SN are * * sgn(x) = { x / |x|, x != 0 * { 1, x = 0 * * R = sgn(Re(F)) * sgn(F) * sqrt(|F|**2 + |G|**2) * * CS = F / R = sgn(Re(F)) * |F| / sqrt(|F|**2 + |G|**2) * * SN = conjg(G) / conjg(R) * = sgn(Re(F)) * sgn(F) * conjg(G) / sqrt(|F|**2 + |G|**2) * * 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 differs from previous implementations in the BLAS, * EISPACK (in-line), and LAPACK in that the formula used to compute * R is continuous, so that small perturbations in F and G will not * cause CS, SN, and R to change sign. * * Arguments * ========= * * F (input) COMPLEX * The first component of vector to be rotated. * * G (input) COMPLEX * The second component of vector to be rotated. * * CS (output) REAL * The cosine of the rotation. * * SN (output) COMPLEX * The sine of the rotation. * * R (output) COMPLEX * The nonzero component of the rotated vector. * * ===================================================================== * * .. Parameters .. REAL ONE, ZERO PARAMETER ( ONE = 1.0E+0, ZERO = 0.0E+0 ) COMPLEX CZERO PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ) ) * .. * .. Local Scalars .. REAL D, F1, F2, G1, G2 COMPLEX FS, GS, T * .. * .. Intrinsic Functions .. INTRINSIC ABS, AIMAG, CONJG, REAL, SIGN, SQRT * .. * .. Statement Functions .. REAL ABS1, ABSSQ * .. * .. Statement Function definitions .. ABS1( T ) = ABS( REAL( T ) ) + ABS( AIMAG( T ) ) ABSSQ( T ) = REAL( T )**2 + AIMAG( T )**2 * .. * .. Executable Statements .. * IF( G.EQ.CZERO ) THEN CS = SIGN( ONE, REAL(F) ) SN = CZERO R = F*CS ELSE IF( F.EQ.CZERO ) THEN CS = ZERO SN = CONJG( G ) / ABS( G ) R = ABS( G ) ELSE F1 = ABS1( F ) G1 = ABS1( G ) IF( F1.GE.G1 ) THEN FS = F / F1 F2 = ABSSQ( FS ) GS = G / F1 G2 = ABSSQ( GS ) D = SIGN( SQRT( ONE + G2 / F2 ), REAL(F) ) CS = ONE / D SN = CONJG( GS )*FS*( CS / F2 ) R = F*D ELSE FS = F / G1 F2 = ABSSQ( FS ) GS = G / G1 G2 = ABSSQ( GS ) D = SIGN( G1*SQRT( F2 + G2 ), REAL(F) ) F1 = ABS( F ) FS = F / F1 CS = F1 / D SN = ( CONJG( G ) / D )*FS R = FS*D END IF END IF RETURN * * End of CLARTG * END