Don't try so hard to convert strings into numbers. Results in bogus

conversions like:

% awk 'BEGIN { print "nanotime" + 123 }'
nan
% awk 'BEGIN { print "microtime" + 123 }'
123
% awk 'BEGIN { print "inftime" + 123 }'
inf
This commit is contained in:
christos 2020-08-31 23:36:58 +00:00
parent fa197dbf76
commit 8871000030
1 changed files with 5 additions and 2 deletions

View File

@ -404,9 +404,12 @@ Awkfloat getfval(Cell *vp) /* get float val of a Cell */
else if (isrec(vp) && !donerec)
recbld();
if (!isnum(vp)) { /* not a number */
vp->fval = atof(vp->sval); /* best guess */
if (is_number(vp->sval) && !(vp->tval&CON))
if (is_number(vp->sval) && !(vp->tval&CON)) {
vp->fval = atof(vp->sval); /* best guess */
vp->tval |= NUM; /* make NUM only sparingly */
} else {
vp->fval = 0;
}
}
dprintf( ("getfval %p: %s = %g, t=%o\n",
(void*)vp, NN(vp->nval), vp->fval, vp->tval) );