dlamch.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002
  1. /* dlamch.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Table of constant values */
  14. static integer c__1 = 1;
  15. static doublereal c_b32 = 0.;
  16. doublereal _starpu_dlamch_(char *cmach)
  17. {
  18. /* Initialized data */
  19. static logical first = TRUE_;
  20. /* System generated locals */
  21. integer i__1;
  22. doublereal ret_val;
  23. /* Builtin functions */
  24. double pow_di(doublereal *, integer *);
  25. /* Local variables */
  26. static doublereal t;
  27. integer it;
  28. static doublereal rnd, eps, base;
  29. integer beta;
  30. static doublereal emin, prec, emax;
  31. integer imin, imax;
  32. logical lrnd;
  33. static doublereal rmin, rmax;
  34. doublereal rmach;
  35. extern logical _starpu_lsame_(char *, char *);
  36. doublereal small;
  37. static doublereal sfmin;
  38. extern /* Subroutine */ int _starpu_dlamc2_(integer *, integer *, logical *,
  39. doublereal *, integer *, doublereal *, integer *, doublereal *);
  40. /* -- LAPACK auxiliary routine (version 3.2) -- */
  41. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  42. /* November 2006 */
  43. /* .. Scalar Arguments .. */
  44. /* .. */
  45. /* Purpose */
  46. /* ======= */
  47. /* DLAMCH determines double precision machine parameters. */
  48. /* Arguments */
  49. /* ========= */
  50. /* CMACH (input) CHARACTER*1 */
  51. /* Specifies the value to be returned by DLAMCH: */
  52. /* = 'E' or 'e', DLAMCH := eps */
  53. /* = 'S' or 's , DLAMCH := sfmin */
  54. /* = 'B' or 'b', DLAMCH := base */
  55. /* = 'P' or 'p', DLAMCH := eps*base */
  56. /* = 'N' or 'n', DLAMCH := t */
  57. /* = 'R' or 'r', DLAMCH := rnd */
  58. /* = 'M' or 'm', DLAMCH := emin */
  59. /* = 'U' or 'u', DLAMCH := rmin */
  60. /* = 'L' or 'l', DLAMCH := emax */
  61. /* = 'O' or 'o', DLAMCH := rmax */
  62. /* where */
  63. /* eps = relative machine precision */
  64. /* sfmin = safe minimum, such that 1/sfmin does not overflow */
  65. /* base = base of the machine */
  66. /* prec = eps*base */
  67. /* t = number of (base) digits in the mantissa */
  68. /* rnd = 1.0 when rounding occurs in addition, 0.0 otherwise */
  69. /* emin = minimum exponent before (gradual) underflow */
  70. /* rmin = underflow threshold - base**(emin-1) */
  71. /* emax = largest exponent before overflow */
  72. /* rmax = overflow threshold - (base**emax)*(1-eps) */
  73. /* ===================================================================== */
  74. /* .. Parameters .. */
  75. /* .. */
  76. /* .. Local Scalars .. */
  77. /* .. */
  78. /* .. External Functions .. */
  79. /* .. */
  80. /* .. External Subroutines .. */
  81. /* .. */
  82. /* .. Save statement .. */
  83. /* .. */
  84. /* .. Data statements .. */
  85. /* .. */
  86. /* .. Executable Statements .. */
  87. if (first) {
  88. _starpu_dlamc2_(&beta, &it, &lrnd, &eps, &imin, &rmin, &imax, &rmax);
  89. base = (doublereal) beta;
  90. t = (doublereal) it;
  91. if (lrnd) {
  92. rnd = 1.;
  93. i__1 = 1 - it;
  94. eps = pow_di(&base, &i__1) / 2;
  95. } else {
  96. rnd = 0.;
  97. i__1 = 1 - it;
  98. eps = pow_di(&base, &i__1);
  99. }
  100. prec = eps * base;
  101. emin = (doublereal) imin;
  102. emax = (doublereal) imax;
  103. sfmin = rmin;
  104. small = 1. / rmax;
  105. if (small >= sfmin) {
  106. /* Use SMALL plus a bit, to avoid the possibility of rounding */
  107. /* causing overflow when computing 1/sfmin. */
  108. sfmin = small * (eps + 1.);
  109. }
  110. }
  111. if (_starpu_lsame_(cmach, "E")) {
  112. rmach = eps;
  113. } else if (_starpu_lsame_(cmach, "S")) {
  114. rmach = sfmin;
  115. } else if (_starpu_lsame_(cmach, "B")) {
  116. rmach = base;
  117. } else if (_starpu_lsame_(cmach, "P")) {
  118. rmach = prec;
  119. } else if (_starpu_lsame_(cmach, "N")) {
  120. rmach = t;
  121. } else if (_starpu_lsame_(cmach, "R")) {
  122. rmach = rnd;
  123. } else if (_starpu_lsame_(cmach, "M")) {
  124. rmach = emin;
  125. } else if (_starpu_lsame_(cmach, "U")) {
  126. rmach = rmin;
  127. } else if (_starpu_lsame_(cmach, "L")) {
  128. rmach = emax;
  129. } else if (_starpu_lsame_(cmach, "O")) {
  130. rmach = rmax;
  131. }
  132. ret_val = rmach;
  133. first = FALSE_;
  134. return ret_val;
  135. /* End of DLAMCH */
  136. } /* _starpu_dlamch_ */
  137. /* *********************************************************************** */
  138. /* Subroutine */ int _starpu_dlamc1_(integer *beta, integer *t, logical *rnd, logical
  139. *ieee1)
  140. {
  141. /* Initialized data */
  142. static logical first = TRUE_;
  143. /* System generated locals */
  144. doublereal d__1, d__2;
  145. /* Local variables */
  146. doublereal a, b, c__, f, t1, t2;
  147. static integer lt;
  148. doublereal one, qtr;
  149. static logical lrnd;
  150. static integer lbeta;
  151. doublereal savec;
  152. extern doublereal _starpu_dlamc3_(doublereal *, doublereal *);
  153. static logical lieee1;
  154. /* -- LAPACK auxiliary routine (version 3.2) -- */
  155. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  156. /* November 2006 */
  157. /* .. Scalar Arguments .. */
  158. /* .. */
  159. /* Purpose */
  160. /* ======= */
  161. /* DLAMC1 determines the machine parameters given by BETA, T, RND, and */
  162. /* IEEE1. */
  163. /* Arguments */
  164. /* ========= */
  165. /* BETA (output) INTEGER */
  166. /* The base of the machine. */
  167. /* T (output) INTEGER */
  168. /* The number of ( BETA ) digits in the mantissa. */
  169. /* RND (output) LOGICAL */
  170. /* Specifies whether proper rounding ( RND = .TRUE. ) or */
  171. /* chopping ( RND = .FALSE. ) occurs in addition. This may not */
  172. /* be a reliable guide to the way in which the machine performs */
  173. /* its arithmetic. */
  174. /* IEEE1 (output) LOGICAL */
  175. /* Specifies whether rounding appears to be done in the IEEE */
  176. /* 'round to nearest' style. */
  177. /* Further Details */
  178. /* =============== */
  179. /* The routine is based on the routine ENVRON by Malcolm and */
  180. /* incorporates suggestions by Gentleman and Marovich. See */
  181. /* Malcolm M. A. (1972) Algorithms to reveal properties of */
  182. /* floating-point arithmetic. Comms. of the ACM, 15, 949-951. */
  183. /* Gentleman W. M. and Marovich S. B. (1974) More on algorithms */
  184. /* that reveal properties of floating point arithmetic units. */
  185. /* Comms. of the ACM, 17, 276-277. */
  186. /* ===================================================================== */
  187. /* .. Local Scalars .. */
  188. /* .. */
  189. /* .. External Functions .. */
  190. /* .. */
  191. /* .. Save statement .. */
  192. /* .. */
  193. /* .. Data statements .. */
  194. /* .. */
  195. /* .. Executable Statements .. */
  196. if (first) {
  197. one = 1.;
  198. /* LBETA, LIEEE1, LT and LRND are the local values of BETA, */
  199. /* IEEE1, T and RND. */
  200. /* Throughout this routine we use the function DLAMC3 to ensure */
  201. /* that relevant values are stored and not held in registers, or */
  202. /* are not affected by optimizers. */
  203. /* Compute a = 2.0**m with the smallest positive integer m such */
  204. /* that */
  205. /* fl( a + 1.0 ) = a. */
  206. a = 1.;
  207. c__ = 1.;
  208. /* + WHILE( C.EQ.ONE )LOOP */
  209. L10:
  210. if (c__ == one) {
  211. a *= 2;
  212. c__ = _starpu_dlamc3_(&a, &one);
  213. d__1 = -a;
  214. c__ = _starpu_dlamc3_(&c__, &d__1);
  215. goto L10;
  216. }
  217. /* + END WHILE */
  218. /* Now compute b = 2.0**m with the smallest positive integer m */
  219. /* such that */
  220. /* fl( a + b ) .gt. a. */
  221. b = 1.;
  222. c__ = _starpu_dlamc3_(&a, &b);
  223. /* + WHILE( C.EQ.A )LOOP */
  224. L20:
  225. if (c__ == a) {
  226. b *= 2;
  227. c__ = _starpu_dlamc3_(&a, &b);
  228. goto L20;
  229. }
  230. /* + END WHILE */
  231. /* Now compute the base. a and c are neighbouring floating point */
  232. /* numbers in the interval ( beta**t, beta**( t + 1 ) ) and so */
  233. /* their difference is beta. Adding 0.25 to c is to ensure that it */
  234. /* is truncated to beta and not ( beta - 1 ). */
  235. qtr = one / 4;
  236. savec = c__;
  237. d__1 = -a;
  238. c__ = _starpu_dlamc3_(&c__, &d__1);
  239. lbeta = (integer) (c__ + qtr);
  240. /* Now determine whether rounding or chopping occurs, by adding a */
  241. /* bit less than beta/2 and a bit more than beta/2 to a. */
  242. b = (doublereal) lbeta;
  243. d__1 = b / 2;
  244. d__2 = -b / 100;
  245. f = _starpu_dlamc3_(&d__1, &d__2);
  246. c__ = _starpu_dlamc3_(&f, &a);
  247. if (c__ == a) {
  248. lrnd = TRUE_;
  249. } else {
  250. lrnd = FALSE_;
  251. }
  252. d__1 = b / 2;
  253. d__2 = b / 100;
  254. f = _starpu_dlamc3_(&d__1, &d__2);
  255. c__ = _starpu_dlamc3_(&f, &a);
  256. if (lrnd && c__ == a) {
  257. lrnd = FALSE_;
  258. }
  259. /* Try and decide whether rounding is done in the IEEE 'round to */
  260. /* nearest' style. B/2 is half a unit in the last place of the two */
  261. /* numbers A and SAVEC. Furthermore, A is even, i.e. has last bit */
  262. /* zero, and SAVEC is odd. Thus adding B/2 to A should not change */
  263. /* A, but adding B/2 to SAVEC should change SAVEC. */
  264. d__1 = b / 2;
  265. t1 = _starpu_dlamc3_(&d__1, &a);
  266. d__1 = b / 2;
  267. t2 = _starpu_dlamc3_(&d__1, &savec);
  268. lieee1 = t1 == a && t2 > savec && lrnd;
  269. /* Now find the mantissa, t. It should be the integer part of */
  270. /* log to the base beta of a, however it is safer to determine t */
  271. /* by powering. So we find t as the smallest positive integer for */
  272. /* which */
  273. /* fl( beta**t + 1.0 ) = 1.0. */
  274. lt = 0;
  275. a = 1.;
  276. c__ = 1.;
  277. /* + WHILE( C.EQ.ONE )LOOP */
  278. L30:
  279. if (c__ == one) {
  280. ++lt;
  281. a *= lbeta;
  282. c__ = _starpu_dlamc3_(&a, &one);
  283. d__1 = -a;
  284. c__ = _starpu_dlamc3_(&c__, &d__1);
  285. goto L30;
  286. }
  287. /* + END WHILE */
  288. }
  289. *beta = lbeta;
  290. *t = lt;
  291. *rnd = lrnd;
  292. *ieee1 = lieee1;
  293. first = FALSE_;
  294. return 0;
  295. /* End of DLAMC1 */
  296. } /* _starpu_dlamc1_ */
  297. /* *********************************************************************** */
  298. /* Subroutine */ int _starpu_dlamc2_(integer *beta, integer *t, logical *rnd,
  299. doublereal *eps, integer *emin, doublereal *rmin, integer *emax,
  300. doublereal *rmax)
  301. {
  302. /* Initialized data */
  303. static logical first = TRUE_;
  304. static logical iwarn = FALSE_;
  305. /* Format strings */
  306. static char fmt_9999[] = "(//\002 WARNING. The value EMIN may be incorre"
  307. "ct:-\002,\002 EMIN = \002,i8,/\002 If, after inspection, the va"
  308. "lue EMIN looks\002,\002 acceptable please comment out \002,/\002"
  309. " the IF block as marked within the code of routine\002,\002 DLAM"
  310. "C2,\002,/\002 otherwise supply EMIN explicitly.\002,/)";
  311. /* System generated locals */
  312. integer i__1;
  313. doublereal d__1, d__2, d__3, d__4, d__5;
  314. /* Builtin functions */
  315. double pow_di(doublereal *, integer *);
  316. integer s_wsfe(cilist *), do_fio(integer *, char *, ftnlen), e_wsfe(void);
  317. /* Local variables */
  318. doublereal a, b, c__;
  319. integer i__;
  320. static integer lt;
  321. doublereal one, two;
  322. logical ieee;
  323. doublereal half;
  324. logical lrnd;
  325. static doublereal leps;
  326. doublereal zero;
  327. static integer lbeta;
  328. doublereal rbase;
  329. static integer lemin, lemax;
  330. integer gnmin;
  331. doublereal small;
  332. integer gpmin;
  333. doublereal third;
  334. static doublereal lrmin, lrmax;
  335. doublereal sixth;
  336. extern /* Subroutine */ int _starpu_dlamc1_(integer *, integer *, logical *,
  337. logical *);
  338. extern doublereal _starpu_dlamc3_(doublereal *, doublereal *);
  339. logical lieee1;
  340. extern /* Subroutine */ int _starpu_dlamc4_(integer *, doublereal *, integer *),
  341. _starpu_dlamc5_(integer *, integer *, integer *, logical *, integer *,
  342. doublereal *);
  343. integer ngnmin, ngpmin;
  344. /* Fortran I/O blocks */
  345. static cilist io___58 = { 0, 6, 0, fmt_9999, 0 };
  346. /* -- LAPACK auxiliary routine (version 3.2) -- */
  347. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  348. /* November 2006 */
  349. /* .. Scalar Arguments .. */
  350. /* .. */
  351. /* Purpose */
  352. /* ======= */
  353. /* DLAMC2 determines the machine parameters specified in its argument */
  354. /* list. */
  355. /* Arguments */
  356. /* ========= */
  357. /* BETA (output) INTEGER */
  358. /* The base of the machine. */
  359. /* T (output) INTEGER */
  360. /* The number of ( BETA ) digits in the mantissa. */
  361. /* RND (output) LOGICAL */
  362. /* Specifies whether proper rounding ( RND = .TRUE. ) or */
  363. /* chopping ( RND = .FALSE. ) occurs in addition. This may not */
  364. /* be a reliable guide to the way in which the machine performs */
  365. /* its arithmetic. */
  366. /* EPS (output) DOUBLE PRECISION */
  367. /* The smallest positive number such that */
  368. /* fl( 1.0 - EPS ) .LT. 1.0, */
  369. /* where fl denotes the computed value. */
  370. /* EMIN (output) INTEGER */
  371. /* The minimum exponent before (gradual) underflow occurs. */
  372. /* RMIN (output) DOUBLE PRECISION */
  373. /* The smallest normalized number for the machine, given by */
  374. /* BASE**( EMIN - 1 ), where BASE is the floating point value */
  375. /* of BETA. */
  376. /* EMAX (output) INTEGER */
  377. /* The maximum exponent before overflow occurs. */
  378. /* RMAX (output) DOUBLE PRECISION */
  379. /* The largest positive number for the machine, given by */
  380. /* BASE**EMAX * ( 1 - EPS ), where BASE is the floating point */
  381. /* value of BETA. */
  382. /* Further Details */
  383. /* =============== */
  384. /* The computation of EPS is based on a routine PARANOIA by */
  385. /* W. Kahan of the University of California at Berkeley. */
  386. /* ===================================================================== */
  387. /* .. Local Scalars .. */
  388. /* .. */
  389. /* .. External Functions .. */
  390. /* .. */
  391. /* .. External Subroutines .. */
  392. /* .. */
  393. /* .. Intrinsic Functions .. */
  394. /* .. */
  395. /* .. Save statement .. */
  396. /* .. */
  397. /* .. Data statements .. */
  398. /* .. */
  399. /* .. Executable Statements .. */
  400. if (first) {
  401. zero = 0.;
  402. one = 1.;
  403. two = 2.;
  404. /* LBETA, LT, LRND, LEPS, LEMIN and LRMIN are the local values of */
  405. /* BETA, T, RND, EPS, EMIN and RMIN. */
  406. /* Throughout this routine we use the function DLAMC3 to ensure */
  407. /* that relevant values are stored and not held in registers, or */
  408. /* are not affected by optimizers. */
  409. /* DLAMC1 returns the parameters LBETA, LT, LRND and LIEEE1. */
  410. _starpu_dlamc1_(&lbeta, &lt, &lrnd, &lieee1);
  411. /* Start to find EPS. */
  412. b = (doublereal) lbeta;
  413. i__1 = -lt;
  414. a = pow_di(&b, &i__1);
  415. leps = a;
  416. /* Try some tricks to see whether or not this is the correct EPS. */
  417. b = two / 3;
  418. half = one / 2;
  419. d__1 = -half;
  420. sixth = _starpu_dlamc3_(&b, &d__1);
  421. third = _starpu_dlamc3_(&sixth, &sixth);
  422. d__1 = -half;
  423. b = _starpu_dlamc3_(&third, &d__1);
  424. b = _starpu_dlamc3_(&b, &sixth);
  425. b = abs(b);
  426. if (b < leps) {
  427. b = leps;
  428. }
  429. leps = 1.;
  430. /* + WHILE( ( LEPS.GT.B ).AND.( B.GT.ZERO ) )LOOP */
  431. L10:
  432. if (leps > b && b > zero) {
  433. leps = b;
  434. d__1 = half * leps;
  435. /* Computing 5th power */
  436. d__3 = two, d__4 = d__3, d__3 *= d__3;
  437. /* Computing 2nd power */
  438. d__5 = leps;
  439. d__2 = d__4 * (d__3 * d__3) * (d__5 * d__5);
  440. c__ = _starpu_dlamc3_(&d__1, &d__2);
  441. d__1 = -c__;
  442. c__ = _starpu_dlamc3_(&half, &d__1);
  443. b = _starpu_dlamc3_(&half, &c__);
  444. d__1 = -b;
  445. c__ = _starpu_dlamc3_(&half, &d__1);
  446. b = _starpu_dlamc3_(&half, &c__);
  447. goto L10;
  448. }
  449. /* + END WHILE */
  450. if (a < leps) {
  451. leps = a;
  452. }
  453. /* Computation of EPS complete. */
  454. /* Now find EMIN. Let A = + or - 1, and + or - (1 + BASE**(-3)). */
  455. /* Keep dividing A by BETA until (gradual) underflow occurs. This */
  456. /* is detected when we cannot recover the previous A. */
  457. rbase = one / lbeta;
  458. small = one;
  459. for (i__ = 1; i__ <= 3; ++i__) {
  460. d__1 = small * rbase;
  461. small = _starpu_dlamc3_(&d__1, &zero);
  462. /* L20: */
  463. }
  464. a = _starpu_dlamc3_(&one, &small);
  465. _starpu_dlamc4_(&ngpmin, &one, &lbeta);
  466. d__1 = -one;
  467. _starpu_dlamc4_(&ngnmin, &d__1, &lbeta);
  468. _starpu_dlamc4_(&gpmin, &a, &lbeta);
  469. d__1 = -a;
  470. _starpu_dlamc4_(&gnmin, &d__1, &lbeta);
  471. ieee = FALSE_;
  472. if (ngpmin == ngnmin && gpmin == gnmin) {
  473. if (ngpmin == gpmin) {
  474. lemin = ngpmin;
  475. /* ( Non twos-complement machines, no gradual underflow; */
  476. /* e.g., VAX ) */
  477. } else if (gpmin - ngpmin == 3) {
  478. lemin = ngpmin - 1 + lt;
  479. ieee = TRUE_;
  480. /* ( Non twos-complement machines, with gradual underflow; */
  481. /* e.g., IEEE standard followers ) */
  482. } else {
  483. lemin = min(ngpmin,gpmin);
  484. /* ( A guess; no known machine ) */
  485. iwarn = TRUE_;
  486. }
  487. } else if (ngpmin == gpmin && ngnmin == gnmin) {
  488. if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1) {
  489. lemin = max(ngpmin,ngnmin);
  490. /* ( Twos-complement machines, no gradual underflow; */
  491. /* e.g., CYBER 205 ) */
  492. } else {
  493. lemin = min(ngpmin,ngnmin);
  494. /* ( A guess; no known machine ) */
  495. iwarn = TRUE_;
  496. }
  497. } else if ((i__1 = ngpmin - ngnmin, abs(i__1)) == 1 && gpmin == gnmin)
  498. {
  499. if (gpmin - min(ngpmin,ngnmin) == 3) {
  500. lemin = max(ngpmin,ngnmin) - 1 + lt;
  501. /* ( Twos-complement machines with gradual underflow; */
  502. /* no known machine ) */
  503. } else {
  504. lemin = min(ngpmin,ngnmin);
  505. /* ( A guess; no known machine ) */
  506. iwarn = TRUE_;
  507. }
  508. } else {
  509. /* Computing MIN */
  510. i__1 = min(ngpmin,ngnmin), i__1 = min(i__1,gpmin);
  511. lemin = min(i__1,gnmin);
  512. /* ( A guess; no known machine ) */
  513. iwarn = TRUE_;
  514. }
  515. first = FALSE_;
  516. /* ** */
  517. /* Comment out this if block if EMIN is ok */
  518. if (iwarn) {
  519. first = TRUE_;
  520. s_wsfe(&io___58);
  521. do_fio(&c__1, (char *)&lemin, (ftnlen)sizeof(integer));
  522. e_wsfe();
  523. }
  524. /* ** */
  525. /* Assume IEEE arithmetic if we found denormalised numbers above, */
  526. /* or if arithmetic seems to round in the IEEE style, determined */
  527. /* in routine DLAMC1. A true IEEE machine should have both things */
  528. /* true; however, faulty machines may have one or the other. */
  529. ieee = ieee || lieee1;
  530. /* Compute RMIN by successive division by BETA. We could compute */
  531. /* RMIN as BASE**( EMIN - 1 ), but some machines underflow during */
  532. /* this computation. */
  533. lrmin = 1.;
  534. i__1 = 1 - lemin;
  535. for (i__ = 1; i__ <= i__1; ++i__) {
  536. d__1 = lrmin * rbase;
  537. lrmin = _starpu_dlamc3_(&d__1, &zero);
  538. /* L30: */
  539. }
  540. /* Finally, call DLAMC5 to compute EMAX and RMAX. */
  541. _starpu_dlamc5_(&lbeta, &lt, &lemin, &ieee, &lemax, &lrmax);
  542. }
  543. *beta = lbeta;
  544. *t = lt;
  545. *rnd = lrnd;
  546. *eps = leps;
  547. *emin = lemin;
  548. *rmin = lrmin;
  549. *emax = lemax;
  550. *rmax = lrmax;
  551. return 0;
  552. /* End of DLAMC2 */
  553. } /* _starpu_dlamc2_ */
  554. /* *********************************************************************** */
  555. doublereal _starpu_dlamc3_(doublereal *a, doublereal *b)
  556. {
  557. /* System generated locals */
  558. doublereal ret_val;
  559. /* -- LAPACK auxiliary routine (version 3.2) -- */
  560. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  561. /* November 2006 */
  562. /* .. Scalar Arguments .. */
  563. /* .. */
  564. /* Purpose */
  565. /* ======= */
  566. /* DLAMC3 is intended to force A and B to be stored prior to doing */
  567. /* the addition of A and B , for use in situations where optimizers */
  568. /* might hold one of these in a register. */
  569. /* Arguments */
  570. /* ========= */
  571. /* A (input) DOUBLE PRECISION */
  572. /* B (input) DOUBLE PRECISION */
  573. /* The values A and B. */
  574. /* ===================================================================== */
  575. /* .. Executable Statements .. */
  576. ret_val = *a + *b;
  577. return ret_val;
  578. /* End of DLAMC3 */
  579. } /* _starpu_dlamc3_ */
  580. /* *********************************************************************** */
  581. /* Subroutine */ int _starpu_dlamc4_(integer *emin, doublereal *start, integer *base)
  582. {
  583. /* System generated locals */
  584. integer i__1;
  585. doublereal d__1;
  586. /* Local variables */
  587. doublereal a;
  588. integer i__;
  589. doublereal b1, b2, c1, c2, d1, d2, one, zero, rbase;
  590. extern doublereal _starpu_dlamc3_(doublereal *, doublereal *);
  591. /* -- LAPACK auxiliary routine (version 3.2) -- */
  592. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  593. /* November 2006 */
  594. /* .. Scalar Arguments .. */
  595. /* .. */
  596. /* Purpose */
  597. /* ======= */
  598. /* DLAMC4 is a service routine for DLAMC2. */
  599. /* Arguments */
  600. /* ========= */
  601. /* EMIN (output) INTEGER */
  602. /* The minimum exponent before (gradual) underflow, computed by */
  603. /* setting A = START and dividing by BASE until the previous A */
  604. /* can not be recovered. */
  605. /* START (input) DOUBLE PRECISION */
  606. /* The starting point for determining EMIN. */
  607. /* BASE (input) INTEGER */
  608. /* The base of the machine. */
  609. /* ===================================================================== */
  610. /* .. Local Scalars .. */
  611. /* .. */
  612. /* .. External Functions .. */
  613. /* .. */
  614. /* .. Executable Statements .. */
  615. a = *start;
  616. one = 1.;
  617. rbase = one / *base;
  618. zero = 0.;
  619. *emin = 1;
  620. d__1 = a * rbase;
  621. b1 = _starpu_dlamc3_(&d__1, &zero);
  622. c1 = a;
  623. c2 = a;
  624. d1 = a;
  625. d2 = a;
  626. /* + WHILE( ( C1.EQ.A ).AND.( C2.EQ.A ).AND. */
  627. /* $ ( D1.EQ.A ).AND.( D2.EQ.A ) )LOOP */
  628. L10:
  629. if (c1 == a && c2 == a && d1 == a && d2 == a) {
  630. --(*emin);
  631. a = b1;
  632. d__1 = a / *base;
  633. b1 = _starpu_dlamc3_(&d__1, &zero);
  634. d__1 = b1 * *base;
  635. c1 = _starpu_dlamc3_(&d__1, &zero);
  636. d1 = zero;
  637. i__1 = *base;
  638. for (i__ = 1; i__ <= i__1; ++i__) {
  639. d1 += b1;
  640. /* L20: */
  641. }
  642. d__1 = a * rbase;
  643. b2 = _starpu_dlamc3_(&d__1, &zero);
  644. d__1 = b2 / rbase;
  645. c2 = _starpu_dlamc3_(&d__1, &zero);
  646. d2 = zero;
  647. i__1 = *base;
  648. for (i__ = 1; i__ <= i__1; ++i__) {
  649. d2 += b2;
  650. /* L30: */
  651. }
  652. goto L10;
  653. }
  654. /* + END WHILE */
  655. return 0;
  656. /* End of DLAMC4 */
  657. } /* _starpu_dlamc4_ */
  658. /* *********************************************************************** */
  659. /* Subroutine */ int _starpu_dlamc5_(integer *beta, integer *p, integer *emin,
  660. logical *ieee, integer *emax, doublereal *rmax)
  661. {
  662. /* System generated locals */
  663. integer i__1;
  664. doublereal d__1;
  665. /* Local variables */
  666. integer i__;
  667. doublereal y, z__;
  668. integer try__, lexp;
  669. doublereal oldy;
  670. integer uexp, nbits;
  671. extern doublereal _starpu_dlamc3_(doublereal *, doublereal *);
  672. doublereal recbas;
  673. integer exbits, expsum;
  674. /* -- LAPACK auxiliary routine (version 3.2) -- */
  675. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  676. /* November 2006 */
  677. /* .. Scalar Arguments .. */
  678. /* .. */
  679. /* Purpose */
  680. /* ======= */
  681. /* DLAMC5 attempts to compute RMAX, the largest machine floating-point */
  682. /* number, without overflow. It assumes that EMAX + abs(EMIN) sum */
  683. /* approximately to a power of 2. It will fail on machines where this */
  684. /* assumption does not hold, for example, the Cyber 205 (EMIN = -28625, */
  685. /* EMAX = 28718). It will also fail if the value supplied for EMIN is */
  686. /* too large (i.e. too close to zero), probably with overflow. */
  687. /* Arguments */
  688. /* ========= */
  689. /* BETA (input) INTEGER */
  690. /* The base of floating-point arithmetic. */
  691. /* P (input) INTEGER */
  692. /* The number of base BETA digits in the mantissa of a */
  693. /* floating-point value. */
  694. /* EMIN (input) INTEGER */
  695. /* The minimum exponent before (gradual) underflow. */
  696. /* IEEE (input) LOGICAL */
  697. /* A logical flag specifying whether or not the arithmetic */
  698. /* system is thought to comply with the IEEE standard. */
  699. /* EMAX (output) INTEGER */
  700. /* The largest exponent before overflow */
  701. /* RMAX (output) DOUBLE PRECISION */
  702. /* The largest machine floating-point number. */
  703. /* ===================================================================== */
  704. /* .. Parameters .. */
  705. /* .. */
  706. /* .. Local Scalars .. */
  707. /* .. */
  708. /* .. External Functions .. */
  709. /* .. */
  710. /* .. Intrinsic Functions .. */
  711. /* .. */
  712. /* .. Executable Statements .. */
  713. /* First compute LEXP and UEXP, two powers of 2 that bound */
  714. /* abs(EMIN). We then assume that EMAX + abs(EMIN) will sum */
  715. /* approximately to the bound that is closest to abs(EMIN). */
  716. /* (EMAX is the exponent of the required number RMAX). */
  717. lexp = 1;
  718. exbits = 1;
  719. L10:
  720. try__ = lexp << 1;
  721. if (try__ <= -(*emin)) {
  722. lexp = try__;
  723. ++exbits;
  724. goto L10;
  725. }
  726. if (lexp == -(*emin)) {
  727. uexp = lexp;
  728. } else {
  729. uexp = try__;
  730. ++exbits;
  731. }
  732. /* Now -LEXP is less than or equal to EMIN, and -UEXP is greater */
  733. /* than or equal to EMIN. EXBITS is the number of bits needed to */
  734. /* store the exponent. */
  735. if (uexp + *emin > -lexp - *emin) {
  736. expsum = lexp << 1;
  737. } else {
  738. expsum = uexp << 1;
  739. }
  740. /* EXPSUM is the exponent range, approximately equal to */
  741. /* EMAX - EMIN + 1 . */
  742. *emax = expsum + *emin - 1;
  743. nbits = exbits + 1 + *p;
  744. /* NBITS is the total number of bits needed to store a */
  745. /* floating-point number. */
  746. if (nbits % 2 == 1 && *beta == 2) {
  747. /* Either there are an odd number of bits used to store a */
  748. /* floating-point number, which is unlikely, or some bits are */
  749. /* not used in the representation of numbers, which is possible, */
  750. /* (e.g. Cray machines) or the mantissa has an implicit bit, */
  751. /* (e.g. IEEE machines, Dec Vax machines), which is perhaps the */
  752. /* most likely. We have to assume the last alternative. */
  753. /* If this is true, then we need to reduce EMAX by one because */
  754. /* there must be some way of representing zero in an implicit-bit */
  755. /* system. On machines like Cray, we are reducing EMAX by one */
  756. /* unnecessarily. */
  757. --(*emax);
  758. }
  759. if (*ieee) {
  760. /* Assume we are on an IEEE machine which reserves one exponent */
  761. /* for infinity and NaN. */
  762. --(*emax);
  763. }
  764. /* Now create RMAX, the largest machine number, which should */
  765. /* be equal to (1.0 - BETA**(-P)) * BETA**EMAX . */
  766. /* First compute 1.0 - BETA**(-P), being careful that the */
  767. /* result is less than 1.0 . */
  768. recbas = 1. / *beta;
  769. z__ = *beta - 1.;
  770. y = 0.;
  771. i__1 = *p;
  772. for (i__ = 1; i__ <= i__1; ++i__) {
  773. z__ *= recbas;
  774. if (y < 1.) {
  775. oldy = y;
  776. }
  777. y = _starpu_dlamc3_(&y, &z__);
  778. /* L20: */
  779. }
  780. if (y >= 1.) {
  781. y = oldy;
  782. }
  783. /* Now multiply by BETA**EMAX to get RMAX. */
  784. i__1 = *emax;
  785. for (i__ = 1; i__ <= i__1; ++i__) {
  786. d__1 = y * *beta;
  787. y = _starpu_dlamc3_(&d__1, &c_b32);
  788. /* L30: */
  789. }
  790. *rmax = y;
  791. return 0;
  792. /* End of DLAMC5 */
  793. } /* _starpu_dlamc5_ */