84
85
86
87
88
89
90 INTEGER INCX, N
91 COMPLEX*16 A
92
93
94 COMPLEX*16 X( * )
95
96
97
98
99
100 DOUBLE PRECISION ZERO, ONE
101 parameter( zero = 0.0d+0, one = 1.0d+0 )
102
103
104 DOUBLE PRECISION SAFMAX, SAFMIN, OV, AR, AI, ABSR, ABSI, UR, UI
105
106
107 DOUBLE PRECISION DLAMCH
108 COMPLEX*16 ZLADIV
110
111
113
114
115 INTRINSIC abs
116
117
118
119
120
121 IF( n.LE.0 )
122 $ RETURN
123
124
125
127 safmax = one / safmin
129
130
131
132 ar = dble( a )
133 ai = dimag( a )
134 absr = abs( ar )
135 absi = abs( ai )
136
137 IF( ai.EQ.zero ) THEN
138
139 CALL zdrscl( n, ar, x, incx )
140
141 ELSE IF( ar.EQ.zero ) THEN
142
143
144 IF( absi.GT.safmax ) THEN
145 CALL zdscal( n, safmin, x, incx )
146 CALL zscal( n, dcmplx( zero, -safmax / ai ), x, incx )
147 ELSE IF( absi.LT.safmin ) THEN
148 CALL zscal( n, dcmplx( zero, -safmin / ai ), x, incx )
149 CALL zdscal( n, safmax, x, incx )
150 ELSE
151 CALL zscal( n, dcmplx( zero, -one / ai ), x, incx )
152 END IF
153
154 ELSE
155
156
157
158
159
160
161
162 ur = ar + ai * ( ai / ar )
163 ui = ai + ar * ( ar / ai )
164
165 IF( (abs( ur ).LT.safmin).OR.(abs( ui ).LT.safmin) ) THEN
166
167 CALL zscal( n, dcmplx( safmin / ur, -safmin / ui ), x,
168 $ incx )
169 CALL zdscal( 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 zscal( n, dcmplx( one / ur, -one / ui ), x, incx )
174 ELSE
175 CALL zdscal( 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 zscal( n, dcmplx( one / ur, -one / ui ), x,
188 $ incx )
189 ELSE
190 CALL zscal( n, dcmplx( safmax / ur, -safmax / ui ),
191 $ x, incx )
192 END IF
193 END IF
194 ELSE
195 CALL zscal( n, dcmplx( one / ur, -one / ui ), x, incx )
196 END IF
197 END IF
198
199 RETURN
200
201
202
complex *16 function zladiv(x, y)
ZLADIV performs complex division in real arithmetic, avoiding unnecessary overflow.
double precision function dlamch(cmach)
DLAMCH
subroutine zdrscl(n, sa, sx, incx)
ZDRSCL multiplies a vector by the reciprocal of a real scalar.
subroutine dscal(n, da, dx, incx)
DSCAL
subroutine zdscal(n, da, zx, incx)
ZDSCAL
subroutine zscal(n, za, zx, incx)
ZSCAL