LAPACK  3.10.0
LAPACK: Linear Algebra PACKage
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 !
17 !
18 ! Definition:
19 ! ===========
20 !
21 ! SUBROUTINE ZLASSQ( N, X, INCX, SCALE, SUMSQ )
22 !
23 ! .. Scalar Arguments ..
24 ! INTEGER INCX, N
25 ! DOUBLE PRECISION SCALE, SUMSQ
26 ! ..
27 ! .. Array Arguments ..
28 ! DOUBLE COMPLEX X( * )
29 ! ..
30 !
31 !
33 ! =============
50 !
51 ! Arguments:
52 ! ==========
53 !
93 !
94 ! Authors:
95 ! ========
96 !
98 !
100 ! ==================
104 !
106 ! =====================
121 !
123 !
124 ! =====================================================================
125 subroutine zlassq( n, x, incx, scl, sumsq )
126  use la_constants, &
127  only: wp=>dp, zero=>dzero, one=>done, &
128  sbig=>dsbig, ssml=>dssml, tbig=>dtbig, tsml=>dtsml
129  use la_xisnan
130 !
131 ! -- LAPACK auxiliary routine --
132 ! -- LAPACK is a software package provided by Univ. of Tennessee, --
133 ! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
134 !
135 ! .. Scalar Arguments ..
136  integer :: incx, n
137  real(wp) :: scl, sumsq
138 ! ..
139 ! .. Array Arguments ..
140  complex(wp) :: x(*)
141 ! ..
142 ! .. Local Scalars ..
143  integer :: i, ix
144  logical :: notbig
145  real(wp) :: abig, amed, asml, ax, ymax, ymin
146 ! ..
147 !
148 ! Quick return if possible
149 !
150  if( la_isnan(scl) .or. la_isnan(sumsq) ) return
151  if( sumsq == zero ) scl = one
152  if( scl == zero ) then
153  scl = one
154  sumsq = zero
155  end if
156  if (n <= 0) then
157  return
158  end if
159 !
160 ! Compute the sum of squares in 3 accumulators:
161 ! abig -- sums of squares scaled down to avoid overflow
162 ! asml -- sums of squares scaled up to avoid underflow
163 ! amed -- sums of squares that do not require scaling
164 ! The thresholds and multipliers are
165 ! tbig -- values bigger than this are scaled down by sbig
166 ! tsml -- values smaller than this are scaled up by ssml
167 !
168  notbig = .true.
169  asml = zero
170  amed = zero
171  abig = zero
172  ix = 1
173  if( incx < 0 ) ix = 1 - (n-1)*incx
174  do i = 1, n
175  ax = abs(real(x(ix)))
176  if (ax > tbig) then
177  abig = abig + (ax*sbig)**2
178  notbig = .false.
179  else if (ax < tsml) then
180  if (notbig) asml = asml + (ax*ssml)**2
181  else
182  amed = amed + ax**2
183  end if
184  ax = abs(aimag(x(ix)))
185  if (ax > tbig) then
186  abig = abig + (ax*sbig)**2
187  notbig = .false.
188  else if (ax < tsml) then
189  if (notbig) asml = asml + (ax*ssml)**2
190  else
191  amed = amed + ax**2
192  end if
193  ix = ix + incx
194  end do
195 !
196 ! Put the existing sum of squares into one of the accumulators
197 !
198  if( sumsq > zero ) then
199  ax = scl*sqrt( sumsq )
200  if (ax > tbig) then
201  abig = abig + (ax*sbig)**2
202  notbig = .false.
203  else if (ax < tsml) then
204  if (notbig) asml = asml + (ax*ssml)**2
205  else
206  amed = amed + ax**2
207  end if
208  end if
209 !
210 ! Combine abig and amed or amed and asml if more than one
211 ! accumulator was used.
212 !
213  if (abig > zero) then
214 !
215 ! Combine abig and amed if abig > 0.
216 !
217  if (amed > zero .or. la_isnan(amed)) then
218  abig = abig + (amed*sbig)*sbig
219  end if
220  scl = one / sbig
221  sumsq = abig
222  else if (asml > zero) then
223 !
224 ! Combine amed and asml if asml > 0.
225 !
226  if (amed > zero .or. la_isnan(amed)) then
227  amed = sqrt(amed)
228  asml = sqrt(asml) / ssml
229  if (asml > amed) then
230  ymin = amed
231  ymax = asml
232  else
233  ymin = asml
234  ymax = amed
235  end if
236  scl = one
237  sumsq = ymax**2*( one + (ymin/ymax)**2 )
238  else
239  scl = one / ssml
240  sumsq = asml
241  end if
242  else
243 !
244 ! Otherwise all values are mid-range or zero
245 !
246  scl = one
247  sumsq = amed
248  end if
249  return
250 end subroutine
subroutine zlassq(n, x, incx, scl, sumsq)
ZLASSQ updates a sum of squares represented in scaled form.
Definition: zlassq.f90:126
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...