C_LAPACK: Fixes to make it compile with MSVC (#3605)
[platform/upstream/openblas.git] / lapack-netlib / INSTALL / slamch.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 real c_b32 = 0.f;
517
518 /* > \brief \b SLAMCHF77 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 /*      REAL FUNCTION SLAMCH( CMACH ) */
529
530 /*      CHARACTER          CMACH */
531
532
533 /* > \par Purpose: */
534 /*  ============= */
535 /* > */
536 /* > \verbatim */
537 /* > */
538 /* > SLAMCH determines single precision machine parameters. */
539 /* > \endverbatim */
540
541 /*  Arguments: */
542 /*  ========== */
543
544 /* > \param[in] CMACH */
545 /* > \verbatim */
546 /* >          Specifies the value to be returned by SLAMCH: */
547 /* >          = 'E' or 'e',   SLAMCH := eps */
548 /* >          = 'S' or 's ,   SLAMCH := sfmin */
549 /* >          = 'B' or 'b',   SLAMCH := base */
550 /* >          = 'P' or 'p',   SLAMCH := eps*base */
551 /* >          = 'N' or 'n',   SLAMCH := t */
552 /* >          = 'R' or 'r',   SLAMCH := rnd */
553 /* >          = 'M' or 'm',   SLAMCH := emin */
554 /* >          = 'U' or 'u',   SLAMCH := rmin */
555 /* >          = 'L' or 'l',   SLAMCH := emax */
556 /* >          = 'O' or 'o',   SLAMCH := 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 real slamch_(char *cmach)
584 {
585     /* Initialized data */
586
587     static logical first = TRUE_;
588
589     /* System generated locals */
590     integer i__1;
591     real ret_val;
592
593     /* Local variables */
594     static real base;
595     integer beta;
596     static real emin, prec, emax;
597     integer imin, imax;
598     logical lrnd;
599     static real rmin, rmax, t;
600     real rmach;
601     extern logical lsame_(char *, char *);
602     real small;
603     static real sfmin;
604     extern /* Subroutine */ int slamc2_(integer *, integer *, logical *, real 
605             *, integer *, real *, integer *, real *);
606     integer it;
607     static real 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         slamc2_(&beta, &it, &lrnd, &eps, &imin, &rmin, &imax, &rmax);
618         base = (real) beta;
619         t = (real) it;
620         if (lrnd) {
621             rnd = 1.f;
622             i__1 = 1 - it;
623             eps = pow_ri(&base, &i__1) / 2;
624         } else {
625             rnd = 0.f;
626             i__1 = 1 - it;
627             eps = pow_ri(&base, &i__1);
628         }
629         prec = eps * base;
630         emin = (real) imin;
631         emax = (real) imax;
632         sfmin = rmin;
633         small = 1.f / 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.f);
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 SLAMCH */
670
671 } /* slamch_ */
672
673
674 /* *********************************************************************** */
675
676 /* > \brief \b SLAMC1 */
677 /* > \details */
678 /* > \b Purpose: */
679 /* > \verbatim */
680 /* > SLAMC1 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 slamc1_(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     real r__1, r__2;
735
736     /* Local variables */
737     static logical lrnd;
738     real a, b, c__, f;
739     static integer lbeta;
740     real savec;
741     static logical lieee1;
742     real t1, t2;
743     extern real slamc3_(real *, real *);
744     static integer lt;
745     real 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.f;
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  SLAMC3  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.f;
771         c__ = 1.f;
772
773 /* +       WHILE( C.EQ.ONE )LOOP */
774 L10:
775         if (c__ == one) {
776             a *= 2;
777             c__ = slamc3_(&a, &one);
778             r__1 = -a;
779             c__ = slamc3_(&c__, &r__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.f;
790         c__ = slamc3_(&a, &b);
791
792 /* +       WHILE( C.EQ.A )LOOP */
793 L20:
794         if (c__ == a) {
795             b *= 2;
796             c__ = slamc3_(&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         r__1 = -a;
809         c__ = slamc3_(&c__, &r__1);
810         lbeta = 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 = (real) lbeta;
816         r__1 = b / 2;
817         r__2 = -b / 100;
818         f = slamc3_(&r__1, &r__2);
819         c__ = slamc3_(&f, &a);
820         if (c__ == a) {
821             lrnd = TRUE_;
822         } else {
823             lrnd = FALSE_;
824         }
825         r__1 = b / 2;
826         r__2 = b / 100;
827         f = slamc3_(&r__1, &r__2);
828         c__ = slamc3_(&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         r__1 = b / 2;
840         t1 = slamc3_(&r__1, &a);
841         r__1 = b / 2;
842         t2 = slamc3_(&r__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.f;
854         c__ = 1.f;
855
856 /* +       WHILE( C.EQ.ONE )LOOP */
857 L30:
858         if (c__ == one) {
859             ++lt;
860             a *= lbeta;
861             c__ = slamc3_(&a, &one);
862             r__1 = -a;
863             c__ = slamc3_(&c__, &r__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 SLAMC1 */
878
879 } /* slamc1_ */
880
881
882 /* *********************************************************************** */
883
884 /* > \brief \b SLAMC2 */
885 /* > \details */
886 /* > \b Purpose: */
887 /* > \verbatim */
888 /* > SLAMC2 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 slamc2_(integer *beta, integer *t, logical *rnd, real *
952         eps, integer *emin, real *rmin, integer *emax, real *rmax)
953 {
954     /* Initialized data */
955
956     static logical first = TRUE_;
957     static logical iwarn = FALSE_;
958
959     /* Format strings */
960     static char fmt_9999[] = "(//\002 WARNING. The value EMIN may be incorre"
961             "ct:-\002,\002  EMIN = \002,i8,/\002 If, after inspection, the va"
962             "lue EMIN looks\002,\002 acceptable please comment out \002,/\002"
963             " the IF block as marked within the code of routine\002,\002 SLAM"
964             "C2,\002,/\002 otherwise supply EMIN explicitly.\002,/)";
965
966     /* System generated locals */
967     integer i__1;
968     real r__1, r__2, r__3, r__4, r__5;
969
970     /* Local variables */
971     logical ieee;
972     real half;
973     logical lrnd;
974     static real leps;
975     real zero, a, b, c__;
976     integer i__;
977     static integer lbeta;
978     real rbase;
979     static integer lemin, lemax;
980     integer gnmin;
981     real small;
982     integer gpmin;
983     real third;
984     static real lrmin, lrmax;
985     real sixth;
986     logical lieee1;
987     extern /* Subroutine */ int slamc1_(integer *, integer *, logical *, 
988             logical *);
989     extern real slamc3_(real *, real *);
990     extern /* Subroutine */ int slamc4_(integer *, real *, integer *), 
991             slamc5_(integer *, integer *, integer *, logical *, integer *, 
992             real *);
993     static integer lt;
994     integer ngnmin, ngpmin;
995     real one, two;
996
997     /* Fortran I/O blocks */
998     static cilist io___58 = { 0, 6, 0, fmt_9999, 0 };
999
1000
1001
1002 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
1003 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1004 /*     November 2010 */
1005
1006 /* ===================================================================== */
1007
1008
1009     if (first) {
1010         zero = 0.f;
1011         one = 1.f;
1012         two = 2.f;
1013
1014 /*        LBETA, LT, LRND, LEPS, LEMIN and LRMIN  are the local values of */
1015 /*        BETA, T, RND, EPS, EMIN and RMIN. */
1016
1017 /*        Throughout this routine  we use the function  SLAMC3  to ensure */
1018 /*        that relevant values are stored  and not held in registers,  or */
1019 /*        are not affected by optimizers. */
1020
1021 /*        SLAMC1 returns the parameters  LBETA, LT, LRND and LIEEE1. */
1022
1023         slamc1_(&lbeta, &lt, &lrnd, &lieee1);
1024
1025 /*        Start to find EPS. */
1026
1027         b = (real) lbeta;
1028         i__1 = -lt;
1029         a = pow_ri(&b, &i__1);
1030         leps = a;
1031
1032 /*        Try some tricks to see whether or not this is the correct  EPS. */
1033
1034         b = two / 3;
1035         half = one / 2;
1036         r__1 = -half;
1037         sixth = slamc3_(&b, &r__1);
1038         third = slamc3_(&sixth, &sixth);
1039         r__1 = -half;
1040         b = slamc3_(&third, &r__1);
1041         b = slamc3_(&b, &sixth);
1042         b = abs(b);
1043         if (b < leps) {
1044             b = leps;
1045         }
1046
1047         leps = 1.f;
1048
1049 /* +       WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP */
1050 L10:
1051         if (leps > b && b > zero) {
1052             leps = b;
1053             r__1 = half * leps;
1054 /* Computing 5th power */
1055             r__3 = two, r__4 = r__3, r__3 *= r__3;
1056 /* Computing 2nd power */
1057             r__5 = leps;
1058             r__2 = r__4 * (r__3 * r__3) * (r__5 * r__5);
1059             c__ = slamc3_(&r__1, &r__2);
1060             r__1 = -c__;
1061             c__ = slamc3_(&half, &r__1);
1062             b = slamc3_(&half, &c__);
1063             r__1 = -b;
1064             c__ = slamc3_(&half, &r__1);
1065             b = slamc3_(&half, &c__);
1066             goto L10;
1067         }
1068 /* +       END WHILE */
1069
1070         if (a < leps) {
1071             leps = a;
1072         }
1073
1074 /*        Computation of EPS complete. */
1075
1076 /*        Now find  EMIN.  Let A = + or - 1, and + or - (1 + BASE**(-3)). */
1077 /*        Keep dividing  A by BETA until (gradual) underflow occurs. This */
1078 /*        is detected when we cannot recover the previous A. */
1079
1080         rbase = one / lbeta;
1081         small = one;
1082         for (i__ = 1; i__ <= 3; ++i__) {
1083             r__1 = small * rbase;
1084             small = slamc3_(&r__1, &zero);
1085 /* L20: */
1086         }
1087         a = slamc3_(&one, &small);
1088         slamc4_(&ngpmin, &one, &lbeta);
1089         r__1 = -one;
1090         slamc4_(&ngnmin, &r__1, &lbeta);
1091         slamc4_(&gpmin, &a, &lbeta);
1092         r__1 = -a;
1093         slamc4_(&gnmin, &r__1, &lbeta);
1094         ieee = FALSE_;
1095
1096         if (ngpmin == ngnmin && gpmin == gnmin) {
1097             if (ngpmin == gpmin) {
1098                 lemin = ngpmin;
1099 /*            ( Non twos-complement machines, no gradual underflow; */
1100 /*              e.g.,  VAX ) */
1101             } else if (gpmin - ngpmin == 3) {
1102                 lemin = ngpmin - 1 + lt;
1103                 ieee = TRUE_;
1104 /*            ( Non twos-complement machines, with gradual underflow; */
1105 /*              e.g., IEEE standard followers ) */
1106             } else {
1107                 lemin = f2cmin(ngpmin,gpmin);
1108 /*            ( A guess; no known machine ) */
1109                 iwarn = TRUE_;
1110             }
1111
1112         } else if (ngpmin == gpmin && ngnmin == gnmin) {
1113             if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1) {
1114                 lemin = f2cmax(ngpmin,ngnmin);
1115 /*            ( Twos-complement machines, no gradual underflow; */
1116 /*              e.g., CYBER 205 ) */
1117             } else {
1118                 lemin = f2cmin(ngpmin,ngnmin);
1119 /*            ( A guess; no known machine ) */
1120                 iwarn = TRUE_;
1121             }
1122
1123         } else if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1 && gpmin == gnmin)
1124                  {
1125             if (gpmin - f2cmin(ngpmin,ngnmin) == 3) {
1126                 lemin = f2cmax(ngpmin,ngnmin) - 1 + lt;
1127 /*            ( Twos-complement machines with gradual underflow; */
1128 /*              no known machine ) */
1129             } else {
1130                 lemin = f2cmin(ngpmin,ngnmin);
1131 /*            ( A guess; no known machine ) */
1132                 iwarn = TRUE_;
1133             }
1134
1135         } else {
1136 /* Computing MIN */
1137             i__1 = f2cmin(ngpmin,ngnmin), i__1 = f2cmin(i__1,gpmin);
1138             lemin = f2cmin(i__1,gnmin);
1139 /*         ( A guess; no known machine ) */
1140             iwarn = TRUE_;
1141         }
1142         first = FALSE_;
1143 /* ** */
1144 /* Comment out this if block if EMIN is ok */
1145 /*
1146   if (iwarn) {
1147             first = TRUE_;
1148             s_wsfe(&io___58);
1149             do_fio(&c__1, (char *)&lemin, (ftnlen)sizeof(integer));
1150             e_wsfe();
1151         }
1152 */
1153 /* ** */
1154
1155 /*        Assume IEEE arithmetic if we found denormalised  numbers above, */
1156 /*        or if arithmetic seems to round in the  IEEE style,  determined */
1157 /*        in routine SLAMC1. A true IEEE machine should have both  things */
1158 /*        true; however, faulty machines may have one or the other. */
1159
1160         ieee = ieee || lieee1;
1161
1162 /*        Compute  RMIN by successive division by  BETA. We could compute */
1163 /*        RMIN as BASE**( EMIN - 1 ),  but some machines underflow during */
1164 /*        this computation. */
1165
1166         lrmin = 1.f;
1167         i__1 = 1 - lemin;
1168         for (i__ = 1; i__ <= i__1; ++i__) {
1169             r__1 = lrmin * rbase;
1170             lrmin = slamc3_(&r__1, &zero);
1171 /* L30: */
1172         }
1173
1174 /*        Finally, call SLAMC5 to compute EMAX and RMAX. */
1175
1176         slamc5_(&lbeta, &lt, &lemin, &ieee, &lemax, &lrmax);
1177     }
1178
1179     *beta = lbeta;
1180     *t = lt;
1181     *rnd = lrnd;
1182     *eps = leps;
1183     *emin = lemin;
1184     *rmin = lrmin;
1185     *emax = lemax;
1186     *rmax = lrmax;
1187
1188     return 0;
1189
1190
1191 /*     End of SLAMC2 */
1192
1193 } /* slamc2_ */
1194
1195
1196 /* *********************************************************************** */
1197
1198 /* > \brief \b SLAMC3 */
1199 /* > \details */
1200 /* > \b Purpose: */
1201 /* > \verbatim */
1202 /* > SLAMC3  is intended to force  A  and  B  to be stored prior to doing */
1203 /* > the addition of  A  and  B ,  for use in situations where optimizers */
1204 /* > might hold one of these in a register. */
1205 /* > \endverbatim */
1206 /* > */
1207 /* > \param[in] A */
1208 /* > */
1209 /* > \param[in] B */
1210 /* > \verbatim */
1211 /* >          The values A and B. */
1212 /* > \endverbatim */
1213 real slamc3_(real *a, real *b)
1214 {
1215     /* System generated locals */
1216     real ret_val;
1217
1218
1219 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
1220 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1221 /*     November 2010 */
1222
1223 /* ===================================================================== */
1224
1225
1226     ret_val = *a + *b;
1227
1228     return ret_val;
1229
1230 /*     End of SLAMC3 */
1231
1232 } /* slamc3_ */
1233
1234
1235 /* *********************************************************************** */
1236
1237 /* > \brief \b SLAMC4 */
1238 /* > \details */
1239 /* > \b Purpose: */
1240 /* > \verbatim */
1241 /* > SLAMC4 is a service routine for SLAMC2. */
1242 /* > \endverbatim */
1243 /* > */
1244 /* > \param[out] EMIN */
1245 /* > \verbatim */
1246 /* >          The minimum exponent before (gradual) underflow, computed by */
1247 /* >          setting A = START and dividing by BASE until the previous A */
1248 /* >          can not be recovered. */
1249 /* > \endverbatim */
1250 /* > */
1251 /* > \param[in] START */
1252 /* > \verbatim */
1253 /* >          The starting point for determining EMIN. */
1254 /* > \endverbatim */
1255 /* > */
1256 /* > \param[in] BASE */
1257 /* > \verbatim */
1258 /* >          The base of the machine. */
1259 /* > \endverbatim */
1260 /* > */
1261 /* Subroutine */ int slamc4_(integer *emin, real *start, integer *base)
1262 {
1263     /* System generated locals */
1264     integer i__1;
1265     real r__1;
1266
1267     /* Local variables */
1268     real zero, a;
1269     integer i__;
1270     real rbase, b1, b2, c1, c2, d1, d2;
1271     extern real slamc3_(real *, real *);
1272     real one;
1273
1274
1275 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
1276 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1277 /*     November 2010 */
1278
1279 /* ===================================================================== */
1280
1281
1282     a = *start;
1283     one = 1.f;
1284     rbase = one / *base;
1285     zero = 0.f;
1286     *emin = 1;
1287     r__1 = a * rbase;
1288     b1 = slamc3_(&r__1, &zero);
1289     c1 = a;
1290     c2 = a;
1291     d1 = a;
1292     d2 = a;
1293 /* +    WHILE( ( C1.EQ.A ).AND.( C2.EQ.A ).AND. */
1294 /*    $       ( D1.EQ.A ).AND.( D2.EQ.A )      )LOOP */
1295 L10:
1296     if (c1 == a && c2 == a && d1 == a && d2 == a) {
1297         --(*emin);
1298         a = b1;
1299         r__1 = a / *base;
1300         b1 = slamc3_(&r__1, &zero);
1301         r__1 = b1 * *base;
1302         c1 = slamc3_(&r__1, &zero);
1303         d1 = zero;
1304         i__1 = *base;
1305         for (i__ = 1; i__ <= i__1; ++i__) {
1306             d1 += b1;
1307 /* L20: */
1308         }
1309         r__1 = a * rbase;
1310         b2 = slamc3_(&r__1, &zero);
1311         r__1 = b2 / rbase;
1312         c2 = slamc3_(&r__1, &zero);
1313         d2 = zero;
1314         i__1 = *base;
1315         for (i__ = 1; i__ <= i__1; ++i__) {
1316             d2 += b2;
1317 /* L30: */
1318         }
1319         goto L10;
1320     }
1321 /* +    END WHILE */
1322
1323     return 0;
1324
1325 /*     End of SLAMC4 */
1326
1327 } /* slamc4_ */
1328
1329
1330 /* *********************************************************************** */
1331
1332 /* > \brief \b SLAMC5 */
1333 /* > \details */
1334 /* > \b Purpose: */
1335 /* > \verbatim */
1336 /* > SLAMC5 attempts to compute RMAX, the largest machine floating-point */
1337 /* > number, without overflow.  It assumes that EMAX + abs(EMIN) sum */
1338 /* > approximately to a power of 2.  It will fail on machines where this */
1339 /* > assumption does not hold, for example, the Cyber 205 (EMIN = -28625, */
1340 /* > EMAX = 28718).  It will also fail if the value supplied for EMIN is */
1341 /* > too large (i.e. too close to zero), probably with overflow. */
1342 /* > \endverbatim */
1343 /* > */
1344 /* > \param[in] BETA */
1345 /* > \verbatim */
1346 /* >          The base of floating-point arithmetic. */
1347 /* > \endverbatim */
1348 /* > */
1349 /* > \param[in] P */
1350 /* > \verbatim */
1351 /* >          The number of base BETA digits in the mantissa of a */
1352 /* >          floating-point value. */
1353 /* > \endverbatim */
1354 /* > */
1355 /* > \param[in] EMIN */
1356 /* > \verbatim */
1357 /* >          The minimum exponent before (gradual) underflow. */
1358 /* > \endverbatim */
1359 /* > */
1360 /* > \param[in] IEEE */
1361 /* > \verbatim */
1362 /* >          A logical flag specifying whether or not the arithmetic */
1363 /* >          system is thought to comply with the IEEE standard. */
1364 /* > \endverbatim */
1365 /* > */
1366 /* > \param[out] EMAX */
1367 /* > \verbatim */
1368 /* >          The largest exponent before overflow */
1369 /* > \endverbatim */
1370 /* > */
1371 /* > \param[out] RMAX */
1372 /* > \verbatim */
1373 /* >          The largest machine floating-point number. */
1374 /* > \endverbatim */
1375 /* > */
1376 /* Subroutine */ int slamc5_(integer *beta, integer *p, integer *emin, 
1377         logical *ieee, integer *emax, real *rmax)
1378 {
1379     /* System generated locals */
1380     integer i__1;
1381     real r__1;
1382
1383     /* Local variables */
1384     integer lexp;
1385     real oldy;
1386     integer uexp, i__;
1387     real y, z__;
1388     integer nbits;
1389     extern real slamc3_(real *, real *);
1390     real recbas;
1391     integer exbits, expsum, try__;
1392
1393
1394 /*  -- LAPACK auxiliary routine (version 3.7.0) -- */
1395 /*     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
1396 /*     November 2010 */
1397
1398 /* ===================================================================== */
1399
1400
1401 /*     First compute LEXP and UEXP, two powers of 2 that bound */
1402 /*     abs(EMIN). We then assume that EMAX + abs(EMIN) will sum */
1403 /*     approximately to the bound that is closest to abs(EMIN). */
1404 /*     (EMAX is the exponent of the required number RMAX). */
1405
1406     lexp = 1;
1407     exbits = 1;
1408 L10:
1409     try__ = lexp << 1;
1410     if (try__ <= -(*emin)) {
1411         lexp = try__;
1412         ++exbits;
1413         goto L10;
1414     }
1415     if (lexp == -(*emin)) {
1416         uexp = lexp;
1417     } else {
1418         uexp = try__;
1419         ++exbits;
1420     }
1421
1422 /*     Now -LEXP is less than or equal to EMIN, and -UEXP is greater */
1423 /*     than or equal to EMIN. EXBITS is the number of bits needed to */
1424 /*     store the exponent. */
1425
1426     if (uexp + *emin > -lexp - *emin) {
1427         expsum = lexp << 1;
1428     } else {
1429         expsum = uexp << 1;
1430     }
1431
1432 /*     EXPSUM is the exponent range, approximately equal to */
1433 /*     EMAX - EMIN + 1 . */
1434
1435     *emax = expsum + *emin - 1;
1436     nbits = exbits + 1 + *p;
1437
1438 /*     NBITS is the total number of bits needed to store a */
1439 /*     floating-point number. */
1440
1441     if (nbits % 2 == 1 && *beta == 2) {
1442
1443 /*        Either there are an odd number of bits used to store a */
1444 /*        floating-point number, which is unlikely, or some bits are */
1445 /*        not used in the representation of numbers, which is possible, */
1446 /*        (e.g. Cray machines) or the mantissa has an implicit bit, */
1447 /*        (e.g. IEEE machines, Dec Vax machines), which is perhaps the */
1448 /*        most likely. We have to assume the last alternative. */
1449 /*        If this is true, then we need to reduce EMAX by one because */
1450 /*        there must be some way of representing zero in an implicit-bit */
1451 /*        system. On machines like Cray, we are reducing EMAX by one */
1452 /*        unnecessarily. */
1453
1454         --(*emax);
1455     }
1456
1457     if (*ieee) {
1458
1459 /*        Assume we are on an IEEE machine which reserves one exponent */
1460 /*        for infinity and NaN. */
1461
1462         --(*emax);
1463     }
1464
1465 /*     Now create RMAX, the largest machine number, which should */
1466 /*     be equal to (1.0 - BETA**(-P)) * BETA**EMAX . */
1467
1468 /*     First compute 1.0 - BETA**(-P), being careful that the */
1469 /*     result is less than 1.0 . */
1470
1471     recbas = 1.f / *beta;
1472     z__ = *beta - 1.f;
1473     y = 0.f;
1474     i__1 = *p;
1475     for (i__ = 1; i__ <= i__1; ++i__) {
1476         z__ *= recbas;
1477         if (y < 1.f) {
1478             oldy = y;
1479         }
1480         y = slamc3_(&y, &z__);
1481 /* L20: */
1482     }
1483     if (y >= 1.f) {
1484         y = oldy;
1485     }
1486
1487 /*     Now multiply by BETA**EMAX to get RMAX. */
1488
1489     i__1 = *emax;
1490     for (i__ = 1; i__ <= i__1; ++i__) {
1491         r__1 = y * *beta;
1492         y = slamc3_(&r__1, &c_b32);
1493 /* L30: */
1494     }
1495
1496     *rmax = y;
1497     return 0;
1498
1499 /*     End of SLAMC5 */
1500
1501 } /* slamc5_ */
1502