82
83
84
85
86
87
88 INTEGER INCX, N
89 COMPLEX A
90
91
92 COMPLEX X( * )
93
94
95
96
97
98 REAL ZERO, ONE
99 parameter( zero = 0.0e+0, one = 1.0e+0 )
100
101
102 REAL SAFMAX, SAFMIN, OV, AR, AI, ABSR, ABSI, UR
103 % , UI
104
105
106 REAL SLAMCH
107 COMPLEX CLADIV
109
110
112
113
114 INTRINSIC abs
115
116
117
118
119
120 IF( n.LE.0 )
121 $ RETURN
122
123
124
126 safmax = one / safmin
128
129
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
138 CALL csrscl( n, ar, x, incx )
139
140 ELSE IF( ar.EQ.zero ) THEN
141
142
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
155
156
157
158
159
160
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
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
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
177 IF( absr.GE.absi ) THEN
178
179 ur = (safmin * ar) + safmin * (ai * ( ai / ar ))
180 ui = (safmin * ai) + ar * ( (safmin * ar) / ai )
181 ELSE
182
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
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