84
85
86
87
88
89
90 INTEGER INCX, N
91 COMPLEX A
92
93
94 COMPLEX X( * )
95
96
97
98
99
100 REAL ZERO, ONE
101 parameter( zero = 0.0e+0, one = 1.0e+0 )
102
103
104 REAL SAFMAX, SAFMIN, OV, AR, AI, ABSR, ABSI, UR
105 % , UI
106
107
108 REAL SLAMCH
109 COMPLEX CLADIV
111
112
114
115
116 INTRINSIC abs
117
118
119
120
121
122 IF( n.LE.0 )
123 $ RETURN
124
125
126
128 safmax = one / safmin
130
131
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
140 CALL csrscl( n, ar, x, incx )
141
142 ELSE IF( ar.EQ.zero ) THEN
143
144
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
157
158
159
160
161
162
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
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
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
178 IF( absr.GE.absi ) THEN
179
180 ur = (safmin * ar) + safmin * (ai * ( ai / ar ))
181 ui = (safmin * ai) + ar * ( (safmin * ar) / ai )
182 ELSE
183
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
201
complex function cladiv(x, y)
CLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.
real function slamch(cmach)
SLAMCH
subroutine csrscl(n, sa, sx, incx)
CSRSCL multiplies a vector by the reciprocal of a real scalar.
subroutine csscal(n, sa, cx, incx)
CSSCAL
subroutine cscal(n, ca, cx, incx)
CSCAL