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