LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
zlassq.f90
Go to the documentation of this file.
1
2!
3! =========== DOCUMENTATION ===========
4!
5! Online html documentation available at
6! http://www.netlib.org/lapack/explore-html/
7!
15!
16! Definition:
17! ===========
18!
19! SUBROUTINE ZLASSQ( N, X, INCX, SCALE, SUMSQ )
20!
21! .. Scalar Arguments ..
22! INTEGER INCX, N
23! DOUBLE PRECISION SCALE, SUMSQ
24! ..
25! .. Array Arguments ..
26! DOUBLE COMPLEX X( * )
27! ..
28!
29!
31! =============
46!
47! Arguments:
48! ==========
49!
89!
90! Authors:
91! ========
92!
94!
96! ==================
100!
102! =====================
117!
119!
120! =====================================================================
121subroutine zlassq( n, x, incx, scale, sumsq )
122 use la_constants, &
123 only: wp=>dp, zero=>dzero, one=>done, &
124 sbig=>dsbig, ssml=>dssml, tbig=>dtbig, tsml=>dtsml
125 use la_xisnan
126!
127! -- LAPACK auxiliary routine --
128! -- LAPACK is a software package provided by Univ. of Tennessee, --
129! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
130!
131! .. Scalar Arguments ..
132 integer :: incx, n
133 real(wp) :: scale, sumsq
134! ..
135! .. Array Arguments ..
136 complex(wp) :: x(*)
137! ..
138! .. Local Scalars ..
139 integer :: i, ix
140 logical :: notbig
141 real(wp) :: abig, amed, asml, ax, ymax, ymin
142! ..
143!
144! Quick return if possible
145!
146 if( la_isnan(scale) .or. la_isnan(sumsq) ) return
147 if( sumsq == zero ) scale = one
148 if( scale == zero ) then
149 scale = one
150 sumsq = zero
151 end if
152 if (n <= 0) then
153 return
154 end if
155!
156! Compute the sum of squares in 3 accumulators:
157! abig -- sums of squares scaled down to avoid overflow
158! asml -- sums of squares scaled up to avoid underflow
159! amed -- sums of squares that do not require scaling
160! The thresholds and multipliers are
161! tbig -- values bigger than this are scaled down by sbig
162! tsml -- values smaller than this are scaled up by ssml
163!
164 notbig = .true.
165 asml = zero
166 amed = zero
167 abig = zero
168 ix = 1
169 if( incx < 0 ) ix = 1 - (n-1)*incx
170 do i = 1, n
171 ax = abs(real(x(ix)))
172 if (ax > tbig) then
173 abig = abig + (ax*sbig)**2
174 notbig = .false.
175 else if (ax < tsml) then
176 if (notbig) asml = asml + (ax*ssml)**2
177 else
178 amed = amed + ax**2
179 end if
180 ax = abs(aimag(x(ix)))
181 if (ax > tbig) then
182 abig = abig + (ax*sbig)**2
183 notbig = .false.
184 else if (ax < tsml) then
185 if (notbig) asml = asml + (ax*ssml)**2
186 else
187 amed = amed + ax**2
188 end if
189 ix = ix + incx
190 end do
191!
192! Put the existing sum of squares into one of the accumulators
193!
194 if( sumsq > zero ) then
195 ax = scale*sqrt( sumsq )
196 if (ax > tbig) then
197 if (scale > one) then
198 scale = scale * sbig
199 abig = abig + scale * (scale * sumsq)
200 else
201 ! sumsq > tbig^2 => (sbig * (sbig * sumsq)) is representable
202 abig = abig + scale * (scale * (sbig * (sbig * sumsq)))
203 end if
204 else if (ax < tsml) then
205 if (notbig) then
206 if (scale < one) then
207 scale = scale * ssml
208 asml = asml + scale * (scale * sumsq)
209 else
210 ! sumsq < tsml^2 => (ssml * (ssml * sumsq)) is representable
211 asml = asml + scale * (scale * (ssml * (ssml * sumsq)))
212 end if
213 end if
214 else
215 amed = amed + scale * (scale * sumsq)
216 end if
217 end if
218!
219! Combine abig and amed or amed and asml if more than one
220! accumulator was used.
221!
222 if (abig > zero) then
223!
224! Combine abig and amed if abig > 0.
225!
226 if (amed > zero .or. la_isnan(amed)) then
227 abig = abig + (amed*sbig)*sbig
228 end if
229 scale = one / sbig
230 sumsq = abig
231 else if (asml > zero) then
232!
233! Combine amed and asml if asml > 0.
234!
235 if (amed > zero .or. la_isnan(amed)) then
236 amed = sqrt(amed)
237 asml = sqrt(asml) / ssml
238 if (asml > amed) then
239 ymin = amed
240 ymax = asml
241 else
242 ymin = asml
243 ymax = amed
244 end if
245 scale = one
246 sumsq = ymax**2*( one + (ymin/ymax)**2 )
247 else
248 scale = one / ssml
249 sumsq = asml
250 end if
251 else
252!
253! Otherwise all values are mid-range or zero
254!
255 scale = one
256 sumsq = amed
257 end if
258 return
259end subroutine
subroutine zlassq(n, x, incx, scale, sumsq)
ZLASSQ updates a sum of squares represented in scaled form.
Definition zlassq.f90:122
real(dp), parameter dtsml
real(dp), parameter dzero
real(dp), parameter dsbig
integer, parameter dp
real(dp), parameter done
real(dp), parameter dtbig
real(dp), parameter dssml
LA_CONSTANTS is a module for the scaling constants for the compiled Fortran single and double precisi...