Skip to content

Commit

Permalink
Ensure Number("1A")==NaN, previously we just parsed the digits we cou…
Browse files Browse the repository at this point in the history
…ld (fix #2555)
  • Loading branch information
gfwilliams committed Sep 23, 2024
1 parent c8934a3 commit 0f3e94f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
STM32: Stay away when USB is connected, even if no app is reading
Remove Ctrl-A/D/E/U/W code handling to free up flash space (the IDE/or VT100 terminals all use escape codes)
Ensure that 1%0.0===NaN (fix #2556)
Ensure Number("1A")==NaN, previously we just parsed the digits we could (fix #2555)

2v24 : Bangle.js2: Add 'Bangle.touchRd()', 'Bangle.touchWr()'
Bangle.js2: After Bangle.showTestScreen, put Bangle.js into a hard off state (not soft off)
Expand Down
6 changes: 4 additions & 2 deletions src/jsvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2249,7 +2249,9 @@ JsVarFloat jsvGetFloat(const JsVar *v) {
if (buf[0]==0) return 0; // empty string -> 0
if (!strcmp(buf,"Infinity")) return INFINITY;
if (!strcmp(buf,"-Infinity")) return -INFINITY;
return stringToFloat(buf);
const char *endOfNumber = 0;
JsVarFloat v = stringToFloatWithRadix(buf,0,&endOfNumber);
if (*endOfNumber==0) return v; // only return the value if there wasn't something after it in the string
}
}
return NAN;
Expand All @@ -2272,7 +2274,7 @@ JsVar *jsvAsNumber(JsVar *var) {
if (jsvGetString(var, buf, sizeof(buf))==sizeof(buf)) {
jsExceptionHere(JSET_ERROR, "String too big to convert to number");
return jsvNewFromFloat(NAN);
} else
} else // jsvIsStringNumericInt=true so we're sure this'll be successful
return jsvNewFromLongInteger(stringToInt(buf));
}
// Else just try and get a float
Expand Down

0 comments on commit 0f3e94f

Please sign in to comment.