LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
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!
15!
16! Definition:
17! ===========
18!
19! SUBROUTINE SLASSQ( N, X, INCX, SCALE, SUMSQ )
20!
21! .. Scalar Arguments ..
22! INTEGER INCX, N
23! REAL SCALE, SUMSQ
24! ..
25! .. Array Arguments ..
26! REAL X( * )
27! ..
28!
29!
31! =============
46!
47! Arguments:
48! ==========
49!
89!
90! Authors:
91! ========
92!
94!
96! ==================
100!
102! =====================
117!
119!
120! =====================================================================
121subroutine slassq( n, x, incx, scale, sumsq )
122 use la_constants, &
123 only: wp=>sp, zero=>szero, one=>sone, &
124 sbig=>ssbig, ssml=>sssml, tbig=>stbig, tsml=>stsml
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 real(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(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 ix = ix + incx
181 end do
182!
183! Put the existing sum of squares into one of the accumulators
184!
185 if( sumsq > zero ) then
186 ax = scale*sqrt( sumsq )
187 if (ax > tbig) then
188 if (scale > one) then
189 scale = scale * sbig
190 abig = abig + scale * (scale * sumsq)
191 else
192 ! sumsq > tbig^2 => (sbig * (sbig * sumsq)) is representable
193 abig = abig + scale * (scale * (sbig * (sbig * sumsq)))
194 end if
195 else if (ax < tsml) then
196 if (notbig) then
197 if (scale < one) then
198 scale = scale * ssml
199 asml = asml + scale * (scale * sumsq)
200 else
201 ! sumsq < tsml^2 => (ssml * (ssml * sumsq)) is representable
202 asml = asml + scale * (scale * (ssml * (ssml * sumsq)))
203 end if
204 end if
205 else
206 amed = amed + scale * (scale * sumsq)
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 scale = 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 scale = one
237 sumsq = ymax**2*( one + (ymin/ymax)**2 )
238 else
239 scale = one / ssml
240 sumsq = asml
241 end if
242 else
243!
244! Otherwise all values are mid-range or zero
245!
246 scale = one
247 sumsq = amed
248 end if
249 return
250end subroutine
subroutine slassq(n, x, incx, scale, sumsq)
SLASSQ updates a sum of squares represented in scaled form.
Definition slassq.f90:122
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...