~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/sparse/SuperLU/SRC/dlamch.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T. Chen (new)
  • Date: 2005-03-16 02:15:29 UTC
  • Revision ID: james.westby@ubuntu.com-20050316021529-xrjlowsejs0cijig
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

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