Skip to content

Commit e7d572c

Browse files
Improve xSLASSQ by removing one operation like sqrt( sumsq )**2
!> If scale * sqrt( sumsq ) > tbig then !> we now require: scale >= sqrt( TINY*EPS ) / sbig on entry, !> and if scale * sqrt( sumsq ) < tsml then !> we now require: scale <= sqrt( HUGE ) / ssml on entry, !> where !> tbig -- upper threshold for values whose square is representable; !> sbig -- scaling constant for big numbers; \see la_constants.f90 !> tsml -- lower threshold for values whose square is representable; !> ssml -- scaling constant for small numbers; \see la_constants.f90 !> and !> TINY*EPS -- tiniest representable number; !> HUGE -- biggest representable number.
1 parent 4ea5c1e commit e7d572c

File tree

4 files changed

+76
-24
lines changed

4 files changed

+76
-24
lines changed

SRC/classq.f90

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,24 @@
3939
!> ( scl**2 )*smsq = x( 1 )**2 +...+ x( n )**2 + ( scale**2 )*sumsq,
4040
!>
4141
!> where x( i ) = X( 1 + ( i - 1 )*INCX ). The value of sumsq is
42-
!> assumed to be non-negative and scl returns the value
43-
!>
44-
!> scl = max( scale, abs( x( i ) ) ).
42+
!> assumed to be non-negative.
4543
!>
4644
!> scale and sumsq must be supplied in SCALE and SUMSQ and
4745
!> scl and smsq are overwritten on SCALE and SUMSQ respectively.
4846
!>
47+
!> If scale * sqrt( sumsq ) > tbig then
48+
!> we require: scale >= sqrt( TINY*EPS ) / sbig on entry,
49+
!> and if scale * sqrt( sumsq ) < tsml then
50+
!> we require: scale <= sqrt( HUGE ) / ssml on entry,
51+
!> where
52+
!> tbig -- upper threshold for values whose square is representable;
53+
!> sbig -- scaling constant for big numbers; \see la_constants.f90
54+
!> tsml -- lower threshold for values whose square is representable;
55+
!> ssml -- scaling constant for small numbers; \see la_constants.f90
56+
!> and
57+
!> TINY*EPS -- tiniest representable number;
58+
!> HUGE -- biggest representable number.
59+
!>
4960
!> \endverbatim
5061
!
5162
! Arguments:
@@ -198,12 +209,14 @@ subroutine CLASSQ( n, x, incx, scl, sumsq )
198209
if( sumsq > zero ) then
199210
ax = scl*sqrt( sumsq )
200211
if (ax > tbig) then
201-
abig = abig + (ax*sbig)**2
212+
! We assume scl >= sqrt( TINY*EPS ) / sbig
213+
abig = abig + (scl*sbig)**2 * sumsq
202214
notbig = .false.
203215
else if (ax < tsml) then
204-
if (notbig) asml = asml + (ax*ssml)**2
216+
! We assume scl <= sqrt( HUGE ) / ssml
217+
if (notbig) asml = asml + (scl*ssml)**2 * sumsq
205218
else
206-
amed = amed + ax**2
219+
amed = amed + scl**2 * sumsq
207220
end if
208221
end if
209222
!

SRC/dlassq.f90

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,24 @@
3939
!> ( scl**2 )*smsq = x( 1 )**2 +...+ x( n )**2 + ( scale**2 )*sumsq,
4040
!>
4141
!> where x( i ) = X( 1 + ( i - 1 )*INCX ). The value of sumsq is
42-
!> assumed to be non-negative and scl returns the value
43-
!>
44-
!> scl = max( scale, abs( x( i ) ) ).
42+
!> assumed to be non-negative.
4543
!>
4644
!> scale and sumsq must be supplied in SCALE and SUMSQ and
4745
!> scl and smsq are overwritten on SCALE and SUMSQ respectively.
4846
!>
47+
!> If scale * sqrt( sumsq ) > tbig then
48+
!> we require: scale >= sqrt( TINY*EPS ) / sbig on entry,
49+
!> and if scale * sqrt( sumsq ) < tsml then
50+
!> we require: scale <= sqrt( HUGE ) / ssml on entry,
51+
!> where
52+
!> tbig -- upper threshold for values whose square is representable;
53+
!> sbig -- scaling constant for big numbers; \see la_constants.f90
54+
!> tsml -- lower threshold for values whose square is representable;
55+
!> ssml -- scaling constant for small numbers; \see la_constants.f90
56+
!> and
57+
!> TINY*EPS -- tiniest representable number;
58+
!> HUGE -- biggest representable number.
59+
!>
4960
!> \endverbatim
5061
!
5162
! Arguments:
@@ -189,12 +200,14 @@ subroutine DLASSQ( n, x, incx, scl, sumsq )
189200
if( sumsq > zero ) then
190201
ax = scl*sqrt( sumsq )
191202
if (ax > tbig) then
192-
abig = abig + (ax*sbig)**2
203+
! We assume scl >= sqrt( TINY*EPS ) / sbig
204+
abig = abig + (scl*sbig)**2 * sumsq
193205
notbig = .false.
194206
else if (ax < tsml) then
195-
if (notbig) asml = asml + (ax*ssml)**2
207+
! We assume scl <= sqrt( HUGE ) / ssml
208+
if (notbig) asml = asml + (scl*ssml)**2 * sumsq
196209
else
197-
amed = amed + ax**2
210+
amed = amed + scl**2 * sumsq
198211
end if
199212
end if
200213
!

SRC/slassq.f90

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,24 @@
3939
!> ( scl**2 )*smsq = x( 1 )**2 +...+ x( n )**2 + ( scale**2 )*sumsq,
4040
!>
4141
!> where x( i ) = X( 1 + ( i - 1 )*INCX ). The value of sumsq is
42-
!> assumed to be non-negative and scl returns the value
43-
!>
44-
!> scl = max( scale, abs( x( i ) ) ).
42+
!> assumed to be non-negative.
4543
!>
4644
!> scale and sumsq must be supplied in SCALE and SUMSQ and
4745
!> scl and smsq are overwritten on SCALE and SUMSQ respectively.
4846
!>
47+
!> If scale * sqrt( sumsq ) > tbig then
48+
!> we require: scale >= sqrt( TINY*EPS ) / sbig on entry,
49+
!> and if scale * sqrt( sumsq ) < tsml then
50+
!> we require: scale <= sqrt( HUGE ) / ssml on entry,
51+
!> where
52+
!> tbig -- upper threshold for values whose square is representable;
53+
!> sbig -- scaling constant for big numbers; \see la_constants.f90
54+
!> tsml -- lower threshold for values whose square is representable;
55+
!> ssml -- scaling constant for small numbers; \see la_constants.f90
56+
!> and
57+
!> TINY*EPS -- tiniest representable number;
58+
!> HUGE -- biggest representable number.
59+
!>
4960
!> \endverbatim
5061
!
5162
! Arguments:
@@ -189,12 +200,14 @@ subroutine SLASSQ( n, x, incx, scl, sumsq )
189200
if( sumsq > zero ) then
190201
ax = scl*sqrt( sumsq )
191202
if (ax > tbig) then
192-
abig = abig + (ax*sbig)**2
203+
! We assume scl >= sqrt( TINY*EPS ) / sbig
204+
abig = abig + (scl*sbig)**2 * sumsq
193205
notbig = .false.
194206
else if (ax < tsml) then
195-
if (notbig) asml = asml + (ax*ssml)**2
207+
! We assume scl <= sqrt( HUGE ) / ssml
208+
if (notbig) asml = asml + (scl*ssml)**2 * sumsq
196209
else
197-
amed = amed + ax**2
210+
amed = amed + scl**2 * sumsq
198211
end if
199212
end if
200213
!

SRC/zlassq.f90

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,24 @@
3939
!> ( scl**2 )*smsq = x( 1 )**2 +...+ x( n )**2 + ( scale**2 )*sumsq,
4040
!>
4141
!> where x( i ) = X( 1 + ( i - 1 )*INCX ). The value of sumsq is
42-
!> assumed to be non-negative and scl returns the value
43-
!>
44-
!> scl = max( scale, abs( x( i ) ) ).
42+
!> assumed to be non-negative.
4543
!>
4644
!> scale and sumsq must be supplied in SCALE and SUMSQ and
4745
!> scl and smsq are overwritten on SCALE and SUMSQ respectively.
4846
!>
47+
!> If scale * sqrt( sumsq ) > tbig then
48+
!> we require: scale >= sqrt( TINY*EPS ) / sbig on entry,
49+
!> and if scale * sqrt( sumsq ) < tsml then
50+
!> we require: scale <= sqrt( HUGE ) / ssml on entry,
51+
!> where
52+
!> tbig -- upper threshold for values whose square is representable;
53+
!> sbig -- scaling constant for big numbers; \see la_constants.f90
54+
!> tsml -- lower threshold for values whose square is representable;
55+
!> ssml -- scaling constant for small numbers; \see la_constants.f90
56+
!> and
57+
!> TINY*EPS -- tiniest representable number;
58+
!> HUGE -- biggest representable number.
59+
!>
4960
!> \endverbatim
5061
!
5162
! Arguments:
@@ -198,12 +209,14 @@ subroutine ZLASSQ( n, x, incx, scl, sumsq )
198209
if( sumsq > zero ) then
199210
ax = scl*sqrt( sumsq )
200211
if (ax > tbig) then
201-
abig = abig + (ax*sbig)**2
212+
! We assume scl >= sqrt( TINY*EPS ) / sbig
213+
abig = abig + (scl*sbig)**2 * sumsq
202214
notbig = .false.
203215
else if (ax < tsml) then
204-
if (notbig) asml = asml + (ax*ssml)**2
216+
! We assume scl <= sqrt( HUGE ) / ssml
217+
if (notbig) asml = asml + (scl*ssml)**2 * sumsq
205218
else
206-
amed = amed + ax**2
219+
amed = amed + scl**2 * sumsq
207220
end if
208221
end if
209222
!

0 commit comments

Comments
 (0)