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