SUBROUTINE SLARTG( F, G, CS, SN, R ) * * -- LAPACK auxiliary routine (version 3.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) * * .. Scalar Arguments .. REAL CS, F, G, R, SN * .. * * Purpose * ======= * * SLARTG generates a plane rotation so that * * [ CS SN ] . [ F ] = [ R ] * [ -SN CS ] [ G ] [ 0 ] * * where CS**2 + SN**2 = 1 and R >= 0. * * The mathematical formulas used for CS and SN are * R = sqrt(F**2 + G**2) * CS = F / R * SN = G / R * Thus CS has the same sign as F, SN has the same sign as G, and R is * always positive. 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) REAL * The first component of vector to be rotated. * * G (input) REAL * The second component of vector to be rotated. * * CS (output) REAL * The cosine of the rotation. * * SN (output) REAL * The sine of the rotation. * * R (output) REAL * The nonzero component of the rotated vector. * * ===================================================================== * * .. Parameters .. REAL ZERO PARAMETER ( ZERO = 0.0E0 ) REAL ONE PARAMETER ( ONE = 1.0E0 ) * .. * .. Local Scalars .. REAL FABS, GABS, T, TT * .. * .. Intrinsic Functions .. INTRINSIC ABS, SIGN, SQRT * .. * .. Executable Statements .. * FABS = ABS( F ) GABS = ABS( G ) IF( G.EQ.ZERO ) THEN CS = SIGN( ONE, F ) SN = ZERO R = FABS ELSE IF( F.EQ.ZERO ) THEN CS = ZERO SN = SIGN( ONE, G ) R = GABS ELSE IF( FABS.GT.GABS ) THEN T = G / F TT = SIGN( SQRT( ONE+T*T ), F ) CS = ONE / TT SN = T*CS R = F*TT ELSE T = F / G TT = SIGN( SQRT( ONE+T*T ), G ) SN = ONE / TT CS = T*SN R = G*TT END IF RETURN END