3 /* Subroutine */ int slarfg_(integer *n, real *alpha, real *x, integer *incx,
6 /* System generated locals */
10 /* Builtin functions */
11 double r_sign(real *, real *);
16 extern doublereal snrm2_(integer *, real *, integer *);
17 extern /* Subroutine */ int sscal_(integer *, real *, real *, integer *);
19 extern doublereal slapy2_(real *, real *), slamch_(char *);
23 /* -- LAPACK auxiliary routine (version 3.1) -- */
24 /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
27 /* .. Scalar Arguments .. */
29 /* .. Array Arguments .. */
35 /* SLARFG generates a real elementary reflector H of order n, such */
38 /* H * ( alpha ) = ( beta ), H' * H = I. */
41 /* where alpha and beta are scalars, and x is an (n-1)-element real */
42 /* vector. H is represented in the form */
44 /* H = I - tau * ( 1 ) * ( 1 v' ) , */
47 /* where tau is a real scalar and v is a real (n-1)-element */
50 /* If the elements of x are all zero, then tau = 0 and H is taken to be */
51 /* the unit matrix. */
53 /* Otherwise 1 <= tau <= 2. */
58 /* N (input) INTEGER */
59 /* The order of the elementary reflector. */
61 /* ALPHA (input/output) REAL */
62 /* On entry, the value alpha. */
63 /* On exit, it is overwritten with the value beta. */
65 /* X (input/output) REAL array, dimension */
66 /* (1+(N-2)*abs(INCX)) */
67 /* On entry, the vector x. */
68 /* On exit, it is overwritten with the vector v. */
70 /* INCX (input) INTEGER */
71 /* The increment between elements of X. INCX > 0. */
73 /* TAU (output) REAL */
76 /* ===================================================================== */
78 /* .. Parameters .. */
80 /* .. Local Scalars .. */
82 /* .. External Functions .. */
84 /* .. Intrinsic Functions .. */
86 /* .. External Subroutines .. */
88 /* .. Executable Statements .. */
90 /* Parameter adjustments */
100 xnorm = snrm2_(&i__1, &x[1], incx);
111 r__1 = slapy2_(alpha, &xnorm);
112 beta = -r_sign(&r__1, alpha);
113 safmin = slamch_("S") / slamch_("E");
114 if (dabs(beta) < safmin) {
116 /* XNORM, BETA may be inaccurate; scale X and recompute them */
118 rsafmn = 1.f / safmin;
123 sscal_(&i__1, &rsafmn, &x[1], incx);
126 if (dabs(beta) < safmin) {
130 /* New BETA is at most 1, at least SAFMIN */
133 xnorm = snrm2_(&i__1, &x[1], incx);
134 r__1 = slapy2_(alpha, &xnorm);
135 beta = -r_sign(&r__1, alpha);
136 *tau = (beta - *alpha) / beta;
138 r__1 = 1.f / (*alpha - beta);
139 sscal_(&i__1, &r__1, &x[1], incx);
141 /* If ALPHA is subnormal, it may lose relative accuracy */
145 for (j = 1; j <= i__1; ++j) {
150 *tau = (beta - *alpha) / beta;
152 r__1 = 1.f / (*alpha - beta);
153 sscal_(&i__1, &r__1, &x[1], incx);