-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Change ToInteger(-0) to return +0? #1637
Comments
Do 402 or HTML use our ToInteger at all? |
I didn't find any occurrence of ToInteger at https://tc39.es/ecma402/ and https://html.spec.whatwg.org/. |
Don't forget to check https://heycam.github.io/webidl/, but yeah, no ToInteger there either. |
(And now the usual note: Hopefully we get one day some automatic tooling to help find downstream users resp. make it so that downstream users are notified on behavioural changes. For example yesterday some Web App manifest test was failing because I changed the result of CanonicalizeLanguageTag from ECMA-402. :-/) |
cc @syg for |
I highly doubt that changing the semantics of Editorially it seems helpful to set the precedent for future spec writers to not have to think about whether they would want to truncate -0 or not when returning integral numbers back to script. Implementation-wise both the truncation and no truncation variants of ToInteger would still be implemented, since there are call sites where the result Number can never be -0 or the sign bit pattern doesn't matter so there's no reason to emit the extra branch to truncate. And I suppose the current no-truncation behavior for All in all I think I am in favor of trying this change -- I like the mental model of methods that return some kind of integral coercion as always doing truncation. -0 isn't an integer. |
I'm also in favor of it. I'll put up a PR. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Fixes tc39#1637. This only has an observable impact on `Atomics.store`.
While working on some SpiderMonkey JIT compiler optimisations, I was wondering if it makes sense to change
ToInteger(-0)
to return+0
instead of-0
, because in all but one case, the result ofToInteger(-0)
is either explicitly or implicitly changed from-0
to+0
anyway.Example for implicit conversion from String.prototype.startsWith:
max
.And from String.prototype.charAt:
And from Array.prototype.includes:
ToString(-0) = ToString(+0) = "0"
holds.Example for explicit conversion from Array.prototype.indexOf:
Or TimeClip:
The only place where changing
ToInteger(-0)
to return+0
instead of-0
would make a difference, is Atomics.store:So, changing
ToInteger(-0)
return+0
would allow to remove some explicit-0
to+0
conversions in various operations, but also result in a noticeable change forAtomics.store
, (which we could avoid if necessary, but I'm not actually sure anyone would really notice the difference for that function when+0
instead of-0
would be returned.) Does it sound useful to anyone else to make this change?The text was updated successfully, but these errors were encountered: