summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2002-07-22 10:04:16 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2002-07-22 10:04:16 (GMT)
commit27070d54f1091210791f5ec8bd0c2474b5531f6d (patch)
tree62adfb7d97aee2eeba07efd96276ecdbc71c51fd /generic
parent6a00bb0ff05f01579f3976bc1ea44902d455f9d7 (diff)
downloadtcl-27070d54f1091210791f5ec8bd0c2474b5531f6d.zip
tcl-27070d54f1091210791f5ec8bd0c2474b5531f6d.tar.gz
tcl-27070d54f1091210791f5ec8bd0c2474b5531f6d.tar.bz2
Allowed parser to recognise 'Inf' as a floating-point number. [Bug 218000]
Also produce better error messages when this happens.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclExecute.c21
-rw-r--r--generic/tclParseExpr.c5
2 files changed, 22 insertions, 4 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index b8d1817..c2e467e 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.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: tclExecute.c,v 1.80 2002/07/19 12:31:09 dkf Exp $
+ * RCS: @(#) $Id: tclExecute.c,v 1.81 2002/07/22 10:04:17 dkf Exp $
*/
#include "tclInt.h"
@@ -3160,7 +3160,7 @@ TclExecuteByteCode(interp, codePtr)
if ((t1Ptr == &tclDoubleType) || (t2Ptr == &tclDoubleType)) {
/*
* Do double arithmetic.
- */
+ */
doDouble = 1;
if (t1Ptr == &tclIntType) {
d1 = i; /* promote value 1 to double */
@@ -4457,6 +4457,22 @@ IllegalExprOperandType(interp, pc, opndPtr)
int length;
s = Tcl_GetStringFromObj(opndPtr, &length);
+ /*
+ * strtod() isn't particularly consistent about detecting Inf
+ * and NaN between platforms.
+ */
+ if (length == 3) {
+ if ((s[0]=='n' || s[0]=='N') && (s[1]=='a' || s[1]=='A') &&
+ (s[2]=='n' || s[2]=='N')) {
+ msg = "non-numeric floating-point value";
+ goto makeErrorMessage;
+ }
+ if ((s[0]=='i' || s[0]=='I') && (s[1]=='n' || s[1]=='N') &&
+ (s[2]=='f' || s[2]=='F')) {
+ msg = "infinite floating-point value";
+ goto makeErrorMessage;
+ }
+ }
if (TclLooksLikeInt(s, length)) {
/*
* If something that looks like an integer appears here, then
@@ -4482,6 +4498,7 @@ IllegalExprOperandType(interp, pc, opndPtr)
msg = "floating-point value";
}
}
+ makeErrorMessage:
Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), "can't use ",
msg, " as operand of \"", operatorStrings[opCode - INST_LOR],
"\"", (char *) NULL);
diff --git a/generic/tclParseExpr.c b/generic/tclParseExpr.c
index 6d1fc30..1c6a5f5 100644
--- a/generic/tclParseExpr.c
+++ b/generic/tclParseExpr.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclParseExpr.c,v 1.13 2002/06/21 21:17:39 jenglish Exp $
+ * RCS: @(#) $Id: tclParseExpr.c,v 1.14 2002/07/22 10:04:17 dkf Exp $
*/
#include "tclInt.h"
@@ -1628,7 +1628,8 @@ GetLexeme(infoPtr)
return TCL_OK;
}
} else if (startsWithDigit || (c == '.')
- || (c == 'n') || (c == 'N')) {
+ || (c == 'i') || (c == 'I') /* Could be 'Inf' */
+ || (c == 'n') || (c == 'N')) { /* Could be 'NaN' */
errno = 0;
doubleValue = strtod(src, &termPtr);
if (termPtr != src) {