Posted to tcl by kbk at Tue Sep 11 00:51:15 GMT 2007view raw

  1. Index: generic/tclExecute.c
  2. ===================================================================
  3. RCS file: /cvsroot/tcl/tcl/generic/tclExecute.c,v
  4. retrieving revision 1.333
  5. diff -u -r1.333 tclExecute.c
  6. --- generic/tclExecute.c 10 Sep 2007 21:47:21 -0000 1.333
  7. +++ generic/tclExecute.c 11 Sep 2007 00:50:27 -0000
  8. @@ -621,7 +621,8 @@
  9. * instruction tracing. */
  10. {
  11. #if (LONG_MAX > 0x7fffffff) || !defined(TCL_WIDE_INT_IS_LONG)
  12. - int i;
  13. + int i, j;
  14. + Tcl_WideInt w, x;
  15. #endif
  16. #ifdef TCL_COMPILE_DEBUG
  17. if (Tcl_LinkVar(interp, "tcl_traceExec", (char *) &tclTraceExec,
  18. @@ -634,8 +635,29 @@
  19. (ClientData) NULL, (Tcl_CmdDeleteProc *) NULL);
  20. #endif /* TCL_COMPILE_STATS */
  21. #if (LONG_MAX > 0x7fffffff) || !defined(TCL_WIDE_INT_IS_LONG)
  22. +
  23. + /*
  24. + * Fill in a table of what base can be raised to powers 2, 3, ... 16
  25. + * without overflowing a Tcl_WideInt
  26. + */
  27. for (i = 2; i <= 16; ++i) {
  28. - MaxBaseWide[i-2] = (Tcl_WideInt) pow((double) LLONG_MAX, 1.0 / i);
  29. +
  30. + /* Compute an initial guess in floating point */
  31. +
  32. + w = (Tcl_WideInt) pow((double) LLONG_MAX, 1.0 / i) + 1;
  33. +
  34. + /* Correct the guess if it's too high */
  35. +
  36. + for (;;) {
  37. + x = LLONG_MAX;
  38. + for (j = 0; j < i; ++j) {
  39. + x /= w;
  40. + }
  41. + if (x == 1) break;
  42. + --w;
  43. + }
  44. +
  45. + MaxBaseWide[i-2] = w;
  46. }
  47. #endif
  48. }