-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Num.fromString(" ") returns 0 #1131
Comments
there probably should be a check to see if Lines 619 to 622 in a4ae905
|
I don't know why the string is |
Trim is user space already fwiw |
Considering how often Anyway, on the face of it, it seems (as @minirop said) that all we need to do is to check whether any part of the string has been consumed by If we do that, there should be no need to treat an empty string as a special case or to skip past any trailing whitespace. So that would give us: DEF_PRIMITIVE(num_fromString)
{
if (!validateString(vm, args[1], "Argument")) return false;
ObjString* string = AS_STRING(args[1]);
errno = 0;
char* end;
double number = strtod(string->value, &end);
if (errno == ERANGE) RETURN_ERROR("Number literal is too large.");
// Check we have consumed any part of the string. Otherwise, it contains non-number
// characters and we can't parse it.
if (end == string->value) RETURN_NULL;
RETURN_NUM(number);
} |
Some time ago, I tried removing our dependency on the standard Lines 232 to 417 in 3f5a16a
It certainly is a very extreme solution to this specific problem but thought it could be more intuitive this way and get rid of a few weird quirks of With I think the biggest issue of #984 is that the results of |
When `strtod` returns `0.0`, no conversion could have happened. Handle the error case correctly.
Yes, I remember that PR. If we introduce octal ( |
Fix null convertion in `Num::fromString` (wren-lang#1131)
Hi, I'm using wren v0.4.0 and I find
Should it be
null
?The text was updated successfully, but these errors were encountered: