LAPACK  3.10.0
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 ! =============
50 !
51 ! Arguments:
52 ! ==========
53 !
93 !
94 ! Authors:
95 ! ========
96 !
98 !
100 ! ==================
104 !
106 ! =====================
121 !
123 !
124 ! =====================================================================
125 subroutine slassq( n, x, incx, scl, sumsq )
126  use la_constants, &
127  only: wp=>sp, zero=>szero, one=>sone, &
128  sbig=>ssbig, ssml=>sssml, tbig=>stbig, tsml=>stsml
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  real(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(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  ix = ix + incx
185  end do
186 !
187 ! Put the existing sum of squares into one of the accumulators
188 !
189  if( sumsq > zero ) then
190  ax = scl*sqrt( sumsq )
191  if (ax > tbig) then
192  abig = abig + (ax*sbig)**2
193  notbig = .false.
194  else if (ax < tsml) then
195  if (notbig) asml = asml + (ax*ssml)**2
196  else
197  amed = amed + ax**2
198  end if
199  end if
200 !
201 ! Combine abig and amed or amed and asml if more than one
202 ! accumulator was used.
203 !
204  if (abig > zero) then
205 !
206 ! Combine abig and amed if abig > 0.
207 !
208  if (amed > zero .or. la_isnan(amed)) then
209  abig = abig + (amed*sbig)*sbig
210  end if
211  scl = one / sbig
212  sumsq = abig
213  else if (asml > zero) then
214 !
215 ! Combine amed and asml if asml > 0.
216 !
217  if (amed > zero .or. la_isnan(amed)) then
218  amed = sqrt(amed)
219  asml = sqrt(asml) / ssml
220  if (asml > amed) then
221  ymin = amed
222  ymax = asml
223  else
224  ymin = asml
225  ymax = amed
226  end if
227  scl = one
228  sumsq = ymax**2*( one + (ymin/ymax)**2 )
229  else
230  scl = one / ssml
231  sumsq = asml
232  end if
233  else
234 !
235 ! Otherwise all values are mid-range or zero
236 !
237  scl = one
238  sumsq = amed
239  end if
240  return
241 end subroutine
subroutine slassq(n, x, incx, scl, sumsq)
SLASSQ updates a sum of squares represented in scaled form.
Definition: slassq.f90:126
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...