LAPACK 3.12.0
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches

◆ crscl()

subroutine crscl ( integer  n,
complex  a,
complex, dimension( * )  x,
integer  incx 
)

CRSCL multiplies a vector by the reciprocal of a real scalar.

Download CRSCL + dependencies [TGZ] [ZIP] [TXT]

Purpose:
 CRSCL multiplies an n-element complex vector x by the complex scalar
 1/a.  This is done without overflow or underflow as long as
 the final result x/a does not overflow or underflow.
Parameters
[in]N
          N is INTEGER
          The number of components of the vector x.
[in]A
          A is COMPLEX
          The scalar a which is used to divide each component of x.
          A must not be 0, or the subroutine will divide by zero.
[in,out]X
          X is COMPLEX array, dimension
                         (1+(N-1)*abs(INCX))
          The n-element vector x.
[in]INCX
          INCX is INTEGER
          The increment between successive values of the vector X.
          > 0:  X(1) = X(1) and X(1+(i-1)*INCX) = x(i),     1< i<= n
Author
Univ. of Tennessee
Univ. of California Berkeley
Univ. of Colorado Denver
NAG Ltd.

Definition at line 83 of file crscl.f.

84*
85* -- LAPACK auxiliary routine --
86* -- LAPACK is a software package provided by Univ. of Tennessee, --
87* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
88*
89* .. Scalar Arguments ..
90 INTEGER INCX, N
91 COMPLEX A
92* ..
93* .. Array Arguments ..
94 COMPLEX X( * )
95* ..
96*
97* =====================================================================
98*
99* .. Parameters ..
100 REAL ZERO, ONE
101 parameter( zero = 0.0e+0, one = 1.0e+0 )
102* ..
103* .. Local Scalars ..
104 REAL SAFMAX, SAFMIN, OV, AR, AI, ABSR, ABSI, UR
105 % , UI
106* ..
107* .. External Functions ..
108 REAL SLAMCH
109 COMPLEX CLADIV
110 EXTERNAL slamch, cladiv
111* ..
112* .. External Subroutines ..
113 EXTERNAL cscal, csscal, csrscl
114* ..
115* .. Intrinsic Functions ..
116 INTRINSIC abs
117* ..
118* .. Executable Statements ..
119*
120* Quick return if possible
121*
122 IF( n.LE.0 )
123 $ RETURN
124*
125* Get machine parameters
126*
127 safmin = slamch( 'S' )
128 safmax = one / safmin
129 ov = slamch( 'O' )
130*
131* Initialize constants related to A.
132*
133 ar = real( a )
134 ai = aimag( a )
135 absr = abs( ar )
136 absi = abs( ai )
137*
138 IF( ai.EQ.zero ) THEN
139* If alpha is real, then we can use csrscl
140 CALL csrscl( n, ar, x, incx )
141*
142 ELSE IF( ar.EQ.zero ) THEN
143* If alpha has a zero real part, then we follow the same rules as if
144* alpha were real.
145 IF( absi.GT.safmax ) THEN
146 CALL csscal( n, safmin, x, incx )
147 CALL cscal( n, cmplx( zero, -safmax / ai ), x, incx )
148 ELSE IF( absi.LT.safmin ) THEN
149 CALL cscal( n, cmplx( zero, -safmin / ai ), x, incx )
150 CALL csscal( n, safmax, x, incx )
151 ELSE
152 CALL cscal( n, cmplx( zero, -one / ai ), x, incx )
153 END IF
154*
155 ELSE
156* The following numbers can be computed.
157* They are the inverse of the real and imaginary parts of 1/alpha.
158* Note that a and b are always different from zero.
159* NaNs are only possible if either:
160* 1. alphaR or alphaI is NaN.
161* 2. alphaR and alphaI are both infinite, in which case it makes sense
162* to propagate a NaN.
163 ur = ar + ai * ( ai / ar )
164 ui = ai + ar * ( ar / ai )
165*
166 IF( (abs( ur ).LT.safmin).OR.(abs( ui ).LT.safmin) ) THEN
167* This means that both alphaR and alphaI are very small.
168 CALL cscal( n, cmplx( safmin / ur, -safmin / ui ), x, incx )
169 CALL csscal( n, safmax, x, incx )
170 ELSE IF( (abs( ur ).GT.safmax).OR.(abs( ui ).GT.safmax) ) THEN
171 IF( (absr.GT.ov).OR.(absi.GT.ov) ) THEN
172* This means that a and b are both Inf. No need for scaling.
173 CALL cscal( n, cmplx( one / ur, -one / ui ), x, incx )
174 ELSE
175 CALL csscal( n, safmin, x, incx )
176 IF( (abs( ur ).GT.ov).OR.(abs( ui ).GT.ov) ) THEN
177* Infs were generated. We do proper scaling to avoid them.
178 IF( absr.GE.absi ) THEN
179* ABS( UR ) <= ABS( UI )
180 ur = (safmin * ar) + safmin * (ai * ( ai / ar ))
181 ui = (safmin * ai) + ar * ( (safmin * ar) / ai )
182 ELSE
183* ABS( UR ) > ABS( UI )
184 ur = (safmin * ar) + ai * ( (safmin * ai) / ar )
185 ui = (safmin * ai) + safmin * (ar * ( ar / ai ))
186 END IF
187 CALL cscal( n, cmplx( one / ur, -one / ui ), x, 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*
complex function cladiv(x, y)
CLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.
Definition cladiv.f:64
real function slamch(cmach)
SLAMCH
Definition slamch.f:68
subroutine csrscl(n, sa, sx, incx)
CSRSCL multiplies a vector by the reciprocal of a real scalar.
Definition csrscl.f:84
subroutine csscal(n, sa, cx, incx)
CSSCAL
Definition csscal.f:78
subroutine cscal(n, ca, cx, incx)
CSCAL
Definition cscal.f:78
Here is the call graph for this function:
Here is the caller graph for this function: