C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / INSTALL / dlamch.c
1 #include <math.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <stdio.h>
5 #include <complex.h>
6 #ifdef complex
7 #undef complex
8 #endif
9 #ifdef I
10 #undef I
11 #endif
12
13 #if defined(_WIN64)
14 typedef long long BLASLONG;
15 typedef unsigned long long BLASULONG;
16 #else
17 typedef long BLASLONG;
18 typedef unsigned long BLASULONG;
19 #endif
20
21 #ifdef LAPACK_ILP64
22 typedef BLASLONG blasint;
23 #if defined(_WIN64)
24 #define blasabs(x) llabs(x)
25 #else
26 #define blasabs(x) labs(x)
27 #endif
28 #else
29 typedef int blasint;
30 #define blasabs(x) abs(x)
31 #endif
32
33 typedef blasint integer;
34
35 typedef unsigned int uinteger;
36 typedef char *address;
37 typedef short int shortint;
38 typedef float real;
39 typedef double doublereal;
40 typedef struct { real r, i; } complex;
41 typedef struct { doublereal r, i; } doublecomplex;
42 #ifdef _MSC_VER
43 static inline _Fcomplex Cf(complex *z) {_Fcomplex zz={z->r , z->i}; return zz;}
44 static inline _Dcomplex Cd(doublecomplex *z) {_Dcomplex zz={z->r , z->i};return zz;}
45 static inline _Fcomplex * _pCf(complex *z) {return (_Fcomplex*)z;}
46 static inline _Dcomplex * _pCd(doublecomplex *z) {return (_Dcomplex*)z;}
47 #else
48 static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;}
49 static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;}
50 static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;}
51 static inline _Complex double * _pCd(doublecomplex *z) {return (_Complex double*)z;}
52 #endif
53 #define pCf(z) (*_pCf(z))
54 #define pCd(z) (*_pCd(z))
55 typedef int logical;
56 typedef short int shortlogical;
57 typedef char logical1;
58 typedef char integer1;
59
60 #define TRUE_ (1)
61 #define FALSE_ (0)
62
63 /* Extern is for use with -E */
64 #ifndef Extern
65 #define Extern extern
66 #endif
67
68 /* I/O stuff */
69
70 typedef int flag;
71 typedef int ftnlen;
72 typedef int ftnint;
73
74 /*external read, write*/
75 typedef struct
76 {       flag cierr;
77         ftnint ciunit;
78         flag ciend;
79         char *cifmt;
80         ftnint cirec;
81 } cilist;
82
83 /*internal read, write*/
84 typedef struct
85 {       flag icierr;
86         char *iciunit;
87         flag iciend;
88         char *icifmt;
89         ftnint icirlen;
90         ftnint icirnum;
91 } icilist;
92
93 /*open*/
94 typedef struct
95 {       flag oerr;
96         ftnint ounit;
97         char *ofnm;
98         ftnlen ofnmlen;
99         char *osta;
100         char *oacc;
101         char *ofm;
102         ftnint orl;
103         char *oblnk;
104 } olist;
105
106 /*close*/
107 typedef struct
108 {       flag cerr;
109         ftnint cunit;
110         char *csta;
111 } cllist;
112
113 /*rewind, backspace, endfile*/
114 typedef struct
115 {       flag aerr;
116         ftnint aunit;
117 } alist;
118
119 /* inquire */
120 typedef struct
121 {       flag inerr;
122         ftnint inunit;
123         char *infile;
124         ftnlen infilen;
125         ftnint  *inex;  /*parameters in standard's order*/
126         ftnint  *inopen;
127         ftnint  *innum;
128         ftnint  *innamed;
129         char    *inname;
130         ftnlen  innamlen;
131         char    *inacc;
132         ftnlen  inacclen;
133         char    *inseq;
134         ftnlen  inseqlen;
135         char    *indir;
136         ftnlen  indirlen;
137         char    *infmt;
138         ftnlen  infmtlen;
139         char    *inform;
140         ftnint  informlen;
141         char    *inunf;
142         ftnlen  inunflen;
143         ftnint  *inrecl;
144         ftnint  *innrec;
145         char    *inblank;
146         ftnlen  inblanklen;
147 } inlist;
148
149 #define VOID void
150
151 union Multitype {       /* for multiple entry points */
152         integer1 g;
153         shortint h;
154         integer i;
155         /* longint j; */
156         real r;
157         doublereal d;
158         complex c;
159         doublecomplex z;
160         };
161
162 typedef union Multitype Multitype;
163
164 struct Vardesc {        /* for Namelist */
165         char *name;
166         char *addr;
167         ftnlen *dims;
168         int  type;
169         };
170 typedef struct Vardesc Vardesc;
171
172 struct Namelist {
173         char *name;
174         Vardesc **vars;
175         int nvars;
176         };
177 typedef struct Namelist Namelist;
178
179 #define abs(x) ((x) >= 0 ? (x) : -(x))
180 #define dabs(x) (fabs(x))
181 #define f2cmin(a,b) ((a) <= (b) ? (a) : (b))
182 #define f2cmax(a,b) ((a) >= (b) ? (a) : (b))
183 #define dmin(a,b) (f2cmin(a,b))
184 #define dmax(a,b) (f2cmax(a,b))
185 #define bit_test(a,b)   ((a) >> (b) & 1)
186 #define bit_clear(a,b)  ((a) & ~((uinteger)1 << (b)))
187 #define bit_set(a,b)    ((a) |  ((uinteger)1 << (b)))
188
189 #define abort_() { sig_die("Fortran abort routine called", 1); }
190 #define c_abs(z) (cabsf(Cf(z)))
191 #define c_cos(R,Z) { pCf(R)=ccos(Cf(Z)); }
192 #ifdef _MSC_VER
193 #define c_div(c, a, b) {Cf(c)._Val[0] = (Cf(a)._Val[0]/Cf(b)._Val[0]); Cf(c)._Val[1]=(Cf(a)._Val[1]/Cf(b)._Val[1]);}
194 #define z_div(c, a, b) {Cd(c)._Val[0] = (Cd(a)._Val[0]/Cd(b)._Val[0]); Cd(c)._Val[1]=(Cd(a)._Val[1]/df(b)._Val[1]);}
195 #else
196 #define c_div(c, a, b) {pCf(c) = Cf(a)/Cf(b);}
197 #define z_div(c, a, b) {pCd(c) = Cd(a)/Cd(b);}
198 #endif
199 #define c_exp(R, Z) {pCf(R) = cexpf(Cf(Z));}
200 #define c_log(R, Z) {pCf(R) = clogf(Cf(Z));}
201 #define c_sin(R, Z) {pCf(R) = csinf(Cf(Z));}
202 //#define c_sqrt(R, Z) {*(R) = csqrtf(Cf(Z));}
203 #define c_sqrt(R, Z) {pCf(R) = csqrtf(Cf(Z));}
204 #define d_abs(x) (fabs(*(x)))
205 #define d_acos(x) (acos(*(x)))
206 #define d_asin(x) (asin(*(x)))
207 #define d_atan(x) (atan(*(x)))
208 #define d_atn2(x, y) (atan2(*(x),*(y)))
209 #define d_cnjg(R, Z) { pCd(R) = conj(Cd(Z)); }
210 #define r_cnjg(R, Z) { pCf(R) = conjf(Cf(Z)); }
211 #define d_cos(x) (cos(*(x)))
212 #define d_cosh(x) (cosh(*(x)))
213 #define d_dim(__a, __b) ( *(__a) > *(__b) ? *(__a) - *(__b) : 0.0 )
214 #define d_exp(x) (exp(*(x)))
215 #define d_imag(z) (cimag(Cd(z)))
216 #define r_imag(z) (cimagf(Cf(z)))
217 #define d_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
218 #define r_int(__x) (*(__x)>0 ? floor(*(__x)) : -floor(- *(__x)))
219 #define d_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
220 #define r_lg10(x) ( 0.43429448190325182765 * log(*(x)) )
221 #define d_log(x) (log(*(x)))
222 #define d_mod(x, y) (fmod(*(x), *(y)))
223 #define u_nint(__x) ((__x)>=0 ? floor((__x) + .5) : -floor(.5 - (__x)))
224 #define d_nint(x) u_nint(*(x))
225 #define u_sign(__a,__b) ((__b) >= 0 ? ((__a) >= 0 ? (__a) : -(__a)) : -((__a) >= 0 ? (__a) : -(__a)))
226 #define d_sign(a,b) u_sign(*(a),*(b))
227 #define r_sign(a,b) u_sign(*(a),*(b))
228 #define d_sin(x) (sin(*(x)))
229 #define d_sinh(x) (sinh(*(x)))
230 #define d_sqrt(x) (sqrt(*(x)))
231 #define d_tan(x) (tan(*(x)))
232 #define d_tanh(x) (tanh(*(x)))
233 #define i_abs(x) abs(*(x))
234 #define i_dnnt(x) ((integer)u_nint(*(x)))
235 #define i_len(s, n) (n)
236 #define i_nint(x) ((integer)u_nint(*(x)))
237 #define i_sign(a,b) ((integer)u_sign((integer)*(a),(integer)*(b)))
238 #define pow_dd(ap, bp) ( pow(*(ap), *(bp)))
239 #define pow_si(B,E) spow_ui(*(B),*(E))
240 #define pow_ri(B,E) spow_ui(*(B),*(E))
241 #define pow_di(B,E) dpow_ui(*(B),*(E))
242 #define pow_zi(p, a, b) {pCd(p) = zpow_ui(Cd(a), *(b));}
243 #define pow_ci(p, a, b) {pCf(p) = cpow_ui(Cf(a), *(b));}
244 #define pow_zz(R,A,B) {pCd(R) = cpow(Cd(A),*(B));}
245 #define s_cat(lpp, rpp, rnp, np, llp) {         ftnlen i, nc, ll; char *f__rp, *lp;     ll = (llp); lp = (lpp);         for(i=0; i < (int)*(np); ++i) {                 nc = ll;                if((rnp)[i] < nc) nc = (rnp)[i];                ll -= nc;               f__rp = (rpp)[i];               while(--nc >= 0) *lp++ = *(f__rp)++;         }  while(--ll >= 0) *lp++ = ' '; }
246 #define s_cmp(a,b,c,d) ((integer)strncmp((a),(b),f2cmin((c),(d))))
247 #define s_copy(A,B,C,D) { int __i,__m; for (__i=0, __m=f2cmin((C),(D)); __i<__m && (B)[__i] != 0; ++__i) (A)[__i] = (B)[__i]; }
248 #define sig_die(s, kill) { exit(1); }
249 #define s_stop(s, n) {exit(0);}
250 static char junk[] = "\n@(#)LIBF77 VERSION 19990503\n";
251 #define z_abs(z) (cabs(Cd(z)))
252 #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));}
253 #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));}
254 #define myexit_() break;
255 #define mycycle() continue;
256 #define myceiling(w) {ceil(w)}
257 #define myhuge(w) {HUGE_VAL}
258 //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);}
259 #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)}
260
261 /* procedure parameter types for -A and -C++ */
262
263 #define F2C_proc_par_types 1
264 #ifdef __cplusplus
265 typedef logical (*L_fp)(...);
266 #else
267 typedef logical (*L_fp)();
268 #endif
269
270 static float spow_ui(float x, integer n) {
271         float pow=1.0; unsigned long int u;
272         if(n != 0) {
273                 if(n < 0) n = -n, x = 1/x;
274                 for(u = n; ; ) {
275                         if(u & 01) pow *= x;
276                         if(u >>= 1) x *= x;
277                         else break;
278                 }
279         }
280         return pow;
281 }
282 static double dpow_ui(double x, integer n) {
283         double pow=1.0; unsigned long int u;
284         if(n != 0) {
285                 if(n < 0) n = -n, x = 1/x;
286                 for(u = n; ; ) {
287                         if(u & 01) pow *= x;
288                         if(u >>= 1) x *= x;
289                         else break;
290                 }
291         }
292         return pow;
293 }
294 #ifdef _MSC_VER
295 static _Fcomplex cpow_ui(complex x, integer n) {
296         complex pow={1.0,0.0}; unsigned long int u;
297                 if(n != 0) {
298                 if(n < 0) n = -n, x.r = 1/x.r, x.i=1/x.i;
299                 for(u = n; ; ) {
300                         if(u & 01) pow.r *= x.r, pow.i *= x.i;
301                         if(u >>= 1) x.r *= x.r, x.i *= x.i;
302                         else break;
303                 }
304         }
305         _Fcomplex p={pow.r, pow.i};
306         return p;
307 }
308 #else
309 static _Complex float cpow_ui(_Complex float x, integer n) {
310         _Complex float pow=1.0; unsigned long int u;
311         if(n != 0) {
312                 if(n < 0) n = -n, x = 1/x;
313                 for(u = n; ; ) {
314                         if(u & 01) pow *= x;
315                         if(u >>= 1) x *= x;
316                         else break;
317                 }
318         }
319         return pow;
320 }
321 #endif
322 #ifdef _MSC_VER
323 static _Dcomplex zpow_ui(_Dcomplex x, integer n) {
324         _Dcomplex pow={1.0,0.0}; unsigned long int u;
325         if(n != 0) {
326                 if(n < 0) n = -n, x._Val[0] = 1/x._Val[0], x._Val[1] =1/x._Val[1];
327                 for(u = n; ; ) {
328                         if(u & 01) pow._Val[0] *= x._Val[0], pow._Val[1] *= x._Val[1];
329                         if(u >>= 1) x._Val[0] *= x._Val[0], x._Val[1] *= x._Val[1];
330                         else break;
331                 }
332         }
333         _Dcomplex p = {pow._Val[0], pow._Val[1]};
334         return p;
335 }
336 #else
337 static _Complex double zpow_ui(_Complex double x, integer n) {
338         _Complex double pow=1.0; unsigned long int u;
339         if(n != 0) {
340                 if(n < 0) n = -n, x = 1/x;
341                 for(u = n; ; ) {
342                         if(u & 01) pow *= x;
343                         if(u >>= 1) x *= x;
344                         else break;
345                 }
346         }
347         return pow;
348 }
349 #endif
350 static integer pow_ii(integer x, integer n) {
351         integer pow; unsigned long int u;
352         if (n <= 0) {
353                 if (n == 0 || x == 1) pow = 1;
354                 else if (x != -1) pow = x == 0 ? 1/x : 0;
355                 else n = -n;
356         }
357         if ((n > 0) || !(n == 0 || x == 1 || x != -1)) {
358                 u = n;
359                 for(pow = 1; ; ) {
360                         if(u & 01) pow *= x;
361                         if(u >>= 1) x *= x;
362                         else break;
363                 }
364         }
365         return pow;
366 }
367 static integer dmaxloc_(double *w, integer s, integer e, integer *n)
368 {
369         double m; integer i, mi;
370         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
371                 if (w[i-1]>m) mi=i ,m=w[i-1];
372         return mi-s+1;
373 }
374 static integer smaxloc_(float *w, integer s, integer e, integer *n)
375 {
376         float m; integer i, mi;
377         for(m=w[s-1], mi=s, i=s+1; i<=e; i++)
378                 if (w[i-1]>m) mi=i ,m=w[i-1];
379         return mi-s+1;
380 }
381 static inline void cdotc_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
382         integer n = *n_, incx = *incx_, incy = *incy_, i;
383 #ifdef _MSC_VER
384         _Fcomplex zdotc = {0.0, 0.0};
385         if (incx == 1 && incy == 1) {
386                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
387                         zdotc._Val[0] += conjf(Cf(&x[i]))._Val[0] * Cf(&y[i])._Val[0];
388                         zdotc._Val[1] += conjf(Cf(&x[i]))._Val[1] * Cf(&y[i])._Val[1];
389                 }
390         } else {
391                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
392                         zdotc._Val[0] += conjf(Cf(&x[i*incx]))._Val[0] * Cf(&y[i*incy])._Val[0];
393                         zdotc._Val[1] += conjf(Cf(&x[i*incx]))._Val[1] * Cf(&y[i*incy])._Val[1];
394                 }
395         }
396         pCf(z) = zdotc;
397 }
398 #else
399         _Complex float zdotc = 0.0;
400         if (incx == 1 && incy == 1) {
401                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
402                         zdotc += conjf(Cf(&x[i])) * Cf(&y[i]);
403                 }
404         } else {
405                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
406                         zdotc += conjf(Cf(&x[i*incx])) * Cf(&y[i*incy]);
407                 }
408         }
409         pCf(z) = zdotc;
410 }
411 #endif
412 static inline void zdotc_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
413         integer n = *n_, incx = *incx_, incy = *incy_, i;
414 #ifdef _MSC_VER
415         _Dcomplex zdotc = {0.0, 0.0};
416         if (incx == 1 && incy == 1) {
417                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
418                         zdotc._Val[0] += conj(Cd(&x[i]))._Val[0] * Cd(&y[i])._Val[0];
419                         zdotc._Val[1] += conj(Cd(&x[i]))._Val[1] * Cd(&y[i])._Val[1];
420                 }
421         } else {
422                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
423                         zdotc._Val[0] += conj(Cd(&x[i*incx]))._Val[0] * Cd(&y[i*incy])._Val[0];
424                         zdotc._Val[1] += conj(Cd(&x[i*incx]))._Val[1] * Cd(&y[i*incy])._Val[1];
425                 }
426         }
427         pCd(z) = zdotc;
428 }
429 #else
430         _Complex double zdotc = 0.0;
431         if (incx == 1 && incy == 1) {
432                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
433                         zdotc += conj(Cd(&x[i])) * Cd(&y[i]);
434                 }
435         } else {
436                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
437                         zdotc += conj(Cd(&x[i*incx])) * Cd(&y[i*incy]);
438                 }
439         }
440         pCd(z) = zdotc;
441 }
442 #endif  
443 static inline void cdotu_(complex *z, integer *n_, complex *x, integer *incx_, complex *y, integer *incy_) {
444         integer n = *n_, incx = *incx_, incy = *incy_, i;
445 #ifdef _MSC_VER
446         _Fcomplex zdotc = {0.0, 0.0};
447         if (incx == 1 && incy == 1) {
448                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
449                         zdotc._Val[0] += Cf(&x[i])._Val[0] * Cf(&y[i])._Val[0];
450                         zdotc._Val[1] += Cf(&x[i])._Val[1] * Cf(&y[i])._Val[1];
451                 }
452         } else {
453                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
454                         zdotc._Val[0] += Cf(&x[i*incx])._Val[0] * Cf(&y[i*incy])._Val[0];
455                         zdotc._Val[1] += Cf(&x[i*incx])._Val[1] * Cf(&y[i*incy])._Val[1];
456                 }
457         }
458         pCf(z) = zdotc;
459 }
460 #else
461         _Complex float zdotc = 0.0;
462         if (incx == 1 && incy == 1) {
463                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
464                         zdotc += Cf(&x[i]) * Cf(&y[i]);
465                 }
466         } else {
467                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
468                         zdotc += Cf(&x[i*incx]) * Cf(&y[i*incy]);
469                 }
470         }
471         pCf(z) = zdotc;
472 }
473 #endif
474 static inline void zdotu_(doublecomplex *z, integer *n_, doublecomplex *x, integer *incx_, doublecomplex *y, integer *incy_) {
475         integer n = *n_, incx = *incx_, incy = *incy_, i;
476 #ifdef _MSC_VER
477         _Dcomplex zdotc = {0.0, 0.0};
478         if (incx == 1 && incy == 1) {
479                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
480                         zdotc._Val[0] += Cd(&x[i])._Val[0] * Cd(&y[i])._Val[0];
481                         zdotc._Val[1] += Cd(&x[i])._Val[1] * Cd(&y[i])._Val[1];
482                 }
483         } else {
484                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
485                         zdotc._Val[0] += Cd(&x[i*incx])._Val[0] * Cd(&y[i*incy])._Val[0];
486                         zdotc._Val[1] += Cd(&x[i*incx])._Val[1] * Cd(&y[i*incy])._Val[1];
487                 }
488         }
489         pCd(z) = zdotc;
490 }
491 #else
492         _Complex double zdotc = 0.0;
493         if (incx == 1 && incy == 1) {
494                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
495                         zdotc += Cd(&x[i]) * Cd(&y[i]);
496                 }
497         } else {
498                 for (i=0;i<n;i++) { /* zdotc = zdotc + dconjg(x(i))* y(i) */
499                         zdotc += Cd(&x[i*incx]) * Cd(&y[i*incy]);
500                 }
501         }
502         pCd(z) = zdotc;
503 }
504 #endif
505 /*  -- translated by f2c (version 20000121).
506    You must link the resulting object file with the libraries:
507         -lf2c -lm   (in that order)
508 */
509
510
511
512
513 /* Table of constant values */
514
515 static integer c__1 = 1;
516 static doublereal c_b32 = 0.;
517
518 /* > \brief \b DLAMCHF77 deprecated */
519
520 /*  =========== DOCUMENTATION =========== */
521
522 /* Online html documentation available at */
523 /*            http://www.netlib.org/lapack/explore-html/ */
524
525 /*  Definition: */
526 /*  =========== */
527
528 /*      DOUBLE PRECISION FUNCTION DLAMCH( CMACH ) */
529
530 /*     CHARACTER          CMACH */
531
532
533 /* > \par Purpose: */
534 /*  ============= */
535 /* > */
536 /* > \verbatim */
537 /* > */
538 /* > DLAMCHF77 determines double precision machine parameters. */
539 /* > \endverbatim */
540
541 /*  Arguments: */
542 /*  ========== */
543
544 /* > \param[in] CMACH */
545 /* > \verbatim */
546 /* >          Specifies the value to be returned by DLAMCH: */
547 /* >          = 'E' or 'e',   DLAMCH := eps */
548 /* >          = 'S' or 's ,   DLAMCH := sfmin */
549 /* >          = 'B' or 'b',   DLAMCH := base */
550 /* >          = 'P' or 'p',   DLAMCH := eps*base */
551 /* >          = 'N' or 'n',   DLAMCH := t */
552 /* >          = 'R' or 'r',   DLAMCH := rnd */
553 /* >          = 'M' or 'm',   DLAMCH := emin */
554 /* >          = 'U' or 'u',   DLAMCH := rmin */
555 /* >          = 'L' or 'l',   DLAMCH := emax */
556 /* >          = 'O' or 'o',   DLAMCH := rmax */
557 /* >          where */
558 /* >          eps   = relative machine precision */
559 /* >          sfmin = safe minimum, such that 1/sfmin does not overflow */
560 /* >          base  = base of the machine */
561 /* >          prec  = eps*base */
562 /* >          t     = number of (base) digits in the mantissa */
563 /* >          rnd   = 1.0 when rounding occurs in addition, 0.0 otherwise */
564 /* >          emin  = minimum exponent before (gradual) underflow */
565 /* >          rmin  = underflow threshold - base**(emin-1) */
566 /* >          emax  = largest exponent before overflow */
567 /* >          rmax  = overflow threshold  - (base**emax)*(1-eps) */
568 /* > \endverbatim */
569
570 /*  Authors: */
571 /*  ======== */
572
573 /* > \author Univ. of Tennessee */
574 /* > \author Univ. of California Berkeley */
575 /* > \author Univ. of Colorado Denver */
576 /* > \author NAG Ltd. */
577
578 /* > \date April 2012 */
579
580 /* > \ingroup auxOTHERauxiliary */
581
582 /*  ===================================================================== */
583 doublereal dlamch_(char *cmach)
584 {
585     /* Initialized data */
586
587     static logical first = TRUE_;
588
589     /* System generated locals */
590     integer i__1;
591     doublereal ret_val;
592
593     /* Local variables */
594     static doublereal base;
595     integer beta;
596     static doublereal emin, prec, emax;
597     integer imin, imax;
598     logical lrnd;
599     static doublereal rmin, rmax, t;
600     doublereal rmach;
601     extern logical lsame_(char *, char *);
602     doublereal small;
603     static doublereal sfmin;
604     extern /* Subroutine */ int dlamc2_(integer *, integer *, logical *, 
605             doublereal *, integer *, doublereal *, integer *, doublereal *);
606     integer it;
607     static doublereal rnd, eps;
608
609
610 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
611 /*  -- LAPACK is a software package provided by Univ. of Tennessee,    -- */
612 /*  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */
613 /*     April 2012 */
614
615
616     if (first) {
617         dlamc2_(&beta, &it, &lrnd, &eps, &imin, &rmin, &imax, &rmax);
618         base = (doublereal) beta;
619         t = (doublereal) it;
620         if (lrnd) {
621             rnd = 1.;
622             i__1 = 1 - it;
623             eps = pow_di(&base, &i__1) / 2;
624         } else {
625             rnd = 0.;
626             i__1 = 1 - it;
627             eps = pow_di(&base, &i__1);
628         }
629         prec = eps * base;
630         emin = (doublereal) imin;
631         emax = (doublereal) imax;
632         sfmin = rmin;
633         small = 1. / rmax;
634         if (small >= sfmin) {
635
636 /*           Use SMALL plus a bit, to avoid the possibility of rounding */
637 /*           causing overflow when computing  1/sfmin. */
638
639             sfmin = small * (eps + 1.);
640         }
641     }
642
643     if (lsame_(cmach, "E")) {
644         rmach = eps;
645     } else if (lsame_(cmach, "S")) {
646         rmach = sfmin;
647     } else if (lsame_(cmach, "B")) {
648         rmach = base;
649     } else if (lsame_(cmach, "P")) {
650         rmach = prec;
651     } else if (lsame_(cmach, "N")) {
652         rmach = t;
653     } else if (lsame_(cmach, "R")) {
654         rmach = rnd;
655     } else if (lsame_(cmach, "M")) {
656         rmach = emin;
657     } else if (lsame_(cmach, "U")) {
658         rmach = rmin;
659     } else if (lsame_(cmach, "L")) {
660         rmach = emax;
661     } else if (lsame_(cmach, "O")) {
662         rmach = rmax;
663     }
664
665     ret_val = rmach;
666     first = FALSE_;
667     return ret_val;
668
669 /*     End of DLAMCH */
670
671 } /* dlamch_ */
672
673
674 /* *********************************************************************** */
675
676 /* > \brief \b DLAMC1 */
677 /* > \details */
678 /* > \b Purpose: */
679 /* > \verbatim */
680 /* > DLAMC1 determines the machine parameters given by BETA, T, RND, and */
681 /* > IEEE1. */
682 /* > \endverbatim */
683 /* > */
684 /* > \param[out] BETA */
685 /* > \verbatim */
686 /* >          The base of the machine. */
687 /* > \endverbatim */
688 /* > */
689 /* > \param[out] T */
690 /* > \verbatim */
691 /* >          The number of ( BETA ) digits in the mantissa. */
692 /* > \endverbatim */
693 /* > */
694 /* > \param[out] RND */
695 /* > \verbatim */
696 /* >          Specifies whether proper rounding  ( RND = .TRUE. )  or */
697 /* >          chopping  ( RND = .FALSE. )  occurs in addition. This may not */
698 /* >          be a reliable guide to the way in which the machine performs */
699 /* >          its arithmetic. */
700 /* > \endverbatim */
701 /* > */
702 /* > \param[out] IEEE1 */
703 /* > \verbatim */
704 /* >          Specifies whether rounding appears to be done in the IEEE */
705 /* >          'round to nearest' style. */
706 /* > \endverbatim */
707 /* > \author LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. 
708 of Colorado Denver and NAG Ltd.. */
709 /* > \date April 2012 */
710 /* > \ingroup auxOTHERauxiliary */
711 /* > */
712 /* > \details \b Further \b Details */
713 /* > \verbatim */
714 /* > */
715 /* >  The routine is based on the routine  ENVRON  by Malcolm and */
716 /* >  incorporates suggestions by Gentleman and Marovich. See */
717 /* > */
718 /* >     Malcolm M. A. (1972) Algorithms to reveal properties of */
719 /* >        floating-point arithmetic. Comms. of the ACM, 15, 949-951. */
720 /* > */
721 /* >     Gentleman W. M. and Marovich S. B. (1974) More on algorithms */
722 /* >        that reveal properties of floating point arithmetic units. */
723 /* >        Comms. of the ACM, 17, 276-277. */
724 /* > \endverbatim */
725 /* > */
726 /* Subroutine */ int dlamc1_(integer *beta, integer *t, logical *rnd, logical 
727         *ieee1)
728 {
729     /* Initialized data */
730
731     static logical first = TRUE_;
732
733     /* System generated locals */
734     doublereal d__1, d__2;
735
736     /* Local variables */
737     static logical lrnd;
738     doublereal a, b, c__, f;
739     static integer lbeta;
740     doublereal savec;
741     extern doublereal dlamc3_(doublereal *, doublereal *);
742     static logical lieee1;
743     doublereal t1, t2;
744     static integer lt;
745     doublereal one, qtr;
746
747
748 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
749 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
750 /*     November 2010 */
751
752 /* ===================================================================== */
753
754
755     if (first) {
756         one = 1.;
757
758 /*        LBETA,  LIEEE1,  LT and  LRND  are the  local values  of  BETA, */
759 /*        IEEE1, T and RND. */
760
761 /*        Throughout this routine  we use the function  DLAMC3  to ensure */
762 /*        that relevant values are  stored and not held in registers,  or */
763 /*        are not affected by optimizers. */
764
765 /*        Compute  a = 2.0**m  with the  smallest positive integer m such */
766 /*        that */
767
768 /*           fl( a + 1.0 ) = a. */
769
770         a = 1.;
771         c__ = 1.;
772
773 /* +       WHILE( C.EQ.ONE )LOOP */
774 L10:
775         if (c__ == one) {
776             a *= 2;
777             c__ = dlamc3_(&a, &one);
778             d__1 = -a;
779             c__ = dlamc3_(&c__, &d__1);
780             goto L10;
781         }
782 /* +       END WHILE */
783
784 /*        Now compute  b = 2.0**m  with the smallest positive integer m */
785 /*        such that */
786
787 /*           fl( a + b ) .gt. a. */
788
789         b = 1.;
790         c__ = dlamc3_(&a, &b);
791
792 /* +       WHILE( C.EQ.A )LOOP */
793 L20:
794         if (c__ == a) {
795             b *= 2;
796             c__ = dlamc3_(&a, &b);
797             goto L20;
798         }
799 /* +       END WHILE */
800
801 /*        Now compute the base.  a and c  are neighbouring floating point */
802 /*        numbers  in the  interval  ( beta**t, beta**( t + 1 ) )  and so */
803 /*        their difference is beta. Adding 0.25 to c is to ensure that it */
804 /*        is truncated to beta and not ( beta - 1 ). */
805
806         qtr = one / 4;
807         savec = c__;
808         d__1 = -a;
809         c__ = dlamc3_(&c__, &d__1);
810         lbeta = (integer) (c__ + qtr);
811
812 /*        Now determine whether rounding or chopping occurs,  by adding a */
813 /*        bit  less  than  beta/2  and a  bit  more  than  beta/2  to  a. */
814
815         b = (doublereal) lbeta;
816         d__1 = b / 2;
817         d__2 = -b / 100;
818         f = dlamc3_(&d__1, &d__2);
819         c__ = dlamc3_(&f, &a);
820         if (c__ == a) {
821             lrnd = TRUE_;
822         } else {
823             lrnd = FALSE_;
824         }
825         d__1 = b / 2;
826         d__2 = b / 100;
827         f = dlamc3_(&d__1, &d__2);
828         c__ = dlamc3_(&f, &a);
829         if (lrnd && c__ == a) {
830             lrnd = FALSE_;
831         }
832
833 /*        Try and decide whether rounding is done in the  IEEE  'round to */
834 /*        nearest' style. B/2 is half a unit in the last place of the two */
835 /*        numbers A and SAVEC. Furthermore, A is even, i.e. has last  bit */
836 /*        zero, and SAVEC is odd. Thus adding B/2 to A should not  change */
837 /*        A, but adding B/2 to SAVEC should change SAVEC. */
838
839         d__1 = b / 2;
840         t1 = dlamc3_(&d__1, &a);
841         d__1 = b / 2;
842         t2 = dlamc3_(&d__1, &savec);
843         lieee1 = t1 == a && t2 > savec && lrnd;
844
845 /*        Now find  the  mantissa, t.  It should  be the  integer part of */
846 /*        log to the base beta of a,  however it is safer to determine  t */
847 /*        by powering.  So we find t as the smallest positive integer for */
848 /*        which */
849
850 /*           fl( beta**t + 1.0 ) = 1.0. */
851
852         lt = 0;
853         a = 1.;
854         c__ = 1.;
855
856 /* +       WHILE( C.EQ.ONE )LOOP */
857 L30:
858         if (c__ == one) {
859             ++lt;
860             a *= lbeta;
861             c__ = dlamc3_(&a, &one);
862             d__1 = -a;
863             c__ = dlamc3_(&c__, &d__1);
864             goto L30;
865         }
866 /* +       END WHILE */
867
868     }
869
870     *beta = lbeta;
871     *t = lt;
872     *rnd = lrnd;
873     *ieee1 = lieee1;
874     first = FALSE_;
875     return 0;
876
877 /*     End of DLAMC1 */
878
879 } /* dlamc1_ */
880
881
882 /* *********************************************************************** */
883
884 /* > \brief \b DLAMC2 */
885 /* > \details */
886 /* > \b Purpose: */
887 /* > \verbatim */
888 /* > DLAMC2 determines the machine parameters specified in its argument */
889 /* > list. */
890 /* > \endverbatim */
891 /* > \author LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. 
892 of Colorado Denver and NAG Ltd.. */
893 /* > \date April 2012 */
894 /* > \ingroup auxOTHERauxiliary */
895 /* > */
896 /* > \param[out] BETA */
897 /* > \verbatim */
898 /* >          The base of the machine. */
899 /* > \endverbatim */
900 /* > */
901 /* > \param[out] T */
902 /* > \verbatim */
903 /* >          The number of ( BETA ) digits in the mantissa. */
904 /* > \endverbatim */
905 /* > */
906 /* > \param[out] RND */
907 /* > \verbatim */
908 /* >          Specifies whether proper rounding  ( RND = .TRUE. )  or */
909 /* >          chopping  ( RND = .FALSE. )  occurs in addition. This may not */
910 /* >          be a reliable guide to the way in which the machine performs */
911 /* >          its arithmetic. */
912 /* > \endverbatim */
913 /* > */
914 /* > \param[out] EPS */
915 /* > \verbatim */
916 /* >          The smallest positive number such that */
917 /* >             fl( 1.0 - EPS ) .LT. 1.0, */
918 /* >          where fl denotes the computed value. */
919 /* > \endverbatim */
920 /* > */
921 /* > \param[out] EMIN */
922 /* > \verbatim */
923 /* >          The minimum exponent before (gradual) underflow occurs. */
924 /* > \endverbatim */
925 /* > */
926 /* > \param[out] RMIN */
927 /* > \verbatim */
928 /* >          The smallest normalized number for the machine, given by */
929 /* >          BASE**( EMIN - 1 ), where  BASE  is the floating point value */
930 /* >          of BETA. */
931 /* > \endverbatim */
932 /* > */
933 /* > \param[out] EMAX */
934 /* > \verbatim */
935 /* >          The maximum exponent before overflow occurs. */
936 /* > \endverbatim */
937 /* > */
938 /* > \param[out] RMAX */
939 /* > \verbatim */
940 /* >          The largest positive number for the machine, given by */
941 /* >          BASE**EMAX * ( 1 - EPS ), where  BASE  is the floating point */
942 /* >          value of BETA. */
943 /* > \endverbatim */
944 /* > */
945 /* > \details \b Further \b Details */
946 /* > \verbatim */
947 /* > */
948 /* >  The computation of  EPS  is based on a routine PARANOIA by */
949 /* >  W. Kahan of the University of California at Berkeley. */
950 /* > \endverbatim */
951 /* Subroutine */ int dlamc2_(integer *beta, integer *t, logical *rnd, 
952         doublereal *eps, integer *emin, doublereal *rmin, integer *emax, 
953         doublereal *rmax)
954 {
955     /* Initialized data */
956
957     static logical first = TRUE_;
958     static logical iwarn = FALSE_;
959
960     /* Format strings */
961     static char fmt_9999[] = "(//\002 WARNING. The value EMIN may be incorre"
962             "ct:-\002,\002  EMIN = \002,i8,/\002 If, after inspection, the va"
963             "lue EMIN looks\002,\002 acceptable please comment out \002,/\002"
964             " the IF block as marked within the code of routine\002,\002 DLAM"
965             "C2,\002,/\002 otherwise supply EMIN explicitly.\002,/)";
966
967     /* System generated locals */
968     integer i__1;
969     doublereal d__1, d__2, d__3, d__4, d__5;
970
971     /* Local variables */
972     logical ieee;
973     doublereal half;
974     logical lrnd;
975     static doublereal leps;
976     doublereal zero, a, b, c__;
977     integer i__;
978     static integer lbeta;
979     doublereal rbase;
980     static integer lemin, lemax;
981     integer gnmin;
982     doublereal small;
983     integer gpmin;
984     doublereal third;
985     static doublereal lrmin, lrmax;
986     doublereal sixth;
987     extern /* Subroutine */ int dlamc1_(integer *, integer *, logical *, 
988             logical *);
989     extern doublereal dlamc3_(doublereal *, doublereal *);
990     logical lieee1;
991     extern /* Subroutine */ int dlamc4_(integer *, doublereal *, integer *), 
992             dlamc5_(integer *, integer *, integer *, logical *, integer *, 
993             doublereal *);
994     static integer lt;
995     integer ngnmin, ngpmin;
996     doublereal one, two;
997
998     /* Fortran I/O blocks */
999     static cilist io___58 = { 0, 6, 0, fmt_9999, 0 };
1000
1001
1002
1003 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
1004 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1005 /*     November 2010 */
1006
1007 /* ===================================================================== */
1008
1009
1010     if (first) {
1011         zero = 0.;
1012         one = 1.;
1013         two = 2.;
1014
1015 /*        LBETA, LT, LRND, LEPS, LEMIN and LRMIN  are the local values of */
1016 /*        BETA, T, RND, EPS, EMIN and RMIN. */
1017
1018 /*        Throughout this routine  we use the function  DLAMC3  to ensure */
1019 /*        that relevant values are stored  and not held in registers,  or */
1020 /*        are not affected by optimizers. */
1021
1022 /*        DLAMC1 returns the parameters  LBETA, LT, LRND and LIEEE1. */
1023
1024         dlamc1_(&lbeta, &lt, &lrnd, &lieee1);
1025
1026 /*        Start to find EPS. */
1027
1028         b = (doublereal) lbeta;
1029         i__1 = -lt;
1030         a = pow_di(&b, &i__1);
1031         leps = a;
1032
1033 /*        Try some tricks to see whether or not this is the correct  EPS. */
1034
1035         b = two / 3;
1036         half = one / 2;
1037         d__1 = -half;
1038         sixth = dlamc3_(&b, &d__1);
1039         third = dlamc3_(&sixth, &sixth);
1040         d__1 = -half;
1041         b = dlamc3_(&third, &d__1);
1042         b = dlamc3_(&b, &sixth);
1043         b = abs(b);
1044         if (b < leps) {
1045             b = leps;
1046         }
1047
1048         leps = 1.;
1049
1050 /* +       WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP */
1051 L10:
1052         if (leps > b && b > zero) {
1053             leps = b;
1054             d__1 = half * leps;
1055 /* Computing 5th power */
1056             d__3 = two, d__4 = d__3, d__3 *= d__3;
1057 /* Computing 2nd power */
1058             d__5 = leps;
1059             d__2 = d__4 * (d__3 * d__3) * (d__5 * d__5);
1060             c__ = dlamc3_(&d__1, &d__2);
1061             d__1 = -c__;
1062             c__ = dlamc3_(&half, &d__1);
1063             b = dlamc3_(&half, &c__);
1064             d__1 = -b;
1065             c__ = dlamc3_(&half, &d__1);
1066             b = dlamc3_(&half, &c__);
1067             goto L10;
1068         }
1069 /* +       END WHILE */
1070
1071         if (a < leps) {
1072             leps = a;
1073         }
1074
1075 /*        Computation of EPS complete. */
1076
1077 /*        Now find  EMIN.  Let A = + or - 1, and + or - (1 + BASE**(-3)). */
1078 /*        Keep dividing  A by BETA until (gradual) underflow occurs. This */
1079 /*        is detected when we cannot recover the previous A. */
1080
1081         rbase = one / lbeta;
1082         small = one;
1083         for (i__ = 1; i__ <= 3; ++i__) {
1084             d__1 = small * rbase;
1085             small = dlamc3_(&d__1, &zero);
1086 /* L20: */
1087         }
1088         a = dlamc3_(&one, &small);
1089         dlamc4_(&ngpmin, &one, &lbeta);
1090         d__1 = -one;
1091         dlamc4_(&ngnmin, &d__1, &lbeta);
1092         dlamc4_(&gpmin, &a, &lbeta);
1093         d__1 = -a;
1094         dlamc4_(&gnmin, &d__1, &lbeta);
1095         ieee = FALSE_;
1096
1097         if (ngpmin == ngnmin && gpmin == gnmin) {
1098             if (ngpmin == gpmin) {
1099                 lemin = ngpmin;
1100 /*            ( Non twos-complement machines, no gradual underflow; */
1101 /*              e.g.,  VAX ) */
1102             } else if (gpmin - ngpmin == 3) {
1103                 lemin = ngpmin - 1 + lt;
1104                 ieee = TRUE_;
1105 /*            ( Non twos-complement machines, with gradual underflow; */
1106 /*              e.g., IEEE standard followers ) */
1107             } else {
1108                 lemin = f2cmin(ngpmin,gpmin);
1109 /*            ( A guess; no known machine ) */
1110                 iwarn = TRUE_;
1111             }
1112
1113         } else if (ngpmin == gpmin && ngnmin == gnmin) {
1114             if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1) {
1115                 lemin = f2cmax(ngpmin,ngnmin);
1116 /*            ( Twos-complement machines, no gradual underflow; */
1117 /*              e.g., CYBER 205 ) */
1118             } else {
1119                 lemin = f2cmin(ngpmin,ngnmin);
1120 /*            ( A guess; no known machine ) */
1121                 iwarn = TRUE_;
1122             }
1123
1124         } else if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1 && gpmin == gnmin)
1125                  {
1126             if (gpmin - f2cmin(ngpmin,ngnmin) == 3) {
1127                 lemin = f2cmax(ngpmin,ngnmin) - 1 + lt;
1128 /*            ( Twos-complement machines with gradual underflow; */
1129 /*              no known machine ) */
1130             } else {
1131                 lemin = f2cmin(ngpmin,ngnmin);
1132 /*            ( A guess; no known machine ) */
1133                 iwarn = TRUE_;
1134             }
1135
1136         } else {
1137 /* Computing MIN */
1138             i__1 = f2cmin(ngpmin,ngnmin), i__1 = f2cmin(i__1,gpmin);
1139             lemin = f2cmin(i__1,gnmin);
1140 /*         ( A guess; no known machine ) */
1141             iwarn = TRUE_;
1142         }
1143         first = FALSE_;
1144 /* ** */
1145 /* Comment out this if block if EMIN is ok */
1146         /*
1147         if (iwarn) {
1148             first = TRUE_;
1149             s_wsfe(&io___58);
1150             do_fio(&c__1, (char *)&lemin, (ftnlen)sizeof(integer));
1151             e_wsfe();
1152         }
1153         */
1154 /* ** */
1155
1156 /*        Assume IEEE arithmetic if we found denormalised  numbers above, */
1157 /*        or if arithmetic seems to round in the  IEEE style,  determined */
1158 /*        in routine DLAMC1. A true IEEE machine should have both  things */
1159 /*        true; however, faulty machines may have one or the other. */
1160
1161         ieee = ieee || lieee1;
1162
1163 /*        Compute  RMIN by successive division by  BETA. We could compute */
1164 /*        RMIN as BASE**( EMIN - 1 ),  but some machines underflow during */
1165 /*        this computation. */
1166
1167         lrmin = 1.;
1168         i__1 = 1 - lemin;
1169         for (i__ = 1; i__ <= i__1; ++i__) {
1170             d__1 = lrmin * rbase;
1171             lrmin = dlamc3_(&d__1, &zero);
1172 /* L30: */
1173         }
1174
1175 /*        Finally, call DLAMC5 to compute EMAX and RMAX. */
1176
1177         dlamc5_(&lbeta, &lt, &lemin, &ieee, &lemax, &lrmax);
1178     }
1179
1180     *beta = lbeta;
1181     *t = lt;
1182     *rnd = lrnd;
1183     *eps = leps;
1184     *emin = lemin;
1185     *rmin = lrmin;
1186     *emax = lemax;
1187     *rmax = lrmax;
1188
1189     return 0;
1190
1191
1192 /*     End of DLAMC2 */
1193
1194 } /* dlamc2_ */
1195
1196
1197 /* *********************************************************************** */
1198
1199 /* > \brief \b DLAMC3 */
1200 /* > \details */
1201 /* > \b Purpose: */
1202 /* > \verbatim */
1203 /* > DLAMC3  is intended to force  A  and  B  to be stored prior to doing */
1204 /* > the addition of  A  and  B ,  for use in situations where optimizers */
1205 /* > might hold one of these in a register. */
1206 /* > \endverbatim */
1207 /* > */
1208 /* > \param[in] A */
1209 /* > */
1210 /* > \param[in] B */
1211 /* > \verbatim */
1212 /* >          The values A and B. */
1213 /* > \endverbatim */
1214 doublereal dlamc3_(doublereal *a, doublereal *b)
1215 {
1216     /* System generated locals */
1217     doublereal ret_val;
1218
1219
1220 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
1221 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1222 /*     November 2010 */
1223
1224 /* ===================================================================== */
1225
1226
1227     ret_val = *a + *b;
1228
1229     return ret_val;
1230
1231 /*     End of DLAMC3 */
1232
1233 } /* dlamc3_ */
1234
1235
1236 /* *********************************************************************** */
1237
1238 /* > \brief \b DLAMC4 */
1239 /* > \details */
1240 /* > \b Purpose: */
1241 /* > \verbatim */
1242 /* > DLAMC4 is a service routine for DLAMC2. */
1243 /* > \endverbatim */
1244 /* > */
1245 /* > \param[out] EMIN */
1246 /* > \verbatim */
1247 /* >          The minimum exponent before (gradual) underflow, computed by */
1248 /* >          setting A = START and dividing by BASE until the previous A */
1249 /* >          can not be recovered. */
1250 /* > \endverbatim */
1251 /* > */
1252 /* > \param[in] START */
1253 /* > \verbatim */
1254 /* >          The starting point for determining EMIN. */
1255 /* > \endverbatim */
1256 /* > */
1257 /* > \param[in] BASE */
1258 /* > \verbatim */
1259 /* >          The base of the machine. */
1260 /* > \endverbatim */
1261 /* > */
1262 /* Subroutine */ int dlamc4_(integer *emin, doublereal *start, integer *base)
1263 {
1264     /* System generated locals */
1265     integer i__1;
1266     doublereal d__1;
1267
1268     /* Local variables */
1269     doublereal zero, a;
1270     integer i__;
1271     doublereal rbase, b1, b2, c1, c2, d1, d2;
1272     extern doublereal dlamc3_(doublereal *, doublereal *);
1273     doublereal one;
1274
1275
1276 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
1277 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1278 /*     November 2010 */
1279
1280 /* ===================================================================== */
1281
1282
1283     a = *start;
1284     one = 1.;
1285     rbase = one / *base;
1286     zero = 0.;
1287     *emin = 1;
1288     d__1 = a * rbase;
1289     b1 = dlamc3_(&d__1, &zero);
1290     c1 = a;
1291     c2 = a;
1292     d1 = a;
1293     d2 = a;
1294 /* +    WHILE( ( C1.EQ.A ).AND.( C2.EQ.A ).AND. */
1295 /*    $       ( D1.EQ.A ).AND.( D2.EQ.A )      )LOOP */
1296 L10:
1297     if (c1 == a && c2 == a && d1 == a && d2 == a) {
1298         --(*emin);
1299         a = b1;
1300         d__1 = a / *base;
1301         b1 = dlamc3_(&d__1, &zero);
1302         d__1 = b1 * *base;
1303         c1 = dlamc3_(&d__1, &zero);
1304         d1 = zero;
1305         i__1 = *base;
1306         for (i__ = 1; i__ <= i__1; ++i__) {
1307             d1 += b1;
1308 /* L20: */
1309         }
1310         d__1 = a * rbase;
1311         b2 = dlamc3_(&d__1, &zero);
1312         d__1 = b2 / rbase;
1313         c2 = dlamc3_(&d__1, &zero);
1314         d2 = zero;
1315         i__1 = *base;
1316         for (i__ = 1; i__ <= i__1; ++i__) {
1317             d2 += b2;
1318 /* L30: */
1319         }
1320         goto L10;
1321     }
1322 /* +    END WHILE */
1323
1324     return 0;
1325
1326 /*     End of DLAMC4 */
1327
1328 } /* dlamc4_ */
1329
1330
1331 /* *********************************************************************** */
1332
1333 /* > \brief \b DLAMC5 */
1334 /* > \details */
1335 /* > \b Purpose: */
1336 /* > \verbatim */
1337 /* > DLAMC5 attempts to compute RMAX, the largest machine floating-point */
1338 /* > number, without overflow.  It assumes that EMAX + abs(EMIN) sum */
1339 /* > approximately to a power of 2.  It will fail on machines where this */
1340 /* > assumption does not hold, for example, the Cyber 205 (EMIN = -28625, */
1341 /* > EMAX = 28718).  It will also fail if the value supplied for EMIN is */
1342 /* > too large (i.e. too close to zero), probably with overflow. */
1343 /* > \endverbatim */
1344 /* > */
1345 /* > \param[in] BETA */
1346 /* > \verbatim */
1347 /* >          The base of floating-point arithmetic. */
1348 /* > \endverbatim */
1349 /* > */
1350 /* > \param[in] P */
1351 /* > \verbatim */
1352 /* >          The number of base BETA digits in the mantissa of a */
1353 /* >          floating-point value. */
1354 /* > \endverbatim */
1355 /* > */
1356 /* > \param[in] EMIN */
1357 /* > \verbatim */
1358 /* >          The minimum exponent before (gradual) underflow. */
1359 /* > \endverbatim */
1360 /* > */
1361 /* > \param[in] IEEE */
1362 /* > \verbatim */
1363 /* >          A logical flag specifying whether or not the arithmetic */
1364 /* >          system is thought to comply with the IEEE standard. */
1365 /* > \endverbatim */
1366 /* > */
1367 /* > \param[out] EMAX */
1368 /* > \verbatim */
1369 /* >          The largest exponent before overflow */
1370 /* > \endverbatim */
1371 /* > */
1372 /* > \param[out] RMAX */
1373 /* > \verbatim */
1374 /* >          The largest machine floating-point number. */
1375 /* > \endverbatim */
1376 /* > */
1377 /* Subroutine */ int dlamc5_(integer *beta, integer *p, integer *emin, 
1378         logical *ieee, integer *emax, doublereal *rmax)
1379 {
1380     /* System generated locals */
1381     integer i__1;
1382     doublereal d__1;
1383
1384     /* Local variables */
1385     integer lexp;
1386     doublereal oldy;
1387     integer uexp, i__;
1388     doublereal y, z__;
1389     integer nbits;
1390     extern doublereal dlamc3_(doublereal *, doublereal *);
1391     doublereal recbas;
1392     integer exbits, expsum, try__;
1393
1394
1395 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
1396 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1397 /*     November 2010 */
1398
1399 /* ===================================================================== */
1400
1401
1402 /*     First compute LEXP and UEXP, two powers of 2 that bound */
1403 /*     abs(EMIN). We then assume that EMAX + abs(EMIN) will sum */
1404 /*     approximately to the bound that is closest to abs(EMIN). */
1405 /*     (EMAX is the exponent of the required number RMAX). */
1406
1407     lexp = 1;
1408     exbits = 1;
1409 L10:
1410     try__ = lexp << 1;
1411     if (try__ <= -(*emin)) {
1412         lexp = try__;
1413         ++exbits;
1414         goto L10;
1415     }
1416     if (lexp == -(*emin)) {
1417         uexp = lexp;
1418     } else {
1419         uexp = try__;
1420         ++exbits;
1421     }
1422
1423 /*     Now -LEXP is less than or equal to EMIN, and -UEXP is greater */
1424 /*     than or equal to EMIN. EXBITS is the number of bits needed to */
1425 /*     store the exponent. */
1426
1427     if (uexp + *emin > -lexp - *emin) {
1428         expsum = lexp << 1;
1429     } else {
1430         expsum = uexp << 1;
1431     }
1432
1433 /*     EXPSUM is the exponent range, approximately equal to */
1434 /*     EMAX - EMIN + 1 . */
1435
1436     *emax = expsum + *emin - 1;
1437     nbits = exbits + 1 + *p;
1438
1439 /*     NBITS is the total number of bits needed to store a */
1440 /*     floating-point number. */
1441
1442     if (nbits % 2 == 1 && *beta == 2) {
1443
1444 /*        Either there are an odd number of bits used to store a */
1445 /*        floating-point number, which is unlikely, or some bits are */
1446 /*        not used in the representation of numbers, which is possible, */
1447 /*        (e.g. Cray machines) or the mantissa has an implicit bit, */
1448 /*        (e.g. IEEE machines, Dec Vax machines), which is perhaps the */
1449 /*        most likely. We have to assume the last alternative. */
1450 /*        If this is true, then we need to reduce EMAX by one because */
1451 /*        there must be some way of representing zero in an implicit-bit */
1452 /*        system. On machines like Cray, we are reducing EMAX by one */
1453 /*        unnecessarily. */
1454
1455         --(*emax);
1456     }
1457
1458     if (*ieee) {
1459
1460 /*        Assume we are on an IEEE machine which reserves one exponent */
1461 /*        for infinity and NaN. */
1462
1463         --(*emax);
1464     }
1465
1466 /*     Now create RMAX, the largest machine number, which should */
1467 /*     be equal to (1.0 - BETA**(-P)) * BETA**EMAX . */
1468
1469 /*     First compute 1.0 - BETA**(-P), being careful that the */
1470 /*     result is less than 1.0 . */
1471
1472     recbas = 1. / *beta;
1473     z__ = *beta - 1.;
1474     y = 0.;
1475     i__1 = *p;
1476     for (i__ = 1; i__ <= i__1; ++i__) {
1477         z__ *= recbas;
1478         if (y < 1.) {
1479             oldy = y;
1480         }
1481         y = dlamc3_(&y, &z__);
1482 /* L20: */
1483     }
1484     if (y >= 1.) {
1485         y = oldy;
1486     }
1487
1488 /*     Now multiply by BETA**EMAX to get RMAX. */
1489
1490     i__1 = *emax;
1491     for (i__ = 1; i__ <= i__1; ++i__) {
1492         d__1 = y * *beta;
1493         y = dlamc3_(&d__1, &c_b32);
1494 /* L30: */
1495     }
1496
1497     *rmax = y;
1498     return 0;
1499
1500 /*     End of DLAMC5 */
1501
1502 } /* dlamc5_ */
1503