LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
crscl.f
Go to the documentation of this file.
1*> \brief \b CRSCL multiplies a vector by the reciprocal of a real scalar.
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CRSCL + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/crscl.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/crscl.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/crscl.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CRSCL( N, A, X, INCX )
20*
21* .. Scalar Arguments ..
22* INTEGER INCX, N
23* COMPLEX A
24* ..
25* .. Array Arguments ..
26* COMPLEX X( * )
27* ..
28*
29*
30*> \par Purpose:
31* =============
32*>
33*> \verbatim
34*>
35*> CRSCL multiplies an n-element complex vector x by the complex scalar
36*> 1/a. This is done without overflow or underflow as long as
37*> the final result x/a does not overflow or underflow.
38*> \endverbatim
39*
40* Arguments:
41* ==========
42*
43*> \param[in] N
44*> \verbatim
45*> N is INTEGER
46*> The number of components of the vector x.
47*> \endverbatim
48*>
49*> \param[in] A
50*> \verbatim
51*> A is COMPLEX
52*> The scalar a which is used to divide each component of x.
53*> A must not be 0, or the subroutine will divide by zero.
54*> \endverbatim
55*>
56*> \param[in,out] X
57*> \verbatim
58*> X is COMPLEX array, dimension
59*> (1+(N-1)*abs(INCX))
60*> The n-element vector x.
61*> \endverbatim
62*>
63*> \param[in] INCX
64*> \verbatim
65*> INCX is INTEGER
66*> The increment between successive values of the vector X.
67*> > 0: X(1) = X(1) and X(1+(i-1)*INCX) = x(i), 1< i<= n
68*> \endverbatim
69*
70* Authors:
71* ========
72*
73*> \author Univ. of Tennessee
74*> \author Univ. of California Berkeley
75*> \author Univ. of Colorado Denver
76*> \author NAG Ltd.
77*
78*> \ingroup complexOTHERauxiliary
79*
80* =====================================================================
81 SUBROUTINE crscl( N, A, X, INCX )
82*
83* -- LAPACK auxiliary routine --
84* -- LAPACK is a software package provided by Univ. of Tennessee, --
85* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
86*
87* .. Scalar Arguments ..
88 INTEGER INCX, N
89 COMPLEX A
90* ..
91* .. Array Arguments ..
92 COMPLEX X( * )
93* ..
94*
95* =====================================================================
96*
97* .. Parameters ..
98 REAL ZERO, ONE
99 parameter( zero = 0.0e+0, one = 1.0e+0 )
100* ..
101* .. Local Scalars ..
102 REAL SAFMAX, SAFMIN, OV, AR, AI, ABSR, ABSI, UR
103 % , UI
104* ..
105* .. External Functions ..
106 REAL SLAMCH
107 COMPLEX CLADIV
108 EXTERNAL slamch, cladiv
109* ..
110* .. External Subroutines ..
111 EXTERNAL cscal, csscal, csrscl
112* ..
113* .. Intrinsic Functions ..
114 INTRINSIC abs
115* ..
116* .. Executable Statements ..
117*
118* Quick return if possible
119*
120 IF( n.LE.0 )
121 $ RETURN
122*
123* Get machine parameters
124*
125 safmin = slamch( 'S' )
126 safmax = one / safmin
127 ov = slamch( 'O' )
128*
129* Initialize constants related to A.
130*
131 ar = real( a )
132 ai = aimag( a )
133 absr = abs( ar )
134 absi = abs( ai )
135*
136 IF( ai.EQ.zero ) THEN
137* If alpha is real, then we can use csrscl
138 CALL csrscl( n, ar, x, incx )
139*
140 ELSE IF( ar.EQ.zero ) THEN
141* If alpha has a zero real part, then we follow the same rules as if
142* alpha were real.
143 IF( absi.GT.safmax ) THEN
144 CALL csscal( n, safmin, x, incx )
145 CALL cscal( n, cmplx( zero, -safmax / ai ), x, incx )
146 ELSE IF( absi.LT.safmin ) THEN
147 CALL cscal( n, cmplx( zero, -safmin / ai ), x, incx )
148 CALL csscal( n, safmax, x, incx )
149 ELSE
150 CALL cscal( n, cmplx( zero, -one / ai ), x, incx )
151 END IF
152*
153 ELSE
154* The following numbers can be computed.
155* They are the inverse of the real and imaginary parts of 1/alpha.
156* Note that a and b are always different from zero.
157* NaNs are only possible if either:
158* 1. alphaR or alphaI is NaN.
159* 2. alphaR and alphaI are both infinite, in which case it makes sense
160* to propagate a NaN.
161 ur = ar + ai * ( ai / ar )
162 ui = ai + ar * ( ar / ai )
163*
164 IF( (abs( ur ).LT.safmin).OR.(abs( ui ).LT.safmin) ) THEN
165* This means that both alphaR and alphaI are very small.
166 CALL cscal( n, cmplx( safmin / ur, -safmin / ui ), x,
167 $ incx )
168 CALL csscal( n, safmax, x, incx )
169 ELSE IF( (abs( ur ).GT.safmax).OR.(abs( ui ).GT.safmax) ) THEN
170 IF( (absr.GT.ov).OR.(absi.GT.ov) ) THEN
171* This means that a and b are both Inf. No need for scaling.
172 CALL cscal( n, cmplx( one / ur, -one / ui ), x, incx )
173 ELSE
174 CALL csscal( n, safmin, x, incx )
175 IF( (abs( ur ).GT.ov).OR.(abs( ui ).GT.ov) ) THEN
176* Infs were generated. We do proper scaling to avoid them.
177 IF( absr.GE.absi ) THEN
178* ABS( UR ) <= ABS( UI )
179 ur = (safmin * ar) + safmin * (ai * ( ai / ar ))
180 ui = (safmin * ai) + ar * ( (safmin * ar) / ai )
181 ELSE
182* ABS( UR ) > ABS( UI )
183 ur = (safmin * ar) + ai * ( (safmin * ai) / ar )
184 ui = (safmin * ai) + safmin * (ar * ( ar / ai ))
185 END IF
186 CALL cscal( n, cmplx( one / ur, -one / ui ), x,
187 $ incx )
188 ELSE
189 CALL cscal( n, cmplx( safmax / ur, -safmax / ui ),
190 $ x, incx )
191 END IF
192 END IF
193 ELSE
194 CALL cscal( n, cmplx( one / ur, -one / ui ), x, incx )
195 END IF
196 END IF
197*
198 RETURN
199*
200* End of CRSCL
201*
202 END
subroutine crscl(n, a, x, incx)
CRSCL multiplies a vector by the reciprocal of a real scalar.
Definition crscl.f:82
subroutine csrscl(n, sa, sx, incx)
CSRSCL multiplies a vector by the reciprocal of a real scalar.
Definition csrscl.f:82
subroutine csscal(n, sa, cx, incx)
CSSCAL
Definition csscal.f:78
subroutine cscal(n, ca, cx, incx)
CSCAL
Definition cscal.f:78