-
-
Notifications
You must be signed in to change notification settings - Fork 667
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
fix: spec compliant parseInt #1378
Conversation
Iiuc, on Discord it was also reported that global Example given was assert(parseInt("this is not semantically equal to 0") == 0)
assert(parseInt("this is not semantically equal to 0") == parseInt("0")) mentioning that these asserts pass, which seems weird given that global export function parseInt(str: string, radix: i32 = 0): f64 {
return strtol<f64>(str, radix);
} |
From a quick test it seems that parseInt("") // returns NaN as expected but
parseInt("abc") // returns 0, which is strange |
In my tests See test case below |
It fix already halfbacked solution which just not properly tests. So as you suggested in discord solution: let parsedFloat = parseInt('bad input');
if(isNaN(parsedFloat)) {
// fail
} else {
// success
} Just not worked. Current PR fix this. |
Great, thanks, looks good then with the other comment above addressed :) |
This comment has been minimized.
This comment has been minimized.
Alright. It seems all cases handled properly |
This comment has been minimized.
This comment has been minimized.
🎉 This PR is included in version 0.13.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
more rejection tests
more tests which mixed different prefixes and radices
fixes edge cases for
parseInt
proper generic variants of
strtol
forF64.parseInt
andF32.parseInt
I've read the contributing guidelines