LAPACK  3.11.0
LAPACK: Linear Algebra PACKage
slamchf77.f
1 *> \brief \b SLAMCHF77 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 * REAL FUNCTION SLAMCH( CMACH )
12 *
13 * .. Scalar Arguments ..
14 * CHARACTER CMACH
15 * ..
16 *
17 *
18 *> \par Purpose:
19 * =============
20 *>
21 *> \verbatim
22 *>
23 *> SLAMCH determines single precision machine parameters.
24 *> \endverbatim
25 *
26 * Arguments:
27 * ==========
28 *
29 *> \param[in] CMACH
30 *> \verbatim
31 *> Specifies the value to be returned by SLAMCH:
32 *> = 'E' or 'e', SLAMCH := eps
33 *> = 'S' or 's , SLAMCH := sfmin
34 *> = 'B' or 'b', SLAMCH := base
35 *> = 'P' or 'p', SLAMCH := eps*base
36 *> = 'N' or 'n', SLAMCH := t
37 *> = 'R' or 'r', SLAMCH := rnd
38 *> = 'M' or 'm', SLAMCH := emin
39 *> = 'U' or 'u', SLAMCH := rmin
40 *> = 'L' or 'l', SLAMCH := emax
41 *> = 'O' or 'o', SLAMCH := rmax
42 *> where
43 *> eps = relative machine precision
44 *> sfmin = safe minimum, such that 1/sfmin does not overflow
45 *> base = base of the machine
46 *> prec = eps*base
47 *> t = number of (base) digits in the mantissa
48 *> rnd = 1.0 when rounding occurs in addition, 0.0 otherwise
49 *> emin = minimum exponent before (gradual) underflow
50 *> rmin = underflow threshold - base**(emin-1)
51 *> emax = largest exponent before overflow
52 *> rmax = overflow threshold - (base**emax)*(1-eps)
53 *> \endverbatim
54 *
55 * Authors:
56 * ========
57 *
58 *> \author Univ. of Tennessee
59 *> \author Univ. of California Berkeley
60 *> \author Univ. of Colorado Denver
61 *> \author NAG Ltd.
62 *
63 *> \ingroup lamch
64 *
65 * =====================================================================
66  REAL FUNCTION slamch( CMACH )
67 *
68 * -- LAPACK auxiliary routine --
69 * -- LAPACK is a software package provided by Univ. of Tennessee, --
70 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
71 *
72 * .. Scalar Arguments ..
73  CHARACTER cmach
74 * ..
75 * .. Parameters ..
76  REAL one, zero
77  parameter( one = 1.0e+0, zero = 0.0e+0 )
78 * ..
79 * .. Local Scalars ..
80  LOGICAL first, lrnd
81  INTEGER beta, imax, imin, it
82  REAL base, emax, emin, eps, prec, rmach, rmax, rmin,
83  $ rnd, sfmin, small, t
84 * ..
85 * .. External Functions ..
86  LOGICAL lsame
87  EXTERNAL lsame
88 * ..
89 * .. External Subroutines ..
90  EXTERNAL slamc2
91 * ..
92 * .. Save statement ..
93  SAVE first, eps, sfmin, base, t, rnd, emin, rmin,
94  $ emax, rmax, prec
95 * ..
96 * .. Data statements ..
97  DATA first / .true. /
98 * ..
99 * .. Executable Statements ..
100 *
101  IF( first ) THEN
102  CALL slamc2( beta, it, lrnd, eps, imin, rmin, imax, rmax )
103  base = beta
104  t = it
105  IF( lrnd ) THEN
106  rnd = one
107  eps = ( base**( 1-it ) ) / 2
108  ELSE
109  rnd = zero
110  eps = base**( 1-it )
111  END IF
112  prec = eps*base
113  emin = imin
114  emax = imax
115  sfmin = rmin
116  small = one / rmax
117  IF( small.GE.sfmin ) THEN
118 *
119 * Use SMALL plus a bit, to avoid the possibility of rounding
120 * causing overflow when computing 1/sfmin.
121 *
122  sfmin = small*( one+eps )
123  END IF
124  END IF
125 *
126  IF( lsame( cmach, 'E' ) ) THEN
127  rmach = eps
128  ELSE IF( lsame( cmach, 'S' ) ) THEN
129  rmach = sfmin
130  ELSE IF( lsame( cmach, 'B' ) ) THEN
131  rmach = base
132  ELSE IF( lsame( cmach, 'P' ) ) THEN
133  rmach = prec
134  ELSE IF( lsame( cmach, 'N' ) ) THEN
135  rmach = t
136  ELSE IF( lsame( cmach, 'R' ) ) THEN
137  rmach = rnd
138  ELSE IF( lsame( cmach, 'M' ) ) THEN
139  rmach = emin
140  ELSE IF( lsame( cmach, 'U' ) ) THEN
141  rmach = rmin
142  ELSE IF( lsame( cmach, 'L' ) ) THEN
143  rmach = emax
144  ELSE IF( lsame( cmach, 'O' ) ) THEN
145  rmach = rmax
146  END IF
147 *
148  slamch = rmach
149  first = .false.
150  RETURN
151 *
152 * End of SLAMCH
153 *
154  END
155 *
156 ************************************************************************
157 *> \brief \b SLAMC1
158 *> \details
159 *> \b Purpose:
160 *> \verbatim
161 *> SLAMC1 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 *>
190 *> \ingroup lamc1
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 slamc1( BETA, T, RND, IEEE1 )
207 *
208 * -- LAPACK auxiliary routine --
209 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
210 *
211 * .. Scalar Arguments ..
212  LOGICAL IEEE1, RND
213  INTEGER BETA, T
214 * ..
215 * =====================================================================
216 *
217 * .. Local Scalars ..
218  LOGICAL FIRST, LIEEE1, LRND
219  INTEGER LBETA, LT
220  REAL A, B, C, F, ONE, QTR, SAVEC, T1, T2
221 * ..
222 * .. External Functions ..
223  REAL SLAMC3
224  EXTERNAL slamc3
225 * ..
226 * .. Save statement ..
227  SAVE first, lieee1, lbeta, lrnd, lt
228 * ..
229 * .. Data statements ..
230  DATA first / .true. /
231 * ..
232 * .. Executable Statements ..
233 *
234  IF( first ) THEN
235  one = 1
236 *
237 * LBETA, LIEEE1, LT and LRND are the local values of BETA,
238 * IEEE1, T and RND.
239 *
240 * Throughout this routine we use the function SLAMC3 to ensure
241 * that relevant values are stored and not held in registers, or
242 * are not affected by optimizers.
243 *
244 * Compute a = 2.0**m with the smallest positive integer m such
245 * that
246 *
247 * fl( a + 1.0 ) = a.
248 *
249  a = 1
250  c = 1
251 *
252 *+ WHILE( C.EQ.ONE )LOOP
253  10 CONTINUE
254  IF( c.EQ.one ) THEN
255  a = 2*a
256  c = slamc3( a, one )
257  c = slamc3( c, -a )
258  GO TO 10
259  END IF
260 *+ END WHILE
261 *
262 * Now compute b = 2.0**m with the smallest positive integer m
263 * such that
264 *
265 * fl( a + b ) .gt. a.
266 *
267  b = 1
268  c = slamc3( a, b )
269 *
270 *+ WHILE( C.EQ.A )LOOP
271  20 CONTINUE
272  IF( c.EQ.a ) THEN
273  b = 2*b
274  c = slamc3( a, b )
275  GO TO 20
276  END IF
277 *+ END WHILE
278 *
279 * Now compute the base. a and c are neighbouring floating point
280 * numbers in the interval ( beta**t, beta**( t + 1 ) ) and so
281 * their difference is beta. Adding 0.25 to c is to ensure that it
282 * is truncated to beta and not ( beta - 1 ).
283 *
284  qtr = one / 4
285  savec = c
286  c = slamc3( c, -a )
287  lbeta = c + qtr
288 *
289 * Now determine whether rounding or chopping occurs, by adding a
290 * bit less than beta/2 and a bit more than beta/2 to a.
291 *
292  b = lbeta
293  f = slamc3( b / 2, -b / 100 )
294  c = slamc3( f, a )
295  IF( c.EQ.a ) THEN
296  lrnd = .true.
297  ELSE
298  lrnd = .false.
299  END IF
300  f = slamc3( b / 2, b / 100 )
301  c = slamc3( f, a )
302  IF( ( lrnd ) .AND. ( c.EQ.a ) )
303  $ lrnd = .false.
304 *
305 * Try and decide whether rounding is done in the IEEE 'round to
306 * nearest' style. B/2 is half a unit in the last place of the two
307 * numbers A and SAVEC. Furthermore, A is even, i.e. has last bit
308 * zero, and SAVEC is odd. Thus adding B/2 to A should not change
309 * A, but adding B/2 to SAVEC should change SAVEC.
310 *
311  t1 = slamc3( b / 2, a )
312  t2 = slamc3( b / 2, savec )
313  lieee1 = ( t1.EQ.a ) .AND. ( t2.GT.savec ) .AND. lrnd
314 *
315 * Now find the mantissa, t. It should be the integer part of
316 * log to the base beta of a, however it is safer to determine t
317 * by powering. So we find t as the smallest positive integer for
318 * which
319 *
320 * fl( beta**t + 1.0 ) = 1.0.
321 *
322  lt = 0
323  a = 1
324  c = 1
325 *
326 *+ WHILE( C.EQ.ONE )LOOP
327  30 CONTINUE
328  IF( c.EQ.one ) THEN
329  lt = lt + 1
330  a = a*lbeta
331  c = slamc3( a, one )
332  c = slamc3( c, -a )
333  GO TO 30
334  END IF
335 *+ END WHILE
336 *
337  END IF
338 *
339  beta = lbeta
340  t = lt
341  rnd = lrnd
342  ieee1 = lieee1
343  first = .false.
344  RETURN
345 *
346 * End of SLAMC1
347 *
348  END
349 *
350 ************************************************************************
351 *> \brief \b SLAMC2
352 *> \details
353 *> \b Purpose:
354 *> \verbatim
355 *> SLAMC2 determines the machine parameters specified in its argument
356 *> list.
357 *> \endverbatim
358 *> \author LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..
359 *>
360 *> \ingroup lamc2
361 *>
362 *> \param[out] BETA
363 *> \verbatim
364 *> The base of the machine.
365 *> \endverbatim
366 *>
367 *> \param[out] T
368 *> \verbatim
369 *> The number of ( BETA ) digits in the mantissa.
370 *> \endverbatim
371 *>
372 *> \param[out] RND
373 *> \verbatim
374 *> Specifies whether proper rounding ( RND = .TRUE. ) or
375 *> chopping ( RND = .FALSE. ) occurs in addition. This may not
376 *> be a reliable guide to the way in which the machine performs
377 *> its arithmetic.
378 *> \endverbatim
379 *>
380 *> \param[out] EPS
381 *> \verbatim
382 *> The smallest positive number such that
383 *> fl( 1.0 - EPS ) .LT. 1.0,
384 *> where fl denotes the computed value.
385 *> \endverbatim
386 *>
387 *> \param[out] EMIN
388 *> \verbatim
389 *> The minimum exponent before (gradual) underflow occurs.
390 *> \endverbatim
391 *>
392 *> \param[out] RMIN
393 *> \verbatim
394 *> The smallest normalized number for the machine, given by
395 *> BASE**( EMIN - 1 ), where BASE is the floating point value
396 *> of BETA.
397 *> \endverbatim
398 *>
399 *> \param[out] EMAX
400 *> \verbatim
401 *> The maximum exponent before overflow occurs.
402 *> \endverbatim
403 *>
404 *> \param[out] RMAX
405 *> \verbatim
406 *> The largest positive number for the machine, given by
407 *> BASE**EMAX * ( 1 - EPS ), where BASE is the floating point
408 *> value of BETA.
409 *> \endverbatim
410 *>
411 *> \details \b Further \b Details
412 *> \verbatim
413 *>
414 *> The computation of EPS is based on a routine PARANOIA by
415 *> W. Kahan of the University of California at Berkeley.
416 *> \endverbatim
417 *>
418  SUBROUTINE slamc2( BETA, T, RND, EPS, EMIN, RMIN, EMAX, RMAX )
419 *
420 * -- LAPACK auxiliary routine --
421 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
422 *
423 * .. Scalar Arguments ..
424  LOGICAL RND
425  INTEGER BETA, EMAX, EMIN, T
426  REAL EPS, RMAX, RMIN
427 * ..
428 * =====================================================================
429 *
430 * .. Local Scalars ..
431  LOGICAL FIRST, IEEE, IWARN, LIEEE1, LRND
432  INTEGER GNMIN, GPMIN, I, LBETA, LEMAX, LEMIN, LT,
433  $ ngnmin, ngpmin
434  REAL A, B, C, HALF, LEPS, LRMAX, LRMIN, ONE, RBASE,
435  $ sixth, small, third, two, zero
436 * ..
437 * .. External Functions ..
438  REAL SLAMC3
439  EXTERNAL slamc3
440 * ..
441 * .. External Subroutines ..
442  EXTERNAL slamc1, slamc4, slamc5
443 * ..
444 * .. Intrinsic Functions ..
445  INTRINSIC abs, max, min
446 * ..
447 * .. Save statement ..
448  SAVE first, iwarn, lbeta, lemax, lemin, leps, lrmax,
449  $ lrmin, lt
450 * ..
451 * .. Data statements ..
452  DATA first / .true. / , iwarn / .false. /
453 * ..
454 * .. Executable Statements ..
455 *
456  IF( first ) THEN
457  zero = 0
458  one = 1
459  two = 2
460 *
461 * LBETA, LT, LRND, LEPS, LEMIN and LRMIN are the local values of
462 * BETA, T, RND, EPS, EMIN and RMIN.
463 *
464 * Throughout this routine we use the function SLAMC3 to ensure
465 * that relevant values are stored and not held in registers, or
466 * are not affected by optimizers.
467 *
468 * SLAMC1 returns the parameters LBETA, LT, LRND and LIEEE1.
469 *
470  CALL slamc1( lbeta, lt, lrnd, lieee1 )
471 *
472 * Start to find EPS.
473 *
474  b = lbeta
475  a = b**( -lt )
476  leps = a
477 *
478 * Try some tricks to see whether or not this is the correct EPS.
479 *
480  b = two / 3
481  half = one / 2
482  sixth = slamc3( b, -half )
483  third = slamc3( sixth, sixth )
484  b = slamc3( third, -half )
485  b = slamc3( b, sixth )
486  b = abs( b )
487  IF( b.LT.leps )
488  $ b = leps
489 *
490  leps = 1
491 *
492 *+ WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP
493  10 CONTINUE
494  IF( ( leps.GT.b ) .AND. ( b.GT.zero ) ) THEN
495  leps = b
496  c = slamc3( half*leps, ( two**5 )*( leps**2 ) )
497  c = slamc3( half, -c )
498  b = slamc3( half, c )
499  c = slamc3( half, -b )
500  b = slamc3( half, c )
501  GO TO 10
502  END IF
503 *+ END WHILE
504 *
505  IF( a.LT.leps )
506  $ leps = a
507 *
508 * Computation of EPS complete.
509 *
510 * Now find EMIN. Let A = + or - 1, and + or - (1 + BASE**(-3)).
511 * Keep dividing A by BETA until (gradual) underflow occurs. This
512 * is detected when we cannot recover the previous A.
513 *
514  rbase = one / lbeta
515  small = one
516  DO 20 i = 1, 3
517  small = slamc3( small*rbase, zero )
518  20 CONTINUE
519  a = slamc3( one, small )
520  CALL slamc4( ngpmin, one, lbeta )
521  CALL slamc4( ngnmin, -one, lbeta )
522  CALL slamc4( gpmin, a, lbeta )
523  CALL slamc4( gnmin, -a, lbeta )
524  ieee = .false.
525 *
526  IF( ( ngpmin.EQ.ngnmin ) .AND. ( gpmin.EQ.gnmin ) ) THEN
527  IF( ngpmin.EQ.gpmin ) THEN
528  lemin = ngpmin
529 * ( Non twos-complement machines, no gradual underflow;
530 * e.g., VAX )
531  ELSE IF( ( gpmin-ngpmin ).EQ.3 ) THEN
532  lemin = ngpmin - 1 + lt
533  ieee = .true.
534 * ( Non twos-complement machines, with gradual underflow;
535 * e.g., IEEE standard followers )
536  ELSE
537  lemin = min( ngpmin, gpmin )
538 * ( A guess; no known machine )
539  iwarn = .true.
540  END IF
541 *
542  ELSE IF( ( ngpmin.EQ.gpmin ) .AND. ( ngnmin.EQ.gnmin ) ) THEN
543  IF( abs( ngpmin-ngnmin ).EQ.1 ) THEN
544  lemin = max( ngpmin, ngnmin )
545 * ( Twos-complement machines, no gradual underflow;
546 * e.g., CYBER 205 )
547  ELSE
548  lemin = min( ngpmin, ngnmin )
549 * ( A guess; no known machine )
550  iwarn = .true.
551  END IF
552 *
553  ELSE IF( ( abs( ngpmin-ngnmin ).EQ.1 ) .AND.
554  $ ( gpmin.EQ.gnmin ) ) THEN
555  IF( ( gpmin-min( ngpmin, ngnmin ) ).EQ.3 ) THEN
556  lemin = max( ngpmin, ngnmin ) - 1 + lt
557 * ( Twos-complement machines with gradual underflow;
558 * no known machine )
559  ELSE
560  lemin = min( ngpmin, ngnmin )
561 * ( A guess; no known machine )
562  iwarn = .true.
563  END IF
564 *
565  ELSE
566  lemin = min( ngpmin, ngnmin, gpmin, gnmin )
567 * ( A guess; no known machine )
568  iwarn = .true.
569  END IF
570  first = .false.
571 ***
572 * Comment out this if block if EMIN is ok
573  IF( iwarn ) THEN
574  first = .true.
575  WRITE( 6, fmt = 9999 )lemin
576  END IF
577 ***
578 *
579 * Assume IEEE arithmetic if we found denormalised numbers above,
580 * or if arithmetic seems to round in the IEEE style, determined
581 * in routine SLAMC1. A true IEEE machine should have both things
582 * true; however, faulty machines may have one or the other.
583 *
584  ieee = ieee .OR. lieee1
585 *
586 * Compute RMIN by successive division by BETA. We could compute
587 * RMIN as BASE**( EMIN - 1 ), but some machines underflow during
588 * this computation.
589 *
590  lrmin = 1
591  DO 30 i = 1, 1 - lemin
592  lrmin = slamc3( lrmin*rbase, zero )
593  30 CONTINUE
594 *
595 * Finally, call SLAMC5 to compute EMAX and RMAX.
596 *
597  CALL slamc5( lbeta, lt, lemin, ieee, lemax, lrmax )
598  END IF
599 *
600  beta = lbeta
601  t = lt
602  rnd = lrnd
603  eps = leps
604  emin = lemin
605  rmin = lrmin
606  emax = lemax
607  rmax = lrmax
608 *
609  RETURN
610 *
611  9999 FORMAT( / / ' WARNING. The value EMIN may be incorrect:-',
612  $ ' EMIN = ', i8, /
613  $ ' If, after inspection, the value EMIN looks',
614  $ ' acceptable please comment out ',
615  $ / ' the IF block as marked within the code of routine',
616  $ ' SLAMC2,', / ' otherwise supply EMIN explicitly.', / )
617 *
618 * End of SLAMC2
619 *
620  END
621 *
622 ************************************************************************
623 *> \brief \b SLAMC3
624 *> \details
625 *> \b Purpose:
626 *> \verbatim
627 *> SLAMC3 is intended to force A and B to be stored prior to doing
628 *> the addition of A and B , for use in situations where optimizers
629 *> might hold one of these in a register.
630 *> \endverbatim
631 *>
632 *> \param[in] A
633 *>
634 *> \param[in] B
635 *> \verbatim
636 *> The values A and B.
637 *> \endverbatim
638 *>
639 *> \ingroup lamc3
640 *>
641  REAL FUNCTION slamc3( A, B )
642 *
643 * -- LAPACK auxiliary routine --
644 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
645 *
646 * .. Scalar Arguments ..
647  REAL A, B
648 * ..
649 * =====================================================================
650 *
651 * .. Executable Statements ..
652 *
653  slamc3 = a + b
654 *
655  RETURN
656 *
657 * End of SLAMC3
658 *
659  END
660 *
661 ************************************************************************
662 *> \brief \b SLAMC4
663 *> \details
664 *> \b Purpose:
665 *> \verbatim
666 *> SLAMC4 is a service routine for SLAMC2.
667 *> \endverbatim
668 *>
669 *> \param[out] EMIN
670 *> \verbatim
671 *> The minimum exponent before (gradual) underflow, computed by
672 *> setting A = START and dividing by BASE until the previous A
673 *> can not be recovered.
674 *> \endverbatim
675 *>
676 *> \param[in] START
677 *> \verbatim
678 *> The starting point for determining EMIN.
679 *> \endverbatim
680 *>
681 *> \param[in] BASE
682 *> \verbatim
683 *> The base of the machine.
684 *> \endverbatim
685 *>
686 *> \ingroup lamc4
687 *>
688  SUBROUTINE slamc4( EMIN, START, BASE )
689 *
690 * -- LAPACK auxiliary routine --
691 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
692 *
693 * .. Scalar Arguments ..
694  INTEGER BASE
695  INTEGER EMIN
696  REAL START
697 * ..
698 * =====================================================================
699 *
700 * .. Local Scalars ..
701  INTEGER I
702  REAL A, B1, B2, C1, C2, D1, D2, ONE, RBASE, ZERO
703 * ..
704 * .. External Functions ..
705  REAL SLAMC3
706  EXTERNAL slamc3
707 * ..
708 * .. Executable Statements ..
709 *
710  a = start
711  one = 1
712  rbase = one / base
713  zero = 0
714  emin = 1
715  b1 = slamc3( 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 = slamc3( a / base, zero )
728  c1 = slamc3( b1*base, zero )
729  d1 = zero
730  DO 20 i = 1, base
731  d1 = d1 + b1
732  20 CONTINUE
733  b2 = slamc3( a*rbase, zero )
734  c2 = slamc3( 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 SLAMC4
746 *
747  END
748 *
749 ************************************************************************
750 *> \brief \b SLAMC5
751 *> \details
752 *> \b Purpose:
753 *> \verbatim
754 *> SLAMC5 attempts to compute RMAX, the largest machine floating-point
755 *> number, without overflow. It assumes that EMAX + abs(EMIN) sum
756 *> approximately to a power of 2. It will fail on machines where this
757 *> assumption does not hold, for example, the Cyber 205 (EMIN = -28625,
758 *> EMAX = 28718). It will also fail if the value supplied for EMIN is
759 *> too large (i.e. too close to zero), probably with overflow.
760 *> \endverbatim
761 *>
762 *> \param[in] BETA
763 *> \verbatim
764 *> The base of floating-point arithmetic.
765 *> \endverbatim
766 *>
767 *> \param[in] P
768 *> \verbatim
769 *> The number of base BETA digits in the mantissa of a
770 *> floating-point value.
771 *> \endverbatim
772 *>
773 *> \param[in] EMIN
774 *> \verbatim
775 *> The minimum exponent before (gradual) underflow.
776 *> \endverbatim
777 *>
778 *> \param[in] IEEE
779 *> \verbatim
780 *> A logical flag specifying whether or not the arithmetic
781 *> system is thought to comply with the IEEE standard.
782 *> \endverbatim
783 *>
784 *> \param[out] EMAX
785 *> \verbatim
786 *> The largest exponent before overflow
787 *> \endverbatim
788 *>
789 *> \param[out] RMAX
790 *> \verbatim
791 *> The largest machine floating-point number.
792 *> \endverbatim
793 *>
794 *> \ingroup lamc5
795 *>
796  SUBROUTINE slamc5( BETA, P, EMIN, IEEE, EMAX, RMAX )
797 *
798 * -- LAPACK auxiliary routine --
799 * Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
800 *
801 * .. Scalar Arguments ..
802  LOGICAL IEEE
803  INTEGER BETA, EMAX, EMIN, P
804  REAL RMAX
805 * ..
806 * =====================================================================
807 *
808 * .. Parameters ..
809  REAL ZERO, ONE
810  parameter( zero = 0.0e0, one = 1.0e0 )
811 * ..
812 * .. Local Scalars ..
813  INTEGER EXBITS, EXPSUM, I, LEXP, NBITS, TRY, UEXP
814  REAL OLDY, RECBAS, Y, Z
815 * ..
816 * .. External Functions ..
817  REAL SLAMC3
818  EXTERNAL slamc3
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 = slamc3( 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 = slamc3( y*beta, zero )
911  30 CONTINUE
912 *
913  rmax = y
914  RETURN
915 *
916 * End of SLAMC5
917 *
918  END
logical function lsame(CA, CB)
LSAME
Definition: lsame.f:53
subroutine slamc5(BETA, P, EMIN, IEEE, EMAX, RMAX)
SLAMC5
Definition: slamchf77.f:797
subroutine slamc1(BETA, T, RND, IEEE1)
SLAMC1
Definition: slamchf77.f:207
real function slamc3(A, B)
SLAMC3
Definition: slamch.f:171
real function slamch(CMACH)
SLAMCH
Definition: slamch.f:68
subroutine slamc4(EMIN, START, BASE)
SLAMC4
Definition: slamchf77.f:689
subroutine slamc2(BETA, T, RND, EPS, EMIN, RMIN, EMAX, RMAX)
SLAMC2
Definition: slamchf77.f:419