LAPACK  3.10.1
LAPACK: Linear Algebra PACKage
slassq.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 SLASSQ( N, X, INCX, SCALE, SUMSQ )
22 !
23 ! .. Scalar Arguments ..
24 ! INTEGER INCX, N
25 ! REAL SCALE, SUMSQ
26 ! ..
27 ! .. Array Arguments ..
28 ! REAL X( * )
29 ! ..
30 !
31 !
33 ! =============
61 !
62 ! Arguments:
63 ! ==========
64 !
104 !
105 ! Authors:
106 ! ========
107 !
109 !
111 ! ==================
115 !
117 ! =====================
132 !
134 !
135 ! =====================================================================
136 subroutine slassq( n, x, incx, scl, sumsq )
137  use la_constants, &
138  only: wp=>sp, zero=>szero, one=>sone, &
139  sbig=>ssbig, ssml=>sssml, tbig=>stbig, tsml=>stsml
140  use la_xisnan
141 !
142 ! -- LAPACK auxiliary routine --
143 ! -- LAPACK is a software package provided by Univ. of Tennessee, --
144 ! -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
145 !
146 ! .. Scalar Arguments ..
147  integer :: incx, n
148  real(wp) :: scl, sumsq
149 ! ..
150 ! .. Array Arguments ..
151  real(wp) :: x(*)
152 ! ..
153 ! .. Local Scalars ..
154  integer :: i, ix
155  logical :: notbig
156  real(wp) :: abig, amed, asml, ax, ymax, ymin
157 ! ..
158 !
159 ! Quick return if possible
160 !
161  if( la_isnan(scl) .or. la_isnan(sumsq) ) return
162  if( sumsq == zero ) scl = one
163  if( scl == zero ) then
164  scl = one
165  sumsq = zero
166  end if
167  if (n <= 0) then
168  return
169  end if
170 !
171 ! Compute the sum of squares in 3 accumulators:
172 ! abig -- sums of squares scaled down to avoid overflow
173 ! asml -- sums of squares scaled up to avoid underflow
174 ! amed -- sums of squares that do not require scaling
175 ! The thresholds and multipliers are
176 ! tbig -- values bigger than this are scaled down by sbig
177 ! tsml -- values smaller than this are scaled up by ssml
178 !
179  notbig = .true.
180  asml = zero
181  amed = zero
182  abig = zero
183  ix = 1
184  if( incx < 0 ) ix = 1 - (n-1)*incx
185  do i = 1, n
186  ax = abs(x(ix))
187  if (ax > tbig) then
188  abig = abig + (ax*sbig)**2
189  notbig = .false.
190  else if (ax < tsml) then
191  if (notbig) asml = asml + (ax*ssml)**2
192  else
193  amed = amed + ax**2
194  end if
195  ix = ix + incx
196  end do
197 !
198 ! Put the existing sum of squares into one of the accumulators
199 !
200  if( sumsq > zero ) then
201  ax = scl*sqrt( sumsq )
202  if (ax > tbig) then
203 ! We assume scl >= sqrt( TINY*EPS ) / sbig
204  abig = abig + (scl*sbig)**2 * sumsq
205  else if (ax < tsml) then
206 ! We assume scl <= sqrt( HUGE ) / ssml
207  if (notbig) asml = asml + (scl*ssml)**2 * sumsq
208  else
209  amed = amed + scl**2 * sumsq
210  end if
211  end if
212 !
213 ! Combine abig and amed or amed and asml if more than one
214 ! accumulator was used.
215 !
216  if (abig > zero) then
217 !
218 ! Combine abig and amed if abig > 0.
219 !
220  if (amed > zero .or. la_isnan(amed)) then
221  abig = abig + (amed*sbig)*sbig
222  end if
223  scl = one / sbig
224  sumsq = abig
225  else if (asml > zero) then
226 !
227 ! Combine amed and asml if asml > 0.
228 !
229  if (amed > zero .or. la_isnan(amed)) then
230  amed = sqrt(amed)
231  asml = sqrt(asml) / ssml
232  if (asml > amed) then
233  ymin = amed
234  ymax = asml
235  else
236  ymin = asml
237  ymax = amed
238  end if
239  scl = one
240  sumsq = ymax**2*( one + (ymin/ymax)**2 )
241  else
242  scl = one / ssml
243  sumsq = asml
244  end if
245  else
246 !
247 ! Otherwise all values are mid-range or zero
248 !
249  scl = one
250  sumsq = amed
251  end if
252  return
253 end subroutine
subroutine slassq(n, x, incx, scl, sumsq)
SLASSQ updates a sum of squares represented in scaled form.
Definition: slassq.f90:137
real(sp), parameter stbig
real(sp), parameter sssml
real(sp), parameter sone
real(sp), parameter stsml
real(sp), parameter ssbig
integer, parameter sp
real(sp), parameter szero
LA_CONSTANTS is a module for the scaling constants for the compiled Fortran single and double precisi...