Module Name: src
Committed By: christos
Date: Tue Sep 1 00:21:02 UTC 2020
Modified Files:
src/external/historical/nawk/dist: tran.c
Log Message:
check explicitly for inf and nan. We can't check if it is a number,
because awk parses 1a as 1...
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/external/historical/nawk/dist/tran.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/external/historical/nawk/dist/tran.c
diff -u src/external/historical/nawk/dist/tran.c:1.12 src/external/historical/nawk/dist/tran.c:1.13
--- src/external/historical/nawk/dist/tran.c:1.12 Mon Aug 31 19:36:58 2020
+++ src/external/historical/nawk/dist/tran.c Mon Aug 31 20:21:01 2020
@@ -395,6 +395,25 @@ char *setsval(Cell *vp, const char *s) /
return(vp->sval);
}
+static int checkstr(const char *s, const char *v)
+{
+ while (*s && tolower((unsigned char)*s) == *v)
+ s++, v++;
+ return !(*s || *v);
+}
+
+static int checkinfnan(const char *s)
+{
+ switch (tolower((unsigned char)*s)) {
+ case 'i':
+ return checkstr(s, "inf") || checkstr(s, "infinity");
+ case 'n':
+ return checkstr(s, "nan");
+ default:
+ return 1;
+ }
+}
+
Awkfloat getfval(Cell *vp) /* get float val of a Cell */
{
if ((vp->tval & (NUM | STR)) == 0)
@@ -404,11 +423,10 @@ Awkfloat getfval(Cell *vp) /* get float
else if (isrec(vp) && !donerec)
recbld();
if (!isnum(vp)) { /* not a number */
- if (is_number(vp->sval) && !(vp->tval&CON)) {
+ if (checkinfnan(vp->sval))
vp->fval = atof(vp->sval); /* best guess */
+ if (is_number(vp->sval) && !(vp->tval&CON)) {
vp->tval |= NUM; /* make NUM only sparingly */
- } else {
- vp->fval = 0;
}
}
dprintf( ("getfval %p: %s = %g, t=%o\n",