You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dlamchf77.f 26 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. *> \brief \b DLAMCHF77 deprecated
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. * Definition:
  9. * ===========
  10. *
  11. * DOUBLE PRECISION FUNCTION DLAMCH( CMACH )
  12. *
  13. *
  14. *> \par Purpose:
  15. * =============
  16. *>
  17. *> \verbatim
  18. *>
  19. *> DLAMCHF77 determines double precision machine parameters.
  20. *> \endverbatim
  21. *
  22. * Arguments:
  23. * ==========
  24. *
  25. *> \param[in] CMACH
  26. *> \verbatim
  27. *> Specifies the value to be returned by DLAMCH:
  28. *> = 'E' or 'e', DLAMCH := eps
  29. *> = 'S' or 's , DLAMCH := sfmin
  30. *> = 'B' or 'b', DLAMCH := base
  31. *> = 'P' or 'p', DLAMCH := eps*base
  32. *> = 'N' or 'n', DLAMCH := t
  33. *> = 'R' or 'r', DLAMCH := rnd
  34. *> = 'M' or 'm', DLAMCH := emin
  35. *> = 'U' or 'u', DLAMCH := rmin
  36. *> = 'L' or 'l', DLAMCH := emax
  37. *> = 'O' or 'o', DLAMCH := rmax
  38. *> where
  39. *> eps = relative machine precision
  40. *> sfmin = safe minimum, such that 1/sfmin does not overflow
  41. *> base = base of the machine
  42. *> prec = eps*base
  43. *> t = number of (base) digits in the mantissa
  44. *> rnd = 1.0 when rounding occurs in addition, 0.0 otherwise
  45. *> emin = minimum exponent before (gradual) underflow
  46. *> rmin = underflow threshold - base**(emin-1)
  47. *> emax = largest exponent before overflow
  48. *> rmax = overflow threshold - (base**emax)*(1-eps)
  49. *> \endverbatim
  50. *
  51. * Authors:
  52. * ========
  53. *
  54. *> \author Univ. of Tennessee
  55. *> \author Univ. of California Berkeley
  56. *> \author Univ. of Colorado Denver
  57. *> \author NAG Ltd.
  58. *
  59. *> \date April 2012
  60. *
  61. *> \ingroup auxOTHERauxiliary
  62. *
  63. * =====================================================================
  64. DOUBLE PRECISION FUNCTION DLAMCH( CMACH )
  65. *
  66. * -- LAPACK auxiliary routine (version 3.4.1) --
  67. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  68. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  69. * April 2012
  70. *
  71. * .. Scalar Arguments ..
  72. CHARACTER CMACH
  73. * ..
  74. * .. Parameters ..
  75. DOUBLE PRECISION ONE, ZERO
  76. PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
  77. * ..
  78. * .. Local Scalars ..
  79. LOGICAL FIRST, LRND
  80. INTEGER BETA, IMAX, IMIN, IT
  81. DOUBLE PRECISION BASE, EMAX, EMIN, EPS, PREC, RMACH, RMAX, RMIN,
  82. $ RND, SFMIN, SMALL, T
  83. * ..
  84. * .. External Functions ..
  85. LOGICAL LSAME
  86. EXTERNAL LSAME
  87. * ..
  88. * .. External Subroutines ..
  89. EXTERNAL DLAMC2
  90. * ..
  91. * .. Save statement ..
  92. SAVE FIRST, EPS, SFMIN, BASE, T, RND, EMIN, RMIN,
  93. $ EMAX, RMAX, PREC
  94. * ..
  95. * .. Data statements ..
  96. DATA FIRST / .TRUE. /
  97. * ..
  98. * .. Executable Statements ..
  99. *
  100. IF( FIRST ) THEN
  101. CALL DLAMC2( BETA, IT, LRND, EPS, IMIN, RMIN, IMAX, RMAX )
  102. BASE = BETA
  103. T = IT
  104. IF( LRND ) THEN
  105. RND = ONE
  106. EPS = ( BASE**( 1-IT ) ) / 2
  107. ELSE
  108. RND = ZERO
  109. EPS = BASE**( 1-IT )
  110. END IF
  111. PREC = EPS*BASE
  112. EMIN = IMIN
  113. EMAX = IMAX
  114. SFMIN = RMIN
  115. SMALL = ONE / RMAX
  116. IF( SMALL.GE.SFMIN ) THEN
  117. *
  118. * Use SMALL plus a bit, to avoid the possibility of rounding
  119. * causing overflow when computing 1/sfmin.
  120. *
  121. SFMIN = SMALL*( ONE+EPS )
  122. END IF
  123. END IF
  124. *
  125. IF( LSAME( CMACH, 'E' ) ) THEN
  126. RMACH = EPS
  127. ELSE IF( LSAME( CMACH, 'S' ) ) THEN
  128. RMACH = SFMIN
  129. ELSE IF( LSAME( CMACH, 'B' ) ) THEN
  130. RMACH = BASE
  131. ELSE IF( LSAME( CMACH, 'P' ) ) THEN
  132. RMACH = PREC
  133. ELSE IF( LSAME( CMACH, 'N' ) ) THEN
  134. RMACH = T
  135. ELSE IF( LSAME( CMACH, 'R' ) ) THEN
  136. RMACH = RND
  137. ELSE IF( LSAME( CMACH, 'M' ) ) THEN
  138. RMACH = EMIN
  139. ELSE IF( LSAME( CMACH, 'U' ) ) THEN
  140. RMACH = RMIN
  141. ELSE IF( LSAME( CMACH, 'L' ) ) THEN
  142. RMACH = EMAX
  143. ELSE IF( LSAME( CMACH, 'O' ) ) THEN
  144. RMACH = RMAX
  145. END IF
  146. *
  147. DLAMCH = RMACH
  148. FIRST = .FALSE.
  149. RETURN
  150. *
  151. * End of DLAMCH
  152. *
  153. END
  154. *
  155. ************************************************************************
  156. *
  157. *> \brief \b DLAMC1
  158. *> \details
  159. *> \b Purpose:
  160. *> \verbatim
  161. *> DLAMC1 determines the machine parameters given by BETA, T, RND, and
  162. *> IEEE1.
  163. *> \endverbatim
  164. *>
  165. *> \param[out] BETA
  166. *> \verbatim
  167. *> The base of the machine.
  168. *> \endverbatim
  169. *>
  170. *> \param[out] T
  171. *> \verbatim
  172. *> The number of ( BETA ) digits in the mantissa.
  173. *> \endverbatim
  174. *>
  175. *> \param[out] RND
  176. *> \verbatim
  177. *> Specifies whether proper rounding ( RND = .TRUE. ) or
  178. *> chopping ( RND = .FALSE. ) occurs in addition. This may not
  179. *> be a reliable guide to the way in which the machine performs
  180. *> its arithmetic.
  181. *> \endverbatim
  182. *>
  183. *> \param[out] IEEE1
  184. *> \verbatim
  185. *> Specifies whether rounding appears to be done in the IEEE
  186. *> 'round to nearest' style.
  187. *> \endverbatim
  188. *> \author LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
  189. *> \date April 2012
  190. *> \ingroup auxOTHERauxiliary
  191. *>
  192. *> \details \b Further \b Details
  193. *> \verbatim
  194. *>
  195. *> The routine is based on the routine ENVRON by Malcolm and
  196. *> incorporates suggestions by Gentleman and Marovich. See
  197. *>
  198. *> Malcolm M. A. (1972) Algorithms to reveal properties of
  199. *> floating-point arithmetic. Comms. of the ACM, 15, 949-951.
  200. *>
  201. *> Gentleman W. M. and Marovich S. B. (1974) More on algorithms
  202. *> that reveal properties of floating point arithmetic units.
  203. *> Comms. of the ACM, 17, 276-277.
  204. *> \endverbatim
  205. *>
  206. SUBROUTINE DLAMC1( BETA, T, RND, IEEE1 )
  207. *
  208. * -- LAPACK auxiliary routine (version 3.4.1) --
  209. * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  210. * November 2010
  211. *
  212. * .. Scalar Arguments ..
  213. LOGICAL IEEE1, RND
  214. INTEGER BETA, T
  215. * ..
  216. * =====================================================================
  217. *
  218. * .. Local Scalars ..
  219. LOGICAL FIRST, LIEEE1, LRND
  220. INTEGER LBETA, LT
  221. DOUBLE PRECISION A, B, C, F, ONE, QTR, SAVEC, T1, T2
  222. * ..
  223. * .. External Functions ..
  224. DOUBLE PRECISION DLAMC3
  225. EXTERNAL DLAMC3
  226. * ..
  227. * .. Save statement ..
  228. SAVE FIRST, LIEEE1, LBETA, LRND, LT
  229. * ..
  230. * .. Data statements ..
  231. DATA FIRST / .TRUE. /
  232. * ..
  233. * .. Executable Statements ..
  234. *
  235. IF( FIRST ) THEN
  236. ONE = 1
  237. *
  238. * LBETA, LIEEE1, LT and LRND are the local values of BETA,
  239. * IEEE1, T and RND.
  240. *
  241. * Throughout this routine we use the function DLAMC3 to ensure
  242. * that relevant values are stored and not held in registers, or
  243. * are not affected by optimizers.
  244. *
  245. * Compute a = 2.0**m with the smallest positive integer m such
  246. * that
  247. *
  248. * fl( a + 1.0 ) = a.
  249. *
  250. A = 1
  251. C = 1
  252. *
  253. *+ WHILE( C.EQ.ONE )LOOP
  254. 10 CONTINUE
  255. IF( C.EQ.ONE ) THEN
  256. A = 2*A
  257. C = DLAMC3( A, ONE )
  258. C = DLAMC3( C, -A )
  259. GO TO 10
  260. END IF
  261. *+ END WHILE
  262. *
  263. * Now compute b = 2.0**m with the smallest positive integer m
  264. * such that
  265. *
  266. * fl( a + b ) .gt. a.
  267. *
  268. B = 1
  269. C = DLAMC3( A, B )
  270. *
  271. *+ WHILE( C.EQ.A )LOOP
  272. 20 CONTINUE
  273. IF( C.EQ.A ) THEN
  274. B = 2*B
  275. C = DLAMC3( A, B )
  276. GO TO 20
  277. END IF
  278. *+ END WHILE
  279. *
  280. * Now compute the base. a and c are neighbouring floating point
  281. * numbers in the interval ( beta**t, beta**( t + 1 ) ) and so
  282. * their difference is beta. Adding 0.25 to c is to ensure that it
  283. * is truncated to beta and not ( beta - 1 ).
  284. *
  285. QTR = ONE / 4
  286. SAVEC = C
  287. C = DLAMC3( C, -A )
  288. LBETA = C + QTR
  289. *
  290. * Now determine whether rounding or chopping occurs, by adding a
  291. * bit less than beta/2 and a bit more than beta/2 to a.
  292. *
  293. B = LBETA
  294. F = DLAMC3( B / 2, -B / 100 )
  295. C = DLAMC3( F, A )
  296. IF( C.EQ.A ) THEN
  297. LRND = .TRUE.
  298. ELSE
  299. LRND = .FALSE.
  300. END IF
  301. F = DLAMC3( B / 2, B / 100 )
  302. C = DLAMC3( F, A )
  303. IF( ( LRND ) .AND. ( C.EQ.A ) )
  304. $ LRND = .FALSE.
  305. *
  306. * Try and decide whether rounding is done in the IEEE 'round to
  307. * nearest' style. B/2 is half a unit in the last place of the two
  308. * numbers A and SAVEC. Furthermore, A is even, i.e. has last bit
  309. * zero, and SAVEC is odd. Thus adding B/2 to A should not change
  310. * A, but adding B/2 to SAVEC should change SAVEC.
  311. *
  312. T1 = DLAMC3( B / 2, A )
  313. T2 = DLAMC3( B / 2, SAVEC )
  314. LIEEE1 = ( T1.EQ.A ) .AND. ( T2.GT.SAVEC ) .AND. LRND
  315. *
  316. * Now find the mantissa, t. It should be the integer part of
  317. * log to the base beta of a, however it is safer to determine t
  318. * by powering. So we find t as the smallest positive integer for
  319. * which
  320. *
  321. * fl( beta**t + 1.0 ) = 1.0.
  322. *
  323. LT = 0
  324. A = 1
  325. C = 1
  326. *
  327. *+ WHILE( C.EQ.ONE )LOOP
  328. 30 CONTINUE
  329. IF( C.EQ.ONE ) THEN
  330. LT = LT + 1
  331. A = A*LBETA
  332. C = DLAMC3( A, ONE )
  333. C = DLAMC3( C, -A )
  334. GO TO 30
  335. END IF
  336. *+ END WHILE
  337. *
  338. END IF
  339. *
  340. BETA = LBETA
  341. T = LT
  342. RND = LRND
  343. IEEE1 = LIEEE1
  344. FIRST = .FALSE.
  345. RETURN
  346. *
  347. * End of DLAMC1
  348. *
  349. END
  350. *
  351. ************************************************************************
  352. *
  353. *> \brief \b DLAMC2
  354. *> \details
  355. *> \b Purpose:
  356. *> \verbatim
  357. *> DLAMC2 determines the machine parameters specified in its argument
  358. *> list.
  359. *> \endverbatim
  360. *> \author LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
  361. *> \date April 2012
  362. *> \ingroup auxOTHERauxiliary
  363. *>
  364. *> \param[out] BETA
  365. *> \verbatim
  366. *> The base of the machine.
  367. *> \endverbatim
  368. *>
  369. *> \param[out] T
  370. *> \verbatim
  371. *> The number of ( BETA ) digits in the mantissa.
  372. *> \endverbatim
  373. *>
  374. *> \param[out] RND
  375. *> \verbatim
  376. *> Specifies whether proper rounding ( RND = .TRUE. ) or
  377. *> chopping ( RND = .FALSE. ) occurs in addition. This may not
  378. *> be a reliable guide to the way in which the machine performs
  379. *> its arithmetic.
  380. *> \endverbatim
  381. *>
  382. *> \param[out] EPS
  383. *> \verbatim
  384. *> The smallest positive number such that
  385. *> fl( 1.0 - EPS ) .LT. 1.0,
  386. *> where fl denotes the computed value.
  387. *> \endverbatim
  388. *>
  389. *> \param[out] EMIN
  390. *> \verbatim
  391. *> The minimum exponent before (gradual) underflow occurs.
  392. *> \endverbatim
  393. *>
  394. *> \param[out] RMIN
  395. *> \verbatim
  396. *> The smallest normalized number for the machine, given by
  397. *> BASE**( EMIN - 1 ), where BASE is the floating point value
  398. *> of BETA.
  399. *> \endverbatim
  400. *>
  401. *> \param[out] EMAX
  402. *> \verbatim
  403. *> The maximum exponent before overflow occurs.
  404. *> \endverbatim
  405. *>
  406. *> \param[out] RMAX
  407. *> \verbatim
  408. *> The largest positive number for the machine, given by
  409. *> BASE**EMAX * ( 1 - EPS ), where BASE is the floating point
  410. *> value of BETA.
  411. *> \endverbatim
  412. *>
  413. *> \details \b Further \b Details
  414. *> \verbatim
  415. *>
  416. *> The computation of EPS is based on a routine PARANOIA by
  417. *> W. Kahan of the University of California at Berkeley.
  418. *> \endverbatim
  419. SUBROUTINE DLAMC2( BETA, T, RND, EPS, EMIN, RMIN, EMAX, RMAX )
  420. *
  421. * -- LAPACK auxiliary routine (version 3.4.1) --
  422. * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  423. * November 2010
  424. *
  425. * .. Scalar Arguments ..
  426. LOGICAL RND
  427. INTEGER BETA, EMAX, EMIN, T
  428. DOUBLE PRECISION EPS, RMAX, RMIN
  429. * ..
  430. * =====================================================================
  431. *
  432. * .. Local Scalars ..
  433. LOGICAL FIRST, IEEE, IWARN, LIEEE1, LRND
  434. INTEGER GNMIN, GPMIN, I, LBETA, LEMAX, LEMIN, LT,
  435. $ NGNMIN, NGPMIN
  436. DOUBLE PRECISION A, B, C, HALF, LEPS, LRMAX, LRMIN, ONE, RBASE,
  437. $ SIXTH, SMALL, THIRD, TWO, ZERO
  438. * ..
  439. * .. External Functions ..
  440. DOUBLE PRECISION DLAMC3
  441. EXTERNAL DLAMC3
  442. * ..
  443. * .. External Subroutines ..
  444. EXTERNAL DLAMC1, DLAMC4, DLAMC5
  445. * ..
  446. * .. Intrinsic Functions ..
  447. INTRINSIC ABS, MAX, MIN
  448. * ..
  449. * .. Save statement ..
  450. SAVE FIRST, IWARN, LBETA, LEMAX, LEMIN, LEPS, LRMAX,
  451. $ LRMIN, LT
  452. * ..
  453. * .. Data statements ..
  454. DATA FIRST / .TRUE. / , IWARN / .FALSE. /
  455. * ..
  456. * .. Executable Statements ..
  457. *
  458. IF( FIRST ) THEN
  459. ZERO = 0
  460. ONE = 1
  461. TWO = 2
  462. *
  463. * LBETA, LT, LRND, LEPS, LEMIN and LRMIN are the local values of
  464. * BETA, T, RND, EPS, EMIN and RMIN.
  465. *
  466. * Throughout this routine we use the function DLAMC3 to ensure
  467. * that relevant values are stored and not held in registers, or
  468. * are not affected by optimizers.
  469. *
  470. * DLAMC1 returns the parameters LBETA, LT, LRND and LIEEE1.
  471. *
  472. CALL DLAMC1( LBETA, LT, LRND, LIEEE1 )
  473. *
  474. * Start to find EPS.
  475. *
  476. B = LBETA
  477. A = B**( -LT )
  478. LEPS = A
  479. *
  480. * Try some tricks to see whether or not this is the correct EPS.
  481. *
  482. B = TWO / 3
  483. HALF = ONE / 2
  484. SIXTH = DLAMC3( B, -HALF )
  485. THIRD = DLAMC3( SIXTH, SIXTH )
  486. B = DLAMC3( THIRD, -HALF )
  487. B = DLAMC3( B, SIXTH )
  488. B = ABS( B )
  489. IF( B.LT.LEPS )
  490. $ B = LEPS
  491. *
  492. LEPS = 1
  493. *
  494. *+ WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP
  495. 10 CONTINUE
  496. IF( ( LEPS.GT.B ) .AND. ( B.GT.ZERO ) ) THEN
  497. LEPS = B
  498. C = DLAMC3( HALF*LEPS, ( TWO**5 )*( LEPS**2 ) )
  499. C = DLAMC3( HALF, -C )
  500. B = DLAMC3( HALF, C )
  501. C = DLAMC3( HALF, -B )
  502. B = DLAMC3( HALF, C )
  503. GO TO 10
  504. END IF
  505. *+ END WHILE
  506. *
  507. IF( A.LT.LEPS )
  508. $ LEPS = A
  509. *
  510. * Computation of EPS complete.
  511. *
  512. * Now find EMIN. Let A = + or - 1, and + or - (1 + BASE**(-3)).
  513. * Keep dividing A by BETA until (gradual) underflow occurs. This
  514. * is detected when we cannot recover the previous A.
  515. *
  516. RBASE = ONE / LBETA
  517. SMALL = ONE
  518. DO 20 I = 1, 3
  519. SMALL = DLAMC3( SMALL*RBASE, ZERO )
  520. 20 CONTINUE
  521. A = DLAMC3( ONE, SMALL )
  522. CALL DLAMC4( NGPMIN, ONE, LBETA )
  523. CALL DLAMC4( NGNMIN, -ONE, LBETA )
  524. CALL DLAMC4( GPMIN, A, LBETA )
  525. CALL DLAMC4( GNMIN, -A, LBETA )
  526. IEEE = .FALSE.
  527. *
  528. IF( ( NGPMIN.EQ.NGNMIN ) .AND. ( GPMIN.EQ.GNMIN ) ) THEN
  529. IF( NGPMIN.EQ.GPMIN ) THEN
  530. LEMIN = NGPMIN
  531. * ( Non twos-complement machines, no gradual underflow;
  532. * e.g., VAX )
  533. ELSE IF( ( GPMIN-NGPMIN ).EQ.3 ) THEN
  534. LEMIN = NGPMIN - 1 + LT
  535. IEEE = .TRUE.
  536. * ( Non twos-complement machines, with gradual underflow;
  537. * e.g., IEEE standard followers )
  538. ELSE
  539. LEMIN = MIN( NGPMIN, GPMIN )
  540. * ( A guess; no known machine )
  541. IWARN = .TRUE.
  542. END IF
  543. *
  544. ELSE IF( ( NGPMIN.EQ.GPMIN ) .AND. ( NGNMIN.EQ.GNMIN ) ) THEN
  545. IF( ABS( NGPMIN-NGNMIN ).EQ.1 ) THEN
  546. LEMIN = MAX( NGPMIN, NGNMIN )
  547. * ( Twos-complement machines, no gradual underflow;
  548. * e.g., CYBER 205 )
  549. ELSE
  550. LEMIN = MIN( NGPMIN, NGNMIN )
  551. * ( A guess; no known machine )
  552. IWARN = .TRUE.
  553. END IF
  554. *
  555. ELSE IF( ( ABS( NGPMIN-NGNMIN ).EQ.1 ) .AND.
  556. $ ( GPMIN.EQ.GNMIN ) ) THEN
  557. IF( ( GPMIN-MIN( NGPMIN, NGNMIN ) ).EQ.3 ) THEN
  558. LEMIN = MAX( NGPMIN, NGNMIN ) - 1 + LT
  559. * ( Twos-complement machines with gradual underflow;
  560. * no known machine )
  561. ELSE
  562. LEMIN = MIN( NGPMIN, NGNMIN )
  563. * ( A guess; no known machine )
  564. IWARN = .TRUE.
  565. END IF
  566. *
  567. ELSE
  568. LEMIN = MIN( NGPMIN, NGNMIN, GPMIN, GNMIN )
  569. * ( A guess; no known machine )
  570. IWARN = .TRUE.
  571. END IF
  572. FIRST = .FALSE.
  573. ***
  574. * Comment out this if block if EMIN is ok
  575. IF( IWARN ) THEN
  576. FIRST = .TRUE.
  577. WRITE( 6, FMT = 9999 )LEMIN
  578. END IF
  579. ***
  580. *
  581. * Assume IEEE arithmetic if we found denormalised numbers above,
  582. * or if arithmetic seems to round in the IEEE style, determined
  583. * in routine DLAMC1. A true IEEE machine should have both things
  584. * true; however, faulty machines may have one or the other.
  585. *
  586. IEEE = IEEE .OR. LIEEE1
  587. *
  588. * Compute RMIN by successive division by BETA. We could compute
  589. * RMIN as BASE**( EMIN - 1 ), but some machines underflow during
  590. * this computation.
  591. *
  592. LRMIN = 1
  593. DO 30 I = 1, 1 - LEMIN
  594. LRMIN = DLAMC3( LRMIN*RBASE, ZERO )
  595. 30 CONTINUE
  596. *
  597. * Finally, call DLAMC5 to compute EMAX and RMAX.
  598. *
  599. CALL DLAMC5( LBETA, LT, LEMIN, IEEE, LEMAX, LRMAX )
  600. END IF
  601. *
  602. BETA = LBETA
  603. T = LT
  604. RND = LRND
  605. EPS = LEPS
  606. EMIN = LEMIN
  607. RMIN = LRMIN
  608. EMAX = LEMAX
  609. RMAX = LRMAX
  610. *
  611. RETURN
  612. *
  613. 9999 FORMAT( / / ' WARNING. The value EMIN may be incorrect:-',
  614. $ ' EMIN = ', I8, /
  615. $ ' If, after inspection, the value EMIN looks',
  616. $ ' acceptable please comment out ',
  617. $ / ' the IF block as marked within the code of routine',
  618. $ ' DLAMC2,', / ' otherwise supply EMIN explicitly.', / )
  619. *
  620. * End of DLAMC2
  621. *
  622. END
  623. *
  624. ************************************************************************
  625. *
  626. *> \brief \b DLAMC3
  627. *> \details
  628. *> \b Purpose:
  629. *> \verbatim
  630. *> DLAMC3 is intended to force A and B to be stored prior to doing
  631. *> the addition of A and B , for use in situations where optimizers
  632. *> might hold one of these in a register.
  633. *> \endverbatim
  634. *>
  635. *> \param[in] A
  636. *>
  637. *> \param[in] B
  638. *> \verbatim
  639. *> The values A and B.
  640. *> \endverbatim
  641. DOUBLE PRECISION FUNCTION DLAMC3( A, B )
  642. *
  643. * -- LAPACK auxiliary routine (version 3.4.1) --
  644. * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  645. * November 2010
  646. *
  647. * .. Scalar Arguments ..
  648. DOUBLE PRECISION A, B
  649. * ..
  650. * =====================================================================
  651. *
  652. * .. Executable Statements ..
  653. *
  654. DLAMC3 = A + B
  655. *
  656. RETURN
  657. *
  658. * End of DLAMC3
  659. *
  660. END
  661. *
  662. ************************************************************************
  663. *
  664. *> \brief \b DLAMC4
  665. *> \details
  666. *> \b Purpose:
  667. *> \verbatim
  668. *> DLAMC4 is a service routine for DLAMC2.
  669. *> \endverbatim
  670. *>
  671. *> \param[out] EMIN
  672. *> \verbatim
  673. *> The minimum exponent before (gradual) underflow, computed by
  674. *> setting A = START and dividing by BASE until the previous A
  675. *> can not be recovered.
  676. *> \endverbatim
  677. *>
  678. *> \param[in] START
  679. *> \verbatim
  680. *> The starting point for determining EMIN.
  681. *> \endverbatim
  682. *>
  683. *> \param[in] BASE
  684. *> \verbatim
  685. *> The base of the machine.
  686. *> \endverbatim
  687. *>
  688. SUBROUTINE DLAMC4( EMIN, START, BASE )
  689. *
  690. * -- LAPACK auxiliary routine (version 3.4.1) --
  691. * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  692. * November 2010
  693. *
  694. * .. Scalar Arguments ..
  695. INTEGER BASE, EMIN
  696. DOUBLE PRECISION START
  697. * ..
  698. * =====================================================================
  699. *
  700. * .. Local Scalars ..
  701. INTEGER I
  702. DOUBLE PRECISION A, B1, B2, C1, C2, D1, D2, ONE, RBASE, ZERO
  703. * ..
  704. * .. External Functions ..
  705. DOUBLE PRECISION DLAMC3
  706. EXTERNAL DLAMC3
  707. * ..
  708. * .. Executable Statements ..
  709. *
  710. A = START
  711. ONE = 1
  712. RBASE = ONE / BASE
  713. ZERO = 0
  714. EMIN = 1
  715. B1 = DLAMC3( A*RBASE, ZERO )
  716. C1 = A
  717. C2 = A
  718. D1 = A
  719. D2 = A
  720. *+ WHILE( ( C1.EQ.A ).AND.( C2.EQ.A ).AND.
  721. * $ ( D1.EQ.A ).AND.( D2.EQ.A ) )LOOP
  722. 10 CONTINUE
  723. IF( ( C1.EQ.A ) .AND. ( C2.EQ.A ) .AND. ( D1.EQ.A ) .AND.
  724. $ ( D2.EQ.A ) ) THEN
  725. EMIN = EMIN - 1
  726. A = B1
  727. B1 = DLAMC3( A / BASE, ZERO )
  728. C1 = DLAMC3( B1*BASE, ZERO )
  729. D1 = ZERO
  730. DO 20 I = 1, BASE
  731. D1 = D1 + B1
  732. 20 CONTINUE
  733. B2 = DLAMC3( A*RBASE, ZERO )
  734. C2 = DLAMC3( B2 / RBASE, ZERO )
  735. D2 = ZERO
  736. DO 30 I = 1, BASE
  737. D2 = D2 + B2
  738. 30 CONTINUE
  739. GO TO 10
  740. END IF
  741. *+ END WHILE
  742. *
  743. RETURN
  744. *
  745. * End of DLAMC4
  746. *
  747. END
  748. *
  749. ************************************************************************
  750. *
  751. *> \brief \b DLAMC5
  752. *> \details
  753. *> \b Purpose:
  754. *> \verbatim
  755. *> DLAMC5 attempts to compute RMAX, the largest machine floating-point
  756. *> number, without overflow. It assumes that EMAX + abs(EMIN) sum
  757. *> approximately to a power of 2. It will fail on machines where this
  758. *> assumption does not hold, for example, the Cyber 205 (EMIN = -28625,
  759. *> EMAX = 28718). It will also fail if the value supplied for EMIN is
  760. *> too large (i.e. too close to zero), probably with overflow.
  761. *> \endverbatim
  762. *>
  763. *> \param[in] BETA
  764. *> \verbatim
  765. *> The base of floating-point arithmetic.
  766. *> \endverbatim
  767. *>
  768. *> \param[in] P
  769. *> \verbatim
  770. *> The number of base BETA digits in the mantissa of a
  771. *> floating-point value.
  772. *> \endverbatim
  773. *>
  774. *> \param[in] EMIN
  775. *> \verbatim
  776. *> The minimum exponent before (gradual) underflow.
  777. *> \endverbatim
  778. *>
  779. *> \param[in] IEEE
  780. *> \verbatim
  781. *> A logical flag specifying whether or not the arithmetic
  782. *> system is thought to comply with the IEEE standard.
  783. *> \endverbatim
  784. *>
  785. *> \param[out] EMAX
  786. *> \verbatim
  787. *> The largest exponent before overflow
  788. *> \endverbatim
  789. *>
  790. *> \param[out] RMAX
  791. *> \verbatim
  792. *> The largest machine floating-point number.
  793. *> \endverbatim
  794. *>
  795. SUBROUTINE DLAMC5( BETA, P, EMIN, IEEE, EMAX, RMAX )
  796. *
  797. * -- LAPACK auxiliary routine (version 3.4.1) --
  798. * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  799. * November 2010
  800. *
  801. * .. Scalar Arguments ..
  802. LOGICAL IEEE
  803. INTEGER BETA, EMAX, EMIN, P
  804. DOUBLE PRECISION RMAX
  805. * ..
  806. * =====================================================================
  807. *
  808. * .. Parameters ..
  809. DOUBLE PRECISION ZERO, ONE
  810. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0 )
  811. * ..
  812. * .. Local Scalars ..
  813. INTEGER EXBITS, EXPSUM, I, LEXP, NBITS, TRY, UEXP
  814. DOUBLE PRECISION OLDY, RECBAS, Y, Z
  815. * ..
  816. * .. External Functions ..
  817. DOUBLE PRECISION DLAMC3
  818. EXTERNAL DLAMC3
  819. * ..
  820. * .. Intrinsic Functions ..
  821. INTRINSIC MOD
  822. * ..
  823. * .. Executable Statements ..
  824. *
  825. * First compute LEXP and UEXP, two powers of 2 that bound
  826. * abs(EMIN). We then assume that EMAX + abs(EMIN) will sum
  827. * approximately to the bound that is closest to abs(EMIN).
  828. * (EMAX is the exponent of the required number RMAX).
  829. *
  830. LEXP = 1
  831. EXBITS = 1
  832. 10 CONTINUE
  833. TRY = LEXP*2
  834. IF( TRY.LE.( -EMIN ) ) THEN
  835. LEXP = TRY
  836. EXBITS = EXBITS + 1
  837. GO TO 10
  838. END IF
  839. IF( LEXP.EQ.-EMIN ) THEN
  840. UEXP = LEXP
  841. ELSE
  842. UEXP = TRY
  843. EXBITS = EXBITS + 1
  844. END IF
  845. *
  846. * Now -LEXP is less than or equal to EMIN, and -UEXP is greater
  847. * than or equal to EMIN. EXBITS is the number of bits needed to
  848. * store the exponent.
  849. *
  850. IF( ( UEXP+EMIN ).GT.( -LEXP-EMIN ) ) THEN
  851. EXPSUM = 2*LEXP
  852. ELSE
  853. EXPSUM = 2*UEXP
  854. END IF
  855. *
  856. * EXPSUM is the exponent range, approximately equal to
  857. * EMAX - EMIN + 1 .
  858. *
  859. EMAX = EXPSUM + EMIN - 1
  860. NBITS = 1 + EXBITS + P
  861. *
  862. * NBITS is the total number of bits needed to store a
  863. * floating-point number.
  864. *
  865. IF( ( MOD( NBITS, 2 ).EQ.1 ) .AND. ( BETA.EQ.2 ) ) THEN
  866. *
  867. * Either there are an odd number of bits used to store a
  868. * floating-point number, which is unlikely, or some bits are
  869. * not used in the representation of numbers, which is possible,
  870. * (e.g. Cray machines) or the mantissa has an implicit bit,
  871. * (e.g. IEEE machines, Dec Vax machines), which is perhaps the
  872. * most likely. We have to assume the last alternative.
  873. * If this is true, then we need to reduce EMAX by one because
  874. * there must be some way of representing zero in an implicit-bit
  875. * system. On machines like Cray, we are reducing EMAX by one
  876. * unnecessarily.
  877. *
  878. EMAX = EMAX - 1
  879. END IF
  880. *
  881. IF( IEEE ) THEN
  882. *
  883. * Assume we are on an IEEE machine which reserves one exponent
  884. * for infinity and NaN.
  885. *
  886. EMAX = EMAX - 1
  887. END IF
  888. *
  889. * Now create RMAX, the largest machine number, which should
  890. * be equal to (1.0 - BETA**(-P)) * BETA**EMAX .
  891. *
  892. * First compute 1.0 - BETA**(-P), being careful that the
  893. * result is less than 1.0 .
  894. *
  895. RECBAS = ONE / BETA
  896. Z = BETA - ONE
  897. Y = ZERO
  898. DO 20 I = 1, P
  899. Z = Z*RECBAS
  900. IF( Y.LT.ONE )
  901. $ OLDY = Y
  902. Y = DLAMC3( Y, Z )
  903. 20 CONTINUE
  904. IF( Y.GE.ONE )
  905. $ Y = OLDY
  906. *
  907. * Now multiply by BETA**EMAX to get RMAX.
  908. *
  909. DO 30 I = 1, EMAX
  910. Y = DLAMC3( Y*BETA, ZERO )
  911. 30 CONTINUE
  912. *
  913. RMAX = Y
  914. RETURN
  915. *
  916. * End of DLAMC5
  917. *
  918. END