You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dlamch.c 34 kB

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