summaryrefslogtreecommitdiffstats
path: root/generic/tclUtil.c
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2005-10-08 14:42:44 (GMT)
committerdgp <dgp@users.sourceforge.net>2005-10-08 14:42:44 (GMT)
commit76faac0f28fe9661f23ff9e35f44df1d899420e5 (patch)
tree7e3de1d0523d70328cfd81d9864b897058823d34 /generic/tclUtil.c
parent98a6fcad96289a40b501fbd2095387a245fd804d (diff)
downloadtcl-76faac0f28fe9661f23ff9e35f44df1d899420e5.zip
tcl-76faac0f28fe9661f23ff9e35f44df1d899420e5.tar.gz
tcl-76faac0f28fe9661f23ff9e35f44df1d899420e5.tar.bz2
TIP#237 IMPLEMENTATION
[kennykb-numerics-branch] Resynchronized with the HEAD; at this checkpoint [-rkennykb-numerics-branch-20051008], the HEAD and kennykb-numerics-branch contain identical code.
Diffstat (limited to 'generic/tclUtil.c')
-rw-r--r--generic/tclUtil.c86
1 files changed, 62 insertions, 24 deletions
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 1dd6fcb..7e9e35a 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUtil.c,v 1.65 2005/09/15 16:40:02 dgp Exp $
+ * RCS: @(#) $Id: tclUtil.c,v 1.66 2005/10/08 14:42:45 dgp Exp $
*/
#include "tclInt.h"
@@ -19,26 +19,6 @@
#include <math.h>
/*
- * Define test for NaN
- */
-
-#ifdef _MSC_VER
-#define IS_NAN(f) (_isnan((f)))
-#else
-#define IS_NAN(f) ((f) != (f))
-#endif
-
-/*
- * Define test for Inf
- */
-
-#ifdef _MSC_VER
-#define IS_INF(f) ( ! (_finite((f))))
-#else
-#define IS_INF(f) ( (f) > DBL_MAX || (f) < -DBL_MAX )
-#endif
-
-/*
* The absolute pathname of the executable in which this Tcl library
* is running.
*/
@@ -87,6 +67,8 @@ static void FreeProcessGlobalValue _ANSI_ARGS_((
ClientData clientData));
static void FreeThreadHash _ANSI_ARGS_((ClientData clientData));
static Tcl_HashTable * GetThreadHash _ANSI_ARGS_((Tcl_ThreadDataKey *keyPtr));
+static int ParseInteger _ANSI_ARGS_((CONST char *bytes,
+ int numBytes));
static int SetEndOffsetFromAny _ANSI_ARGS_((Tcl_Interp* interp,
Tcl_Obj* objPtr));
static void UpdateStringOfEndOffset _ANSI_ARGS_((Tcl_Obj* objPtr));
@@ -1906,7 +1888,7 @@ Tcl_PrintDouble(interp, value, dst)
* Handle NaN.
*/
- if (IS_NAN(value)) {
+ if (TclIsNaN(value)) {
TclFormatNaN(value, dst);
return;
}
@@ -1915,7 +1897,7 @@ Tcl_PrintDouble(interp, value, dst)
* Handle infinities.
*/
- if (IS_INF(value)) {
+ if (TclIsInfinite(value)) {
if (value < 0) {
strcpy(dst, "-Inf");
} else {
@@ -2175,6 +2157,7 @@ TclNeedSpace(start, end)
}
return 1;
}
+#if 0
/*
*----------------------------------------------------------------------
@@ -2228,6 +2211,61 @@ TclLooksLikeInt(bytes, length)
return (0 != TclParseInteger(p, length));
}
+#endif
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * ParseInteger --
+ *
+ * Scans up to numBytes bytes starting at bytes, and checks whether the
+ * leading bytes look like an integer's string representation.
+ *
+ * Results:
+ * Returns 0 if the leading bytes do not look like an integer.
+ * Otherwise, returns the number of bytes examined that look like an
+ * integer. This may be less than numBytes if the integer is only the
+ * leading part of the string.
+ *
+ * Side effects:
+ * None.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static int
+ParseInteger(bytes, numBytes)
+ CONST char *bytes; /* The string to examine. */
+ int numBytes; /* Max number of bytes to scan. */
+{
+ register CONST char *p = bytes;
+
+ /* Take care of introductory "0x". */
+ if ((numBytes > 1) && (p[0] == '0') && ((p[1] == 'x') || (p[1] == 'X'))) {
+ int scanned;
+ Tcl_UniChar ch;
+
+ p += 2;
+ numBytes -= 2;
+ scanned = TclParseHex(p, numBytes, &ch);
+ if (scanned) {
+ return scanned+2;
+ }
+
+ /* Recognize the 0 as valid integer, but x is left behind. */
+ return 1;
+ }
+ while (numBytes && isdigit(UCHAR(*p))) { /* INTL: digit */
+ numBytes--; p++;
+ }
+ if (numBytes == 0) {
+ return (p - bytes);
+ }
+ if ((*p != '.') && (*p != 'e') && (*p != 'E')) {
+ return (p - bytes);
+ }
+ return 0;
+}
/*
*----------------------------------------------------------------------
@@ -2291,7 +2329,7 @@ TclGetIntForIndex(interp, objPtr, endValue, indexPtr)
if ((*p == '+') || (*p == '-')) {
p++; length--;
}
- opIdx = TclParseInteger(p, length) + (int) (p-bytes);
+ opIdx = ParseInteger(p, length) + (int) (p-bytes);
if (opIdx) {
int code, first, second;
char savedOp = bytes[opIdx];