/root/doris/contrib/openblas/lapack-netlib/INSTALL/dlamch.c
Line | Count | Source |
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 | 0 | static inline _Complex float Cf(complex *z) {return z->r + z->i*_Complex_I;} |
49 | 0 | static inline _Complex double Cd(doublecomplex *z) {return z->r + z->i*_Complex_I;} |
50 | 0 | static inline _Complex float * _pCf(complex *z) {return (_Complex float*)z;} |
51 | 0 | 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 | 0 | #define TRUE_ (1) |
61 | 0 | #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 | 0 | #define abs(x) ((x) >= 0 ? (x) : -(x)) |
180 | | #define dabs(x) (fabs(x)) |
181 | 0 | #define f2cmin(a,b) ((a) <= (b) ? (a) : (b)) |
182 | 0 | #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 | 0 | #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 | | #define z_abs(z) (cabs(Cd(z))) |
251 | | #define z_exp(R, Z) {pCd(R) = cexp(Cd(Z));} |
252 | | #define z_sqrt(R, Z) {pCd(R) = csqrt(Cd(Z));} |
253 | | #define myexit_() break; |
254 | | #define mycycle() continue; |
255 | | #define myceiling(w) {ceil(w)} |
256 | | #define myhuge(w) {HUGE_VAL} |
257 | | //#define mymaxloc_(w,s,e,n) {if (sizeof(*(w)) == sizeof(double)) dmaxloc_((w),*(s),*(e),n); else dmaxloc_((w),*(s),*(e),n);} |
258 | | #define mymaxloc(w,s,e,n) {dmaxloc_(w,*(s),*(e),n)} |
259 | | |
260 | | /* procedure parameter types for -A and -C++ */ |
261 | | |
262 | | #define F2C_proc_par_types 1 |
263 | | |
264 | 0 | static double dpow_ui(double x, integer n) { |
265 | 0 | double pow=1.0; unsigned long int u; |
266 | 0 | if(n != 0) { |
267 | 0 | if(n < 0) n = -n, x = 1/x; |
268 | 0 | for(u = n; ; ) { |
269 | 0 | if(u & 01) pow *= x; |
270 | 0 | if(u >>= 1) x *= x; |
271 | 0 | else break; |
272 | 0 | } |
273 | 0 | } |
274 | 0 | return pow; |
275 | 0 | } |
276 | | |
277 | | /* -- translated by f2c (version 20000121). |
278 | | You must link the resulting object file with the libraries: |
279 | | -lf2c -lm (in that order) |
280 | | */ |
281 | | |
282 | | |
283 | | |
284 | | |
285 | | /* Table of constant values */ |
286 | | |
287 | | static integer c__1 = 1; |
288 | | static doublereal c_b32 = 0.; |
289 | | |
290 | | /* > \brief \b DLAMCHF77 deprecated */ |
291 | | |
292 | | /* =========== DOCUMENTATION =========== */ |
293 | | |
294 | | /* Online html documentation available at */ |
295 | | /* http://www.netlib.org/lapack/explore-html/ */ |
296 | | |
297 | | /* Definition: */ |
298 | | /* =========== */ |
299 | | |
300 | | /* DOUBLE PRECISION FUNCTION DLAMCH( CMACH ) */ |
301 | | |
302 | | /* CHARACTER CMACH */ |
303 | | |
304 | | |
305 | | /* > \par Purpose: */ |
306 | | /* ============= */ |
307 | | /* > */ |
308 | | /* > \verbatim */ |
309 | | /* > */ |
310 | | /* > DLAMCHF77 determines double precision machine parameters. */ |
311 | | /* > \endverbatim */ |
312 | | |
313 | | /* Arguments: */ |
314 | | /* ========== */ |
315 | | |
316 | | /* > \param[in] CMACH */ |
317 | | /* > \verbatim */ |
318 | | /* > Specifies the value to be returned by DLAMCH: */ |
319 | | /* > = 'E' or 'e', DLAMCH := eps */ |
320 | | /* > = 'S' or 's , DLAMCH := sfmin */ |
321 | | /* > = 'B' or 'b', DLAMCH := base */ |
322 | | /* > = 'P' or 'p', DLAMCH := eps*base */ |
323 | | /* > = 'N' or 'n', DLAMCH := t */ |
324 | | /* > = 'R' or 'r', DLAMCH := rnd */ |
325 | | /* > = 'M' or 'm', DLAMCH := emin */ |
326 | | /* > = 'U' or 'u', DLAMCH := rmin */ |
327 | | /* > = 'L' or 'l', DLAMCH := emax */ |
328 | | /* > = 'O' or 'o', DLAMCH := rmax */ |
329 | | /* > where */ |
330 | | /* > eps = relative machine precision */ |
331 | | /* > sfmin = safe minimum, such that 1/sfmin does not overflow */ |
332 | | /* > base = base of the machine */ |
333 | | /* > prec = eps*base */ |
334 | | /* > t = number of (base) digits in the mantissa */ |
335 | | /* > rnd = 1.0 when rounding occurs in addition, 0.0 otherwise */ |
336 | | /* > emin = minimum exponent before (gradual) underflow */ |
337 | | /* > rmin = underflow threshold - base**(emin-1) */ |
338 | | /* > emax = largest exponent before overflow */ |
339 | | /* > rmax = overflow threshold - (base**emax)*(1-eps) */ |
340 | | /* > \endverbatim */ |
341 | | |
342 | | /* Authors: */ |
343 | | /* ======== */ |
344 | | |
345 | | /* > \author Univ. of Tennessee */ |
346 | | /* > \author Univ. of California Berkeley */ |
347 | | /* > \author Univ. of Colorado Denver */ |
348 | | /* > \author NAG Ltd. */ |
349 | | |
350 | | /* > \date April 2012 */ |
351 | | |
352 | | /* > \ingroup auxOTHERauxiliary */ |
353 | | |
354 | | /* ===================================================================== */ |
355 | | doublereal dlamch_(char *cmach) |
356 | 0 | { |
357 | | /* Initialized data */ |
358 | |
|
359 | 0 | static logical first = TRUE_; |
360 | | |
361 | | /* System generated locals */ |
362 | 0 | integer i__1; |
363 | 0 | doublereal ret_val; |
364 | | |
365 | | /* Local variables */ |
366 | 0 | static doublereal base; |
367 | 0 | integer beta; |
368 | 0 | static doublereal emin, prec, emax; |
369 | 0 | integer imin, imax; |
370 | 0 | logical lrnd; |
371 | 0 | static doublereal rmin, rmax, t; |
372 | 0 | doublereal rmach; |
373 | 0 | extern logical lsame_(char *, char *); |
374 | 0 | doublereal small; |
375 | 0 | static doublereal sfmin; |
376 | 0 | extern /* Subroutine */ int dlamc2_(integer *, integer *, logical *, |
377 | 0 | doublereal *, integer *, doublereal *, integer *, doublereal *); |
378 | 0 | integer it; |
379 | 0 | static doublereal rnd, eps; |
380 | | |
381 | | |
382 | | /* -- LAPACK auxiliary routine (version 3.7.0) -- */ |
383 | | /* -- LAPACK is a software package provided by Univ. of Tennessee, -- */ |
384 | | /* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- */ |
385 | | /* April 2012 */ |
386 | | |
387 | |
|
388 | 0 | if (first) { |
389 | 0 | dlamc2_(&beta, &it, &lrnd, &eps, &imin, &rmin, &imax, &rmax); |
390 | 0 | base = (doublereal) beta; |
391 | 0 | t = (doublereal) it; |
392 | 0 | if (lrnd) { |
393 | 0 | rnd = 1.; |
394 | 0 | i__1 = 1 - it; |
395 | 0 | eps = pow_di(&base, &i__1) / 2; |
396 | 0 | } else { |
397 | 0 | rnd = 0.; |
398 | 0 | i__1 = 1 - it; |
399 | 0 | eps = pow_di(&base, &i__1); |
400 | 0 | } |
401 | 0 | prec = eps * base; |
402 | 0 | emin = (doublereal) imin; |
403 | 0 | emax = (doublereal) imax; |
404 | 0 | sfmin = rmin; |
405 | 0 | small = 1. / rmax; |
406 | 0 | if (small >= sfmin) { |
407 | | |
408 | | /* Use SMALL plus a bit, to avoid the possibility of rounding */ |
409 | | /* causing overflow when computing 1/sfmin. */ |
410 | |
|
411 | 0 | sfmin = small * (eps + 1.); |
412 | 0 | } |
413 | 0 | } |
414 | |
|
415 | 0 | if (lsame_(cmach, "E")) { |
416 | 0 | rmach = eps; |
417 | 0 | } else if (lsame_(cmach, "S")) { |
418 | 0 | rmach = sfmin; |
419 | 0 | } else if (lsame_(cmach, "B")) { |
420 | 0 | rmach = base; |
421 | 0 | } else if (lsame_(cmach, "P")) { |
422 | 0 | rmach = prec; |
423 | 0 | } else if (lsame_(cmach, "N")) { |
424 | 0 | rmach = t; |
425 | 0 | } else if (lsame_(cmach, "R")) { |
426 | 0 | rmach = rnd; |
427 | 0 | } else if (lsame_(cmach, "M")) { |
428 | 0 | rmach = emin; |
429 | 0 | } else if (lsame_(cmach, "U")) { |
430 | 0 | rmach = rmin; |
431 | 0 | } else if (lsame_(cmach, "L")) { |
432 | 0 | rmach = emax; |
433 | 0 | } else if (lsame_(cmach, "O")) { |
434 | 0 | rmach = rmax; |
435 | 0 | } |
436 | |
|
437 | 0 | ret_val = rmach; |
438 | 0 | first = FALSE_; |
439 | 0 | return ret_val; |
440 | | |
441 | | /* End of DLAMCH */ |
442 | |
|
443 | 0 | } /* dlamch_ */ |
444 | | |
445 | | |
446 | | /* *********************************************************************** */ |
447 | | |
448 | | /* > \brief \b DLAMC1 */ |
449 | | /* > \details */ |
450 | | /* > \b Purpose: */ |
451 | | /* > \verbatim */ |
452 | | /* > DLAMC1 determines the machine parameters given by BETA, T, RND, and */ |
453 | | /* > IEEE1. */ |
454 | | /* > \endverbatim */ |
455 | | /* > */ |
456 | | /* > \param[out] BETA */ |
457 | | /* > \verbatim */ |
458 | | /* > The base of the machine. */ |
459 | | /* > \endverbatim */ |
460 | | /* > */ |
461 | | /* > \param[out] T */ |
462 | | /* > \verbatim */ |
463 | | /* > The number of ( BETA ) digits in the mantissa. */ |
464 | | /* > \endverbatim */ |
465 | | /* > */ |
466 | | /* > \param[out] RND */ |
467 | | /* > \verbatim */ |
468 | | /* > Specifies whether proper rounding ( RND = .TRUE. ) or */ |
469 | | /* > chopping ( RND = .FALSE. ) occurs in addition. This may not */ |
470 | | /* > be a reliable guide to the way in which the machine performs */ |
471 | | /* > its arithmetic. */ |
472 | | /* > \endverbatim */ |
473 | | /* > */ |
474 | | /* > \param[out] IEEE1 */ |
475 | | /* > \verbatim */ |
476 | | /* > Specifies whether rounding appears to be done in the IEEE */ |
477 | | /* > 'round to nearest' style. */ |
478 | | /* > \endverbatim */ |
479 | | /* > \author LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. |
480 | | of Colorado Denver and NAG Ltd.. */ |
481 | | /* > \date April 2012 */ |
482 | | /* > \ingroup auxOTHERauxiliary */ |
483 | | /* > */ |
484 | | /* > \details \b Further \b Details */ |
485 | | /* > \verbatim */ |
486 | | /* > */ |
487 | | /* > The routine is based on the routine ENVRON by Malcolm and */ |
488 | | /* > incorporates suggestions by Gentleman and Marovich. See */ |
489 | | /* > */ |
490 | | /* > Malcolm M. A. (1972) Algorithms to reveal properties of */ |
491 | | /* > floating-point arithmetic. Comms. of the ACM, 15, 949-951. */ |
492 | | /* > */ |
493 | | /* > Gentleman W. M. and Marovich S. B. (1974) More on algorithms */ |
494 | | /* > that reveal properties of floating point arithmetic units. */ |
495 | | /* > Comms. of the ACM, 17, 276-277. */ |
496 | | /* > \endverbatim */ |
497 | | /* > */ |
498 | | /* Subroutine */ int dlamc1_(integer *beta, integer *t, logical *rnd, logical |
499 | | *ieee1) |
500 | 0 | { |
501 | | /* Initialized data */ |
502 | |
|
503 | 0 | static logical first = TRUE_; |
504 | | |
505 | | /* System generated locals */ |
506 | 0 | doublereal d__1, d__2; |
507 | | |
508 | | /* Local variables */ |
509 | 0 | static logical lrnd; |
510 | 0 | doublereal a, b, c__, f; |
511 | 0 | static integer lbeta; |
512 | 0 | doublereal savec; |
513 | 0 | extern doublereal dlamc3_(doublereal *, doublereal *); |
514 | 0 | static logical lieee1; |
515 | 0 | doublereal t1, t2; |
516 | 0 | static integer lt; |
517 | 0 | doublereal one, qtr; |
518 | | |
519 | | |
520 | | /* -- LAPACK auxiliary routine (version 3.7.0) -- */ |
521 | | /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
522 | | /* November 2010 */ |
523 | | |
524 | | /* ===================================================================== */ |
525 | | |
526 | |
|
527 | 0 | if (first) { |
528 | 0 | one = 1.; |
529 | | |
530 | | /* LBETA, LIEEE1, LT and LRND are the local values of BETA, */ |
531 | | /* IEEE1, T and RND. */ |
532 | | |
533 | | /* Throughout this routine we use the function DLAMC3 to ensure */ |
534 | | /* that relevant values are stored and not held in registers, or */ |
535 | | /* are not affected by optimizers. */ |
536 | | |
537 | | /* Compute a = 2.0**m with the smallest positive integer m such */ |
538 | | /* that */ |
539 | | |
540 | | /* fl( a + 1.0 ) = a. */ |
541 | |
|
542 | 0 | a = 1.; |
543 | 0 | c__ = 1.; |
544 | | |
545 | | /* + WHILE( C.EQ.ONE )LOOP */ |
546 | 0 | L10: |
547 | 0 | if (c__ == one) { |
548 | 0 | a *= 2; |
549 | 0 | c__ = dlamc3_(&a, &one); |
550 | 0 | d__1 = -a; |
551 | 0 | c__ = dlamc3_(&c__, &d__1); |
552 | 0 | goto L10; |
553 | 0 | } |
554 | | /* + END WHILE */ |
555 | | |
556 | | /* Now compute b = 2.0**m with the smallest positive integer m */ |
557 | | /* such that */ |
558 | | |
559 | | /* fl( a + b ) .gt. a. */ |
560 | | |
561 | 0 | b = 1.; |
562 | 0 | c__ = dlamc3_(&a, &b); |
563 | | |
564 | | /* + WHILE( C.EQ.A )LOOP */ |
565 | 0 | L20: |
566 | 0 | if (c__ == a) { |
567 | 0 | b *= 2; |
568 | 0 | c__ = dlamc3_(&a, &b); |
569 | 0 | goto L20; |
570 | 0 | } |
571 | | /* + END WHILE */ |
572 | | |
573 | | /* Now compute the base. a and c are neighbouring floating point */ |
574 | | /* numbers in the interval ( beta**t, beta**( t + 1 ) ) and so */ |
575 | | /* their difference is beta. Adding 0.25 to c is to ensure that it */ |
576 | | /* is truncated to beta and not ( beta - 1 ). */ |
577 | | |
578 | 0 | qtr = one / 4; |
579 | 0 | savec = c__; |
580 | 0 | d__1 = -a; |
581 | 0 | c__ = dlamc3_(&c__, &d__1); |
582 | 0 | lbeta = (integer) (c__ + qtr); |
583 | | |
584 | | /* Now determine whether rounding or chopping occurs, by adding a */ |
585 | | /* bit less than beta/2 and a bit more than beta/2 to a. */ |
586 | |
|
587 | 0 | b = (doublereal) lbeta; |
588 | 0 | d__1 = b / 2; |
589 | 0 | d__2 = -b / 100; |
590 | 0 | f = dlamc3_(&d__1, &d__2); |
591 | 0 | c__ = dlamc3_(&f, &a); |
592 | 0 | if (c__ == a) { |
593 | 0 | lrnd = TRUE_; |
594 | 0 | } else { |
595 | 0 | lrnd = FALSE_; |
596 | 0 | } |
597 | 0 | d__1 = b / 2; |
598 | 0 | d__2 = b / 100; |
599 | 0 | f = dlamc3_(&d__1, &d__2); |
600 | 0 | c__ = dlamc3_(&f, &a); |
601 | 0 | if (lrnd && c__ == a) { |
602 | 0 | lrnd = FALSE_; |
603 | 0 | } |
604 | | |
605 | | /* Try and decide whether rounding is done in the IEEE 'round to */ |
606 | | /* nearest' style. B/2 is half a unit in the last place of the two */ |
607 | | /* numbers A and SAVEC. Furthermore, A is even, i.e. has last bit */ |
608 | | /* zero, and SAVEC is odd. Thus adding B/2 to A should not change */ |
609 | | /* A, but adding B/2 to SAVEC should change SAVEC. */ |
610 | |
|
611 | 0 | d__1 = b / 2; |
612 | 0 | t1 = dlamc3_(&d__1, &a); |
613 | 0 | d__1 = b / 2; |
614 | 0 | t2 = dlamc3_(&d__1, &savec); |
615 | 0 | lieee1 = t1 == a && t2 > savec && lrnd; |
616 | | |
617 | | /* Now find the mantissa, t. It should be the integer part of */ |
618 | | /* log to the base beta of a, however it is safer to determine t */ |
619 | | /* by powering. So we find t as the smallest positive integer for */ |
620 | | /* which */ |
621 | | |
622 | | /* fl( beta**t + 1.0 ) = 1.0. */ |
623 | |
|
624 | 0 | lt = 0; |
625 | 0 | a = 1.; |
626 | 0 | c__ = 1.; |
627 | | |
628 | | /* + WHILE( C.EQ.ONE )LOOP */ |
629 | 0 | L30: |
630 | 0 | if (c__ == one) { |
631 | 0 | ++lt; |
632 | 0 | a *= lbeta; |
633 | 0 | c__ = dlamc3_(&a, &one); |
634 | 0 | d__1 = -a; |
635 | 0 | c__ = dlamc3_(&c__, &d__1); |
636 | 0 | goto L30; |
637 | 0 | } |
638 | | /* + END WHILE */ |
639 | |
|
640 | 0 | } |
641 | | |
642 | 0 | *beta = lbeta; |
643 | 0 | *t = lt; |
644 | 0 | *rnd = lrnd; |
645 | 0 | *ieee1 = lieee1; |
646 | 0 | first = FALSE_; |
647 | 0 | return 0; |
648 | | |
649 | | /* End of DLAMC1 */ |
650 | |
|
651 | 0 | } /* dlamc1_ */ |
652 | | |
653 | | |
654 | | /* *********************************************************************** */ |
655 | | |
656 | | /* > \brief \b DLAMC2 */ |
657 | | /* > \details */ |
658 | | /* > \b Purpose: */ |
659 | | /* > \verbatim */ |
660 | | /* > DLAMC2 determines the machine parameters specified in its argument */ |
661 | | /* > list. */ |
662 | | /* > \endverbatim */ |
663 | | /* > \author LAPACK is a software package provided by Univ. of Tennessee, Univ. of California Berkeley, Univ. |
664 | | of Colorado Denver and NAG Ltd.. */ |
665 | | /* > \date April 2012 */ |
666 | | /* > \ingroup auxOTHERauxiliary */ |
667 | | /* > */ |
668 | | /* > \param[out] BETA */ |
669 | | /* > \verbatim */ |
670 | | /* > The base of the machine. */ |
671 | | /* > \endverbatim */ |
672 | | /* > */ |
673 | | /* > \param[out] T */ |
674 | | /* > \verbatim */ |
675 | | /* > The number of ( BETA ) digits in the mantissa. */ |
676 | | /* > \endverbatim */ |
677 | | /* > */ |
678 | | /* > \param[out] RND */ |
679 | | /* > \verbatim */ |
680 | | /* > Specifies whether proper rounding ( RND = .TRUE. ) or */ |
681 | | /* > chopping ( RND = .FALSE. ) occurs in addition. This may not */ |
682 | | /* > be a reliable guide to the way in which the machine performs */ |
683 | | /* > its arithmetic. */ |
684 | | /* > \endverbatim */ |
685 | | /* > */ |
686 | | /* > \param[out] EPS */ |
687 | | /* > \verbatim */ |
688 | | /* > The smallest positive number such that */ |
689 | | /* > fl( 1.0 - EPS ) .LT. 1.0, */ |
690 | | /* > where fl denotes the computed value. */ |
691 | | /* > \endverbatim */ |
692 | | /* > */ |
693 | | /* > \param[out] EMIN */ |
694 | | /* > \verbatim */ |
695 | | /* > The minimum exponent before (gradual) underflow occurs. */ |
696 | | /* > \endverbatim */ |
697 | | /* > */ |
698 | | /* > \param[out] RMIN */ |
699 | | /* > \verbatim */ |
700 | | /* > The smallest normalized number for the machine, given by */ |
701 | | /* > BASE**( EMIN - 1 ), where BASE is the floating point value */ |
702 | | /* > of BETA. */ |
703 | | /* > \endverbatim */ |
704 | | /* > */ |
705 | | /* > \param[out] EMAX */ |
706 | | /* > \verbatim */ |
707 | | /* > The maximum exponent before overflow occurs. */ |
708 | | /* > \endverbatim */ |
709 | | /* > */ |
710 | | /* > \param[out] RMAX */ |
711 | | /* > \verbatim */ |
712 | | /* > The largest positive number for the machine, given by */ |
713 | | /* > BASE**EMAX * ( 1 - EPS ), where BASE is the floating point */ |
714 | | /* > value of BETA. */ |
715 | | /* > \endverbatim */ |
716 | | /* > */ |
717 | | /* > \details \b Further \b Details */ |
718 | | /* > \verbatim */ |
719 | | /* > */ |
720 | | /* > The computation of EPS is based on a routine PARANOIA by */ |
721 | | /* > W. Kahan of the University of California at Berkeley. */ |
722 | | /* > \endverbatim */ |
723 | | /* Subroutine */ int dlamc2_(integer *beta, integer *t, logical *rnd, |
724 | | doublereal *eps, integer *emin, doublereal *rmin, integer *emax, |
725 | | doublereal *rmax) |
726 | 0 | { |
727 | | /* Initialized data */ |
728 | |
|
729 | 0 | static logical first = TRUE_; |
730 | 0 | static logical iwarn = FALSE_; |
731 | | |
732 | | /* Format strings */ |
733 | 0 | static char fmt_9999[] = "(//\002 WARNING. The value EMIN may be incorre" |
734 | 0 | "ct:-\002,\002 EMIN = \002,i8,/\002 If, after inspection, the va" |
735 | 0 | "lue EMIN looks\002,\002 acceptable please comment out \002,/\002" |
736 | 0 | " the IF block as marked within the code of routine\002,\002 DLAM" |
737 | 0 | "C2,\002,/\002 otherwise supply EMIN explicitly.\002,/)"; |
738 | | |
739 | | /* System generated locals */ |
740 | 0 | integer i__1; |
741 | 0 | doublereal d__1, d__2, d__3, d__4, d__5; |
742 | | |
743 | | /* Local variables */ |
744 | 0 | logical ieee; |
745 | 0 | doublereal half; |
746 | 0 | logical lrnd; |
747 | 0 | static doublereal leps; |
748 | 0 | doublereal zero, a, b, c__; |
749 | 0 | integer i__; |
750 | 0 | static integer lbeta; |
751 | 0 | doublereal rbase; |
752 | 0 | static integer lemin, lemax; |
753 | 0 | integer gnmin; |
754 | 0 | doublereal small; |
755 | 0 | integer gpmin; |
756 | 0 | doublereal third; |
757 | 0 | static doublereal lrmin, lrmax; |
758 | 0 | doublereal sixth; |
759 | 0 | extern /* Subroutine */ int dlamc1_(integer *, integer *, logical *, |
760 | 0 | logical *); |
761 | 0 | extern doublereal dlamc3_(doublereal *, doublereal *); |
762 | 0 | logical lieee1; |
763 | 0 | extern /* Subroutine */ int dlamc4_(integer *, doublereal *, integer *), |
764 | 0 | dlamc5_(integer *, integer *, integer *, logical *, integer *, |
765 | 0 | doublereal *); |
766 | 0 | static integer lt; |
767 | 0 | integer ngnmin, ngpmin; |
768 | 0 | doublereal one, two; |
769 | | |
770 | | /* Fortran I/O blocks */ |
771 | 0 | static cilist io___58 = { 0, 6, 0, fmt_9999, 0 }; |
772 | | |
773 | | |
774 | | |
775 | | /* -- LAPACK auxiliary routine (version 3.7.0) -- */ |
776 | | /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
777 | | /* November 2010 */ |
778 | | |
779 | | /* ===================================================================== */ |
780 | | |
781 | |
|
782 | 0 | if (first) { |
783 | 0 | zero = 0.; |
784 | 0 | one = 1.; |
785 | 0 | two = 2.; |
786 | | |
787 | | /* LBETA, LT, LRND, LEPS, LEMIN and LRMIN are the local values of */ |
788 | | /* BETA, T, RND, EPS, EMIN and RMIN. */ |
789 | | |
790 | | /* Throughout this routine we use the function DLAMC3 to ensure */ |
791 | | /* that relevant values are stored and not held in registers, or */ |
792 | | /* are not affected by optimizers. */ |
793 | | |
794 | | /* DLAMC1 returns the parameters LBETA, LT, LRND and LIEEE1. */ |
795 | |
|
796 | 0 | dlamc1_(&lbeta, <, &lrnd, &lieee1); |
797 | | |
798 | | /* Start to find EPS. */ |
799 | |
|
800 | 0 | b = (doublereal) lbeta; |
801 | 0 | i__1 = -lt; |
802 | 0 | a = pow_di(&b, &i__1); |
803 | 0 | leps = a; |
804 | | |
805 | | /* Try some tricks to see whether or not this is the correct EPS. */ |
806 | |
|
807 | 0 | b = two / 3; |
808 | 0 | half = one / 2; |
809 | 0 | d__1 = -half; |
810 | 0 | sixth = dlamc3_(&b, &d__1); |
811 | 0 | third = dlamc3_(&sixth, &sixth); |
812 | 0 | d__1 = -half; |
813 | 0 | b = dlamc3_(&third, &d__1); |
814 | 0 | b = dlamc3_(&b, &sixth); |
815 | 0 | b = abs(b); |
816 | 0 | if (b < leps) { |
817 | 0 | b = leps; |
818 | 0 | } |
819 | |
|
820 | 0 | leps = 1.; |
821 | | |
822 | | /* + WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP */ |
823 | 0 | L10: |
824 | 0 | if (leps > b && b > zero) { |
825 | 0 | leps = b; |
826 | 0 | d__1 = half * leps; |
827 | | /* Computing 5th power */ |
828 | 0 | d__3 = two, d__4 = d__3, d__3 *= d__3; |
829 | | /* Computing 2nd power */ |
830 | 0 | d__5 = leps; |
831 | 0 | d__2 = d__4 * (d__3 * d__3) * (d__5 * d__5); |
832 | 0 | c__ = dlamc3_(&d__1, &d__2); |
833 | 0 | d__1 = -c__; |
834 | 0 | c__ = dlamc3_(&half, &d__1); |
835 | 0 | b = dlamc3_(&half, &c__); |
836 | 0 | d__1 = -b; |
837 | 0 | c__ = dlamc3_(&half, &d__1); |
838 | 0 | b = dlamc3_(&half, &c__); |
839 | 0 | goto L10; |
840 | 0 | } |
841 | | /* + END WHILE */ |
842 | | |
843 | 0 | if (a < leps) { |
844 | 0 | leps = a; |
845 | 0 | } |
846 | | |
847 | | /* Computation of EPS complete. */ |
848 | | |
849 | | /* Now find EMIN. Let A = + or - 1, and + or - (1 + BASE**(-3)). */ |
850 | | /* Keep dividing A by BETA until (gradual) underflow occurs. This */ |
851 | | /* is detected when we cannot recover the previous A. */ |
852 | |
|
853 | 0 | rbase = one / lbeta; |
854 | 0 | small = one; |
855 | 0 | for (i__ = 1; i__ <= 3; ++i__) { |
856 | 0 | d__1 = small * rbase; |
857 | 0 | small = dlamc3_(&d__1, &zero); |
858 | | /* L20: */ |
859 | 0 | } |
860 | 0 | a = dlamc3_(&one, &small); |
861 | 0 | dlamc4_(&ngpmin, &one, &lbeta); |
862 | 0 | d__1 = -one; |
863 | 0 | dlamc4_(&ngnmin, &d__1, &lbeta); |
864 | 0 | dlamc4_(&gpmin, &a, &lbeta); |
865 | 0 | d__1 = -a; |
866 | 0 | dlamc4_(&gnmin, &d__1, &lbeta); |
867 | 0 | ieee = FALSE_; |
868 | |
|
869 | 0 | if (ngpmin == ngnmin && gpmin == gnmin) { |
870 | 0 | if (ngpmin == gpmin) { |
871 | 0 | lemin = ngpmin; |
872 | | /* ( Non twos-complement machines, no gradual underflow; */ |
873 | | /* e.g., VAX ) */ |
874 | 0 | } else if (gpmin - ngpmin == 3) { |
875 | 0 | lemin = ngpmin - 1 + lt; |
876 | 0 | ieee = TRUE_; |
877 | | /* ( Non twos-complement machines, with gradual underflow; */ |
878 | | /* e.g., IEEE standard followers ) */ |
879 | 0 | } else { |
880 | 0 | lemin = f2cmin(ngpmin,gpmin); |
881 | | /* ( A guess; no known machine ) */ |
882 | 0 | iwarn = TRUE_; |
883 | 0 | } |
884 | |
|
885 | 0 | } else if (ngpmin == gpmin && ngnmin == gnmin) { |
886 | 0 | if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1) { |
887 | 0 | lemin = f2cmax(ngpmin,ngnmin); |
888 | | /* ( Twos-complement machines, no gradual underflow; */ |
889 | | /* e.g., CYBER 205 ) */ |
890 | 0 | } else { |
891 | 0 | lemin = f2cmin(ngpmin,ngnmin); |
892 | | /* ( A guess; no known machine ) */ |
893 | 0 | iwarn = TRUE_; |
894 | 0 | } |
895 | |
|
896 | 0 | } else if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1 && gpmin == gnmin) |
897 | 0 | { |
898 | 0 | if (gpmin - f2cmin(ngpmin,ngnmin) == 3) { |
899 | 0 | lemin = f2cmax(ngpmin,ngnmin) - 1 + lt; |
900 | | /* ( Twos-complement machines with gradual underflow; */ |
901 | | /* no known machine ) */ |
902 | 0 | } else { |
903 | 0 | lemin = f2cmin(ngpmin,ngnmin); |
904 | | /* ( A guess; no known machine ) */ |
905 | 0 | iwarn = TRUE_; |
906 | 0 | } |
907 | |
|
908 | 0 | } else { |
909 | | /* Computing MIN */ |
910 | 0 | i__1 = f2cmin(ngpmin,ngnmin), i__1 = f2cmin(i__1,gpmin); |
911 | 0 | lemin = f2cmin(i__1,gnmin); |
912 | | /* ( A guess; no known machine ) */ |
913 | 0 | iwarn = TRUE_; |
914 | 0 | } |
915 | 0 | first = FALSE_; |
916 | | /* ** */ |
917 | | /* Comment out this if block if EMIN is ok */ |
918 | | /* |
919 | | if (iwarn) { |
920 | | first = TRUE_; |
921 | | s_wsfe(&io___58); |
922 | | do_fio(&c__1, (char *)&lemin, (ftnlen)sizeof(integer)); |
923 | | e_wsfe(); |
924 | | } |
925 | | */ |
926 | | /* ** */ |
927 | | |
928 | | /* Assume IEEE arithmetic if we found denormalised numbers above, */ |
929 | | /* or if arithmetic seems to round in the IEEE style, determined */ |
930 | | /* in routine DLAMC1. A true IEEE machine should have both things */ |
931 | | /* true; however, faulty machines may have one or the other. */ |
932 | |
|
933 | 0 | ieee = ieee || lieee1; |
934 | | |
935 | | /* Compute RMIN by successive division by BETA. We could compute */ |
936 | | /* RMIN as BASE**( EMIN - 1 ), but some machines underflow during */ |
937 | | /* this computation. */ |
938 | |
|
939 | 0 | lrmin = 1.; |
940 | 0 | i__1 = 1 - lemin; |
941 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
942 | 0 | d__1 = lrmin * rbase; |
943 | 0 | lrmin = dlamc3_(&d__1, &zero); |
944 | | /* L30: */ |
945 | 0 | } |
946 | | |
947 | | /* Finally, call DLAMC5 to compute EMAX and RMAX. */ |
948 | |
|
949 | 0 | dlamc5_(&lbeta, <, &lemin, &ieee, &lemax, &lrmax); |
950 | 0 | } |
951 | | |
952 | 0 | *beta = lbeta; |
953 | 0 | *t = lt; |
954 | 0 | *rnd = lrnd; |
955 | 0 | *eps = leps; |
956 | 0 | *emin = lemin; |
957 | 0 | *rmin = lrmin; |
958 | 0 | *emax = lemax; |
959 | 0 | *rmax = lrmax; |
960 | |
|
961 | 0 | return 0; |
962 | | |
963 | | |
964 | | /* End of DLAMC2 */ |
965 | |
|
966 | 0 | } /* dlamc2_ */ |
967 | | |
968 | | |
969 | | /* *********************************************************************** */ |
970 | | |
971 | | /* > \brief \b DLAMC3 */ |
972 | | /* > \details */ |
973 | | /* > \b Purpose: */ |
974 | | /* > \verbatim */ |
975 | | /* > DLAMC3 is intended to force A and B to be stored prior to doing */ |
976 | | /* > the addition of A and B , for use in situations where optimizers */ |
977 | | /* > might hold one of these in a register. */ |
978 | | /* > \endverbatim */ |
979 | | /* > */ |
980 | | /* > \param[in] A */ |
981 | | /* > */ |
982 | | /* > \param[in] B */ |
983 | | /* > \verbatim */ |
984 | | /* > The values A and B. */ |
985 | | /* > \endverbatim */ |
986 | | doublereal dlamc3_(doublereal *a, doublereal *b) |
987 | 0 | { |
988 | | /* System generated locals */ |
989 | 0 | doublereal ret_val; |
990 | | |
991 | | |
992 | | /* -- LAPACK auxiliary routine (version 3.7.0) -- */ |
993 | | /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
994 | | /* November 2010 */ |
995 | | |
996 | | /* ===================================================================== */ |
997 | | |
998 | |
|
999 | 0 | ret_val = *a + *b; |
1000 | |
|
1001 | 0 | return ret_val; |
1002 | | |
1003 | | /* End of DLAMC3 */ |
1004 | |
|
1005 | 0 | } /* dlamc3_ */ |
1006 | | |
1007 | | |
1008 | | /* *********************************************************************** */ |
1009 | | |
1010 | | /* > \brief \b DLAMC4 */ |
1011 | | /* > \details */ |
1012 | | /* > \b Purpose: */ |
1013 | | /* > \verbatim */ |
1014 | | /* > DLAMC4 is a service routine for DLAMC2. */ |
1015 | | /* > \endverbatim */ |
1016 | | /* > */ |
1017 | | /* > \param[out] EMIN */ |
1018 | | /* > \verbatim */ |
1019 | | /* > The minimum exponent before (gradual) underflow, computed by */ |
1020 | | /* > setting A = START and dividing by BASE until the previous A */ |
1021 | | /* > can not be recovered. */ |
1022 | | /* > \endverbatim */ |
1023 | | /* > */ |
1024 | | /* > \param[in] START */ |
1025 | | /* > \verbatim */ |
1026 | | /* > The starting point for determining EMIN. */ |
1027 | | /* > \endverbatim */ |
1028 | | /* > */ |
1029 | | /* > \param[in] BASE */ |
1030 | | /* > \verbatim */ |
1031 | | /* > The base of the machine. */ |
1032 | | /* > \endverbatim */ |
1033 | | /* > */ |
1034 | | /* Subroutine */ int dlamc4_(integer *emin, doublereal *start, integer *base) |
1035 | 0 | { |
1036 | | /* System generated locals */ |
1037 | 0 | integer i__1; |
1038 | 0 | doublereal d__1; |
1039 | | |
1040 | | /* Local variables */ |
1041 | 0 | doublereal zero, a; |
1042 | 0 | integer i__; |
1043 | 0 | doublereal rbase, b1, b2, c1, c2, d1, d2; |
1044 | 0 | extern doublereal dlamc3_(doublereal *, doublereal *); |
1045 | 0 | doublereal one; |
1046 | | |
1047 | | |
1048 | | /* -- LAPACK auxiliary routine (version 3.7.0) -- */ |
1049 | | /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
1050 | | /* November 2010 */ |
1051 | | |
1052 | | /* ===================================================================== */ |
1053 | | |
1054 | |
|
1055 | 0 | a = *start; |
1056 | 0 | one = 1.; |
1057 | 0 | rbase = one / *base; |
1058 | 0 | zero = 0.; |
1059 | 0 | *emin = 1; |
1060 | 0 | d__1 = a * rbase; |
1061 | 0 | b1 = dlamc3_(&d__1, &zero); |
1062 | 0 | c1 = a; |
1063 | 0 | c2 = a; |
1064 | 0 | d1 = a; |
1065 | 0 | d2 = a; |
1066 | | /* + WHILE( ( C1.EQ.A ).AND.( C2.EQ.A ).AND. */ |
1067 | | /* $ ( D1.EQ.A ).AND.( D2.EQ.A ) )LOOP */ |
1068 | 0 | L10: |
1069 | 0 | if (c1 == a && c2 == a && d1 == a && d2 == a) { |
1070 | 0 | --(*emin); |
1071 | 0 | a = b1; |
1072 | 0 | d__1 = a / *base; |
1073 | 0 | b1 = dlamc3_(&d__1, &zero); |
1074 | 0 | d__1 = b1 * *base; |
1075 | 0 | c1 = dlamc3_(&d__1, &zero); |
1076 | 0 | d1 = zero; |
1077 | 0 | i__1 = *base; |
1078 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
1079 | 0 | d1 += b1; |
1080 | | /* L20: */ |
1081 | 0 | } |
1082 | 0 | d__1 = a * rbase; |
1083 | 0 | b2 = dlamc3_(&d__1, &zero); |
1084 | 0 | d__1 = b2 / rbase; |
1085 | 0 | c2 = dlamc3_(&d__1, &zero); |
1086 | 0 | d2 = zero; |
1087 | 0 | i__1 = *base; |
1088 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
1089 | 0 | d2 += b2; |
1090 | | /* L30: */ |
1091 | 0 | } |
1092 | 0 | goto L10; |
1093 | 0 | } |
1094 | | /* + END WHILE */ |
1095 | | |
1096 | 0 | return 0; |
1097 | | |
1098 | | /* End of DLAMC4 */ |
1099 | |
|
1100 | 0 | } /* dlamc4_ */ |
1101 | | |
1102 | | |
1103 | | /* *********************************************************************** */ |
1104 | | |
1105 | | /* > \brief \b DLAMC5 */ |
1106 | | /* > \details */ |
1107 | | /* > \b Purpose: */ |
1108 | | /* > \verbatim */ |
1109 | | /* > DLAMC5 attempts to compute RMAX, the largest machine floating-point */ |
1110 | | /* > number, without overflow. It assumes that EMAX + abs(EMIN) sum */ |
1111 | | /* > approximately to a power of 2. It will fail on machines where this */ |
1112 | | /* > assumption does not hold, for example, the Cyber 205 (EMIN = -28625, */ |
1113 | | /* > EMAX = 28718). It will also fail if the value supplied for EMIN is */ |
1114 | | /* > too large (i.e. too close to zero), probably with overflow. */ |
1115 | | /* > \endverbatim */ |
1116 | | /* > */ |
1117 | | /* > \param[in] BETA */ |
1118 | | /* > \verbatim */ |
1119 | | /* > The base of floating-point arithmetic. */ |
1120 | | /* > \endverbatim */ |
1121 | | /* > */ |
1122 | | /* > \param[in] P */ |
1123 | | /* > \verbatim */ |
1124 | | /* > The number of base BETA digits in the mantissa of a */ |
1125 | | /* > floating-point value. */ |
1126 | | /* > \endverbatim */ |
1127 | | /* > */ |
1128 | | /* > \param[in] EMIN */ |
1129 | | /* > \verbatim */ |
1130 | | /* > The minimum exponent before (gradual) underflow. */ |
1131 | | /* > \endverbatim */ |
1132 | | /* > */ |
1133 | | /* > \param[in] IEEE */ |
1134 | | /* > \verbatim */ |
1135 | | /* > A logical flag specifying whether or not the arithmetic */ |
1136 | | /* > system is thought to comply with the IEEE standard. */ |
1137 | | /* > \endverbatim */ |
1138 | | /* > */ |
1139 | | /* > \param[out] EMAX */ |
1140 | | /* > \verbatim */ |
1141 | | /* > The largest exponent before overflow */ |
1142 | | /* > \endverbatim */ |
1143 | | /* > */ |
1144 | | /* > \param[out] RMAX */ |
1145 | | /* > \verbatim */ |
1146 | | /* > The largest machine floating-point number. */ |
1147 | | /* > \endverbatim */ |
1148 | | /* > */ |
1149 | | /* Subroutine */ int dlamc5_(integer *beta, integer *p, integer *emin, |
1150 | | logical *ieee, integer *emax, doublereal *rmax) |
1151 | 0 | { |
1152 | | /* System generated locals */ |
1153 | 0 | integer i__1; |
1154 | 0 | doublereal d__1; |
1155 | | |
1156 | | /* Local variables */ |
1157 | 0 | integer lexp; |
1158 | 0 | doublereal oldy; |
1159 | 0 | integer uexp, i__; |
1160 | 0 | doublereal y, z__; |
1161 | 0 | integer nbits; |
1162 | 0 | extern doublereal dlamc3_(doublereal *, doublereal *); |
1163 | 0 | doublereal recbas; |
1164 | 0 | integer exbits, expsum, try__; |
1165 | | |
1166 | | |
1167 | | /* -- LAPACK auxiliary routine (version 3.7.0) -- */ |
1168 | | /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */ |
1169 | | /* November 2010 */ |
1170 | | |
1171 | | /* ===================================================================== */ |
1172 | | |
1173 | | |
1174 | | /* First compute LEXP and UEXP, two powers of 2 that bound */ |
1175 | | /* abs(EMIN). We then assume that EMAX + abs(EMIN) will sum */ |
1176 | | /* approximately to the bound that is closest to abs(EMIN). */ |
1177 | | /* (EMAX is the exponent of the required number RMAX). */ |
1178 | |
|
1179 | 0 | lexp = 1; |
1180 | 0 | exbits = 1; |
1181 | 0 | L10: |
1182 | 0 | try__ = lexp << 1; |
1183 | 0 | if (try__ <= -(*emin)) { |
1184 | 0 | lexp = try__; |
1185 | 0 | ++exbits; |
1186 | 0 | goto L10; |
1187 | 0 | } |
1188 | 0 | if (lexp == -(*emin)) { |
1189 | 0 | uexp = lexp; |
1190 | 0 | } else { |
1191 | 0 | uexp = try__; |
1192 | 0 | ++exbits; |
1193 | 0 | } |
1194 | | |
1195 | | /* Now -LEXP is less than or equal to EMIN, and -UEXP is greater */ |
1196 | | /* than or equal to EMIN. EXBITS is the number of bits needed to */ |
1197 | | /* store the exponent. */ |
1198 | |
|
1199 | 0 | if (uexp + *emin > -lexp - *emin) { |
1200 | 0 | expsum = lexp << 1; |
1201 | 0 | } else { |
1202 | 0 | expsum = uexp << 1; |
1203 | 0 | } |
1204 | | |
1205 | | /* EXPSUM is the exponent range, approximately equal to */ |
1206 | | /* EMAX - EMIN + 1 . */ |
1207 | |
|
1208 | 0 | *emax = expsum + *emin - 1; |
1209 | 0 | nbits = exbits + 1 + *p; |
1210 | | |
1211 | | /* NBITS is the total number of bits needed to store a */ |
1212 | | /* floating-point number. */ |
1213 | |
|
1214 | 0 | if (nbits % 2 == 1 && *beta == 2) { |
1215 | | |
1216 | | /* Either there are an odd number of bits used to store a */ |
1217 | | /* floating-point number, which is unlikely, or some bits are */ |
1218 | | /* not used in the representation of numbers, which is possible, */ |
1219 | | /* (e.g. Cray machines) or the mantissa has an implicit bit, */ |
1220 | | /* (e.g. IEEE machines, Dec Vax machines), which is perhaps the */ |
1221 | | /* most likely. We have to assume the last alternative. */ |
1222 | | /* If this is true, then we need to reduce EMAX by one because */ |
1223 | | /* there must be some way of representing zero in an implicit-bit */ |
1224 | | /* system. On machines like Cray, we are reducing EMAX by one */ |
1225 | | /* unnecessarily. */ |
1226 | |
|
1227 | 0 | --(*emax); |
1228 | 0 | } |
1229 | |
|
1230 | 0 | if (*ieee) { |
1231 | | |
1232 | | /* Assume we are on an IEEE machine which reserves one exponent */ |
1233 | | /* for infinity and NaN. */ |
1234 | |
|
1235 | 0 | --(*emax); |
1236 | 0 | } |
1237 | | |
1238 | | /* Now create RMAX, the largest machine number, which should */ |
1239 | | /* be equal to (1.0 - BETA**(-P)) * BETA**EMAX . */ |
1240 | | |
1241 | | /* First compute 1.0 - BETA**(-P), being careful that the */ |
1242 | | /* result is less than 1.0 . */ |
1243 | |
|
1244 | 0 | recbas = 1. / *beta; |
1245 | 0 | z__ = *beta - 1.; |
1246 | 0 | y = 0.; |
1247 | 0 | i__1 = *p; |
1248 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
1249 | 0 | z__ *= recbas; |
1250 | 0 | if (y < 1.) { |
1251 | 0 | oldy = y; |
1252 | 0 | } |
1253 | 0 | y = dlamc3_(&y, &z__); |
1254 | | /* L20: */ |
1255 | 0 | } |
1256 | 0 | if (y >= 1.) { |
1257 | 0 | y = oldy; |
1258 | 0 | } |
1259 | | |
1260 | | /* Now multiply by BETA**EMAX to get RMAX. */ |
1261 | |
|
1262 | 0 | i__1 = *emax; |
1263 | 0 | for (i__ = 1; i__ <= i__1; ++i__) { |
1264 | 0 | d__1 = y * *beta; |
1265 | 0 | y = dlamc3_(&d__1, &c_b32); |
1266 | | /* L30: */ |
1267 | 0 | } |
1268 | |
|
1269 | 0 | *rmax = y; |
1270 | 0 | return 0; |
1271 | | |
1272 | | /* End of DLAMC5 */ |
1273 | |
|
1274 | 0 | } /* dlamc5_ */ |
1275 | | |