9 DOUBLE PRECISION FUNCTION dlamch( CMACH )
57 DOUBLE PRECISION one, zero
58 parameter( one = 1.0d+0, zero = 0.0d+0 )
62 INTEGER beta, imax, imin, it
63 DOUBLE PRECISION base, emax, emin, eps, prec, rmach, rmax, rmin,
64 $ rnd, sfmin, small, t
74 SAVE first, eps, sfmin, base, t, rnd, emin, rmin,
84 CALL dlamc2( beta, it, lrnd, eps, imin, rmin, imax, rmax )
89 eps = ( base**( 1-it ) ) / 2
99 IF( small.GE.sfmin )
THEN
104 sfmin = small*( one+eps )
108 IF(
lsame( cmach,
'E' ) )
THEN
110 ELSE IF(
lsame( cmach,
'S' ) )
THEN
112 ELSE IF(
lsame( cmach,
'B' ) )
THEN
114 ELSE IF(
lsame( cmach,
'P' ) )
THEN
116 ELSE IF(
lsame( cmach,
'N' ) )
THEN
118 ELSE IF(
lsame( cmach,
'R' ) )
THEN
120 ELSE IF(
lsame( cmach,
'M' ) )
THEN
122 ELSE IF(
lsame( cmach,
'U' ) )
THEN
124 ELSE IF(
lsame( cmach,
'L' ) )
THEN
126 ELSE IF(
lsame( cmach,
'O' ) )
THEN
139 SUBROUTINE dlamc1( BETA, T, RND, IEEE1 )
192 LOGICAL first, lieee1, lrnd
194 DOUBLE PRECISION a, b, c, f, one, qtr, savec, t1, t2
201 SAVE first, lieee1, lbeta, lrnd, lt
204 DATA first / .true. /
268 f =
dlamc3( b / 2, -b / 100 )
275 f =
dlamc3( b / 2, b / 100 )
277 IF( ( lrnd ) .AND. ( c.EQ.a ) )
287 t2 =
dlamc3( b / 2, savec )
288 lieee1 = ( t1.EQ.a ) .AND. ( t2.GT.savec ) .AND. lrnd
326 SUBROUTINE dlamc2( BETA, T, RND, EPS, EMIN, RMIN, EMAX, RMAX )
335 INTEGER beta, emax, emin, t
336 DOUBLE PRECISION eps, rmax, rmin
392 LOGICAL first, ieee, iwarn, lieee1, lrnd
393 INTEGER gnmin, gpmin, i, lbeta, lemax, lemin, lt,
395 DOUBLE PRECISION a, b, c, half, leps, lrmax, lrmin, one, rbase,
396 $ sixth, small, third, two, zero
409 SAVE first, iwarn, lbeta, lemax, lemin, leps, lrmax,
413 DATA first / .true. / , iwarn / .false. /
432 CALL dlamc1( lbeta, lt, lrnd, lieee1 )
444 sixth =
dlamc3( b, -half )
445 third =
dlamc3( sixth, sixth )
446 b =
dlamc3( third, -half )
456 IF( ( leps.GT.b ) .AND. ( b.GT.zero ) )
THEN
458 c =
dlamc3( half*leps, ( two**5 )*( leps**2 ) )
479 small =
dlamc3( small*rbase, zero )
482 CALL dlamc4( ngpmin, one, lbeta )
483 CALL dlamc4( ngnmin, -one, lbeta )
484 CALL dlamc4( gpmin, a, lbeta )
485 CALL dlamc4( gnmin, -a, lbeta )
488 IF( ( ngpmin.EQ.ngnmin ) .AND. ( gpmin.EQ.gnmin ) )
THEN
489 IF( ngpmin.EQ.gpmin )
THEN
493 ELSE IF( ( gpmin-ngpmin ).EQ.3 )
THEN
494 lemin = ngpmin - 1 + lt
499 lemin =
min( ngpmin, gpmin )
504 ELSE IF( ( ngpmin.EQ.gpmin ) .AND. ( ngnmin.EQ.gnmin ) )
THEN
505 IF( abs( ngpmin-ngnmin ).EQ.1 )
THEN
506 lemin =
max( ngpmin, ngnmin )
510 lemin =
min( ngpmin, ngnmin )
515 ELSE IF( ( abs( ngpmin-ngnmin ).EQ.1 ) .AND.
516 $ ( gpmin.EQ.gnmin ) )
THEN
517 IF( ( gpmin-
min( ngpmin, ngnmin ) ).EQ.3 )
THEN
518 lemin =
max( ngpmin, ngnmin ) - 1 + lt
522 lemin =
min( ngpmin, ngnmin )
528 lemin =
min( ngpmin, ngnmin, gpmin, gnmin )
536 WRITE( 6, fmt = 9999 )lemin
545 ieee = ieee .OR. lieee1
552 DO 30 i = 1, 1 - lemin
553 lrmin =
dlamc3( lrmin*rbase, zero )
558 CALL dlamc5( lbeta, lt, lemin, ieee, lemax, lrmax )
572 9999
FORMAT( / /
' WARNING. The value EMIN may be incorrect:-',
574 $
' If, after inspection, the value EMIN looks',
575 $
' acceptable please comment out ',
576 $ /
' the IF block as marked within the code of routine',
577 $
' DLAMC2,', /
' otherwise supply EMIN explicitly.', / )
585 DOUBLE PRECISION FUNCTION dlamc3( A, B )
593 DOUBLE PRECISION a, b
623 SUBROUTINE dlamc4( EMIN, START, BASE )
632 DOUBLE PRECISION start
658 DOUBLE PRECISION a, b1, b2, c1, c2, d1, d2, one, rbase, zero
671 b1 =
dlamc3( a*rbase, zero )
679 IF( ( c1.EQ.a ) .AND. ( c2.EQ.a ) .AND. ( d1.EQ.a ) .AND.
683 b1 =
dlamc3( a / base, zero )
684 c1 =
dlamc3( b1*base, zero )
689 b2 =
dlamc3( a*rbase, zero )
690 c2 =
dlamc3( b2 / rbase, zero )
707 SUBROUTINE dlamc5( BETA, P, EMIN, IEEE, EMAX, RMAX )
716 INTEGER beta, emax, emin, p
717 DOUBLE PRECISION rmax
756 DOUBLE PRECISION zero, one
757 parameter( zero = 0.0d0, one = 1.0d0 )
760 INTEGER exbits, expsum, i, lexp, nbits, try, uexp
761 DOUBLE PRECISION oldy, recbas, y, z
781 IF( try.LE.( -emin ) )
THEN
786 IF( lexp.EQ.-emin )
THEN
797 IF( ( uexp+emin ).GT.( -lexp-emin ) )
THEN
806 emax = expsum + emin - 1
807 nbits = 1 + exbits + p
812 IF( ( mod( nbits, 2 ).EQ.1 ) .AND. ( beta.EQ.2 ) )
THEN
857 y =
dlamc3( y*beta, zero )
866 REAL function
slamch( cmach )
915 parameter( one = 1.0e+0, zero = 0.0e+0 )
919 INTEGER beta, imax, imin, it
920 REAL base, emax, emin, eps, prec, rmach, rmax, rmin,
921 $ rnd, sfmin, small, t
931 SAVE first, eps, sfmin, base, t, rnd, emin, rmin,
935 DATA first / .true. /
941 CALL slamc2( beta, it, lrnd, eps, imin, rmin, imax, rmax )
946 eps = ( base**( 1-it ) ) / 2
956 IF( small.GE.sfmin )
THEN
961 sfmin = small*( one+eps )
965 IF(
lsame( cmach,
'E' ) )
THEN
967 ELSE IF(
lsame( cmach,
'S' ) )
THEN
969 ELSE IF(
lsame( cmach,
'B' ) )
THEN
971 ELSE IF(
lsame( cmach,
'P' ) )
THEN
973 ELSE IF(
lsame( cmach,
'N' ) )
THEN
975 ELSE IF(
lsame( cmach,
'R' ) )
THEN
977 ELSE IF(
lsame( cmach,
'M' ) )
THEN
979 ELSE IF(
lsame( cmach,
'U' ) )
THEN
981 ELSE IF(
lsame( cmach,
'L' ) )
THEN
983 ELSE IF(
lsame( cmach,
'O' ) )
THEN
996 SUBROUTINE slamc1( BETA, T, RND, IEEE1 )
1049 LOGICAL FIRST, LIEEE1, LRND
1051 REAL A, B, C, F, ONE, QTR, SAVEC, T1, T2
1058 SAVE first, lieee1, lbeta, lrnd, lt
1061 DATA first / .true. /
1088 c = slamc3( a, one )
1125 f = slamc3( b / 2, -b / 100 )
1132 f = slamc3( b / 2, b / 100 )
1134 IF( ( lrnd ) .AND. ( c.EQ.a ) )
1143 t1 = slamc3( b / 2, a )
1144 t2 = slamc3( b / 2, savec )
1145 lieee1 = ( t1.EQ.a ) .AND. ( t2.GT.savec ) .AND. lrnd
1163 c = slamc3( a, one )
1183 SUBROUTINE slamc2( BETA, T, RND, EPS, EMIN, RMIN, EMAX, RMAX )
1192 INTEGER BETA, EMAX, EMIN, T
1193 REAL EPS, RMAX, RMIN
1249 LOGICAL FIRST, IEEE, IWARN, LIEEE1, LRND
1250 INTEGER GNMIN, GPMIN, I, LBETA, LEMAX, LEMIN, LT,
1252 REAL A, B, C, HALF, LEPS, LRMAX, LRMIN, ONE, RBASE,
1253 $ SIXTH, SMALL, THIRD, TWO, ZERO
1266 SAVE first, iwarn, lbeta, lemax, lemin, leps, lrmax,
1270 DATA first / .true. / , iwarn / .false. /
1289 CALL slamc1( lbeta, lt, lrnd, lieee1 )
1301 sixth = slamc3( b, -half )
1302 third = slamc3( sixth, sixth )
1303 b = slamc3( third, -half )
1304 b = slamc3( b, sixth )
1313 IF( ( leps.GT.b ) .AND. ( b.GT.zero ) )
THEN
1315 c = slamc3( half*leps, ( two**5 )*( leps**2 ) )
1316 c = slamc3( half, -c )
1317 b = slamc3( half, c )
1318 c = slamc3( half, -b )
1319 b = slamc3( half, c )
1336 small = slamc3( small*rbase, zero )
1338 a = slamc3( one, small )
1339 CALL slamc4( ngpmin, one, lbeta )
1340 CALL slamc4( ngnmin, -one, lbeta )
1341 CALL slamc4( gpmin, a, lbeta )
1342 CALL slamc4( gnmin, -a, lbeta )
1345 IF( ( ngpmin.EQ.ngnmin ) .AND. ( gpmin.EQ.gnmin ) )
THEN
1346 IF( ngpmin.EQ.gpmin )
THEN
1350 ELSE IF( ( gpmin-ngpmin ).EQ.3 )
THEN
1351 lemin = ngpmin - 1 + lt
1356 lemin =
min( ngpmin, gpmin )
1361 ELSE IF( ( ngpmin.EQ.gpmin ) .AND. ( ngnmin.EQ.gnmin ) )
THEN
1362 IF( abs( ngpmin-ngnmin ).EQ.1 )
THEN
1363 lemin =
max( ngpmin, ngnmin )
1367 lemin =
min( ngpmin, ngnmin )
1372 ELSE IF( ( abs( ngpmin-ngnmin ).EQ.1 ) .AND.
1373 $ ( gpmin.EQ.gnmin ) )
THEN
1374 IF( ( gpmin-
min( ngpmin, ngnmin ) ).EQ.3 )
THEN
1375 lemin =
max( ngpmin, ngnmin ) - 1 + lt
1379 lemin =
min( ngpmin, ngnmin )
1385 lemin =
min( ngpmin, ngnmin, gpmin, gnmin )
1393 WRITE( 6, fmt = 9999 )lemin
1402 ieee = ieee .OR. lieee1
1409 DO 30 i = 1, 1 - lemin
1410 lrmin = slamc3( lrmin*rbase, zero )
1415 CALL slamc5( lbeta, lt, lemin, ieee, lemax, lrmax )
1429 9999
FORMAT( / /
' WARNING. The value EMIN may be incorrect:-',
1431 $
' If, after inspection, the value EMIN looks',
1432 $
' acceptable please comment out ',
1433 $ /
' the IF block as marked within the code of routine',
1434 $
' SLAMC2,', /
' otherwise supply EMIN explicitly.', / )
1442 REAL FUNCTION SLAMC3( A, B )
1480 SUBROUTINE slamc4( EMIN, START, BASE )
1515 REAL A, B1, B2, C1, C2, D1, D2, ONE, RBASE, ZERO
1528 b1 = slamc3( a*rbase, zero )
1536 IF( ( c1.EQ.a ) .AND. ( c2.EQ.a ) .AND. ( d1.EQ.a ) .AND.
1537 $ ( d2.EQ.a ) )
THEN
1540 b1 = slamc3( a / base, zero )
1541 c1 = slamc3( b1*base, zero )
1546 b2 = slamc3( a*rbase, zero )
1547 c2 = slamc3( b2 / rbase, zero )
1564 SUBROUTINE slamc5( BETA, P, EMIN, IEEE, EMAX, RMAX )
1573 INTEGER BETA, EMAX, EMIN, P
1614 parameter( zero = 0.0e0, one = 1.0e0 )
1617 INTEGER EXBITS, EXPSUM, I, LEXP, NBITS, TRY, UEXP
1618 REAL OLDY, RECBAS, Y, Z
1638 IF( try.LE.( -emin ) )
THEN
1643 IF( lexp.EQ.-emin )
THEN
1654 IF( ( uexp+emin ).GT.( -lexp-emin ) )
THEN
1663 emax = expsum + emin - 1
1664 nbits = 1 + exbits + p
1669 IF( ( mod( nbits, 2 ).EQ.1 ) .AND. ( beta.EQ.2 ) )
THEN
1714 y = slamc3( y*beta, zero )
1723 LOGICAL FUNCTION lsame( CA, CB )
1753 INTEGER inta, intb, zcode
1765 zcode = ichar(
'Z' )
1775 IF( zcode.EQ.90 .OR. zcode.EQ.122 )
THEN
1780 IF( inta.GE.97 .AND. inta.LE.122 ) inta = inta - 32
1781 IF( intb.GE.97 .AND. intb.LE.122 ) intb = intb - 32
1783 ELSE IF( zcode.EQ.233 .OR. zcode.EQ.169 )
THEN
1788 IF( inta.GE.129 .AND. inta.LE.137 .OR.
1789 $ inta.GE.145 .AND. inta.LE.153 .OR.
1790 $ inta.GE.162 .AND. inta.LE.169 ) inta = inta + 64
1791 IF( intb.GE.129 .AND. intb.LE.137 .OR.
1792 $ intb.GE.145 .AND. intb.LE.153 .OR.
1793 $ intb.GE.162 .AND. intb.LE.169 ) intb = intb + 64
1795 ELSE IF( zcode.EQ.218 .OR. zcode.EQ.250 )
THEN
1800 IF( inta.GE.225 .AND. inta.LE.250 ) inta = inta - 32
1801 IF( intb.GE.225 .AND. intb.LE.250 ) intb = intb - 32
1803 lsame = inta.EQ.intb
1810 DOUBLE PRECISION FUNCTION dlarnd( IDIST, ISEED )
1855 DOUBLE PRECISION one, two
1856 parameter( one = 1.0d+0, two = 2.0d+0 )
1857 DOUBLE PRECISION twopi
1858 parameter( twopi = 6.2831853071795864769252867663d+0 )
1861 DOUBLE PRECISION t1, t2
1868 INTRINSIC cos, log, sqrt
1876 IF( idist.EQ.1 )
THEN
1881 ELSE IF( idist.EQ.2 )
THEN
1886 ELSE IF( idist.EQ.3 )
THEN
1891 dlarnd = sqrt( -two*log( t1 ) )*cos( twopi*t2 )
1898 DOUBLE COMPLEX FUNCTION zlarnd( IDIST, ISEED )
1945 DOUBLE PRECISION zero, one, two
1946 parameter( zero = 0.0d+0, one = 1.0d+0, two = 2.0d+0 )
1947 DOUBLE PRECISION twopi
1948 parameter( twopi = 6.2831853071795864769252867663d+0 )
1951 DOUBLE PRECISION t1, t2
1958 INTRINSIC dcmplx, exp, log, sqrt
1968 IF( idist.EQ.1 )
THEN
1972 zlarnd = dcmplx( t1, t2 )
1973 ELSE IF( idist.EQ.2 )
THEN
1977 zlarnd = dcmplx( two*t1-one, two*t2-one )
1978 ELSE IF( idist.EQ.3 )
THEN
1982 zlarnd = sqrt( -two*log( t1 ) )*exp( dcmplx( zero, twopi*t2 ) )
1983 ELSE IF( idist.EQ.4 )
THEN
1987 zlarnd = sqrt( t1 )*exp( dcmplx( zero, twopi*t2 ) )
1988 ELSE IF( idist.EQ.5 )
THEN
1992 zlarnd = exp( dcmplx( zero, twopi*t2 ) )
1999 DOUBLE PRECISION FUNCTION dlaran( ISEED )
2041 INTEGER m1, m2, m3, m4
2042 parameter( m1 = 494, m2 = 322, m3 = 2508, m4 = 2549 )
2043 DOUBLE PRECISION one
2044 parameter( one = 1.0d+0 )
2047 parameter( ipw2 = 4096, r = one / ipw2 )
2050 INTEGER it1, it2, it3, it4
2061 it4 = it4 - ipw2*it3
2062 it3 = it3 + iseed( 3 )*m4 + iseed( 4 )*m3
2064 it3 = it3 - ipw2*it2
2065 it2 = it2 + iseed( 2 )*m4 + iseed( 3 )*m3 + iseed( 4 )*m2
2067 it2 = it2 - ipw2*it1
2068 it1 = it1 + iseed( 1 )*m4 + iseed( 2 )*m3 + iseed( 3 )*m2 +
2070 it1 = mod( it1, ipw2 )
2081 dlaran = r*( dble( it1 )+r*( dble( it2 )+r*( dble( it3 )+r*
2082 $ ( dble( it4 ) ) ) ) )