Skip to content

Simplify Math.signbit. Don't ignore sign bit for NaNs #1467

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

Merged
merged 2 commits into from
Sep 25, 2020
Merged

Simplify Math.signbit. Don't ignore sign bit for NaNs #1467

merged 2 commits into from
Sep 25, 2020

Conversation

MaxGraey
Copy link
Member

I don't think we should ignore sign for NaNs due to signed -NaN is actually valid and canonical.

  • I've read the contributing guidelines

@dcodeIO
Copy link
Member

dcodeIO commented Sep 18, 2020

Does this align with https://github.com/tc39/proposal-Math.signbit?

@MaxGraey
Copy link
Member Author

Does this align with https://github.com/tc39/proposal-Math.signbit?

proposal-Math.signbit doesn't specify this. But anyway that proposal on Stage 1 and I don't think it will be move forward in near future. Other implrmrntation in different languages use simply NaN-agnostic version so I suggest follow the same way

@dcodeIO
Copy link
Member

dcodeIO commented Sep 18, 2020

My thinking is mostly that the introduction of Math.signbit is based upon exactly that proposal, so I think it should do exactly what is proposed. Code relying on different semantics has better options in AS anyway and does not necessarily have to use that function.

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 18, 2020

That proposal is not standard and nobody except me it seems interested to move that proposal forward. Anyway even if AS implementation will be slightly different I don't think it broke any code now and in future. First of all signed nans is really rare case, also I don't think somebody will build his logic around sign / non-sign NaNs=) Also proposed behaviour align with other languages which not exclude sign NaNs and just extract sign bit

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 18, 2020

But I'm ok to leave old behaviour (and close this PR) as more JavaScript way which prefer don't distinguish NaN sign)

@dcodeIO
Copy link
Member

dcodeIO commented Sep 18, 2020

Is an interesting situation. Like, the motivation to propose it for JS is that there is no good alternative, and NaN canonicalization is merely a side-effect. Our motivation, however, is to provide it for compatibility with JS, but we don't really do NaN canonicalization. Now, users probably won't care about NaN canonicalization that much, they just want the sign bit. In turn, the question relevant to us becomes "what is the sign of NaN?" independently of canonicalization, leading us here. Interesting.

@dcodeIO
Copy link
Member

dcodeIO commented Sep 18, 2020

The radical but also most straight-forward solution here is to document that "AssemblyScript doesn't do NaN canonicalization", then merging this PR. So, slightly in favor of making this change. Can you add a new comment?

@MaxGraey
Copy link
Member Author

For example Object.is(NaN, -NaN) will return false as expected, so Math.signbit with this changes will be only one way to figure outing sign of NaN without bit manipulations

@MaxGraey
Copy link
Member Author

MaxGraey commented Sep 18, 2020

AssemblyScript doesn't do NaN canonicalization

It's not formally correct due to -NaN also canonical and propagated "as is". This also became a discovery for me recently) So perhaps it could be AssemblyScript implementation sensitive to NaN sign which may differ to https://github.com/tc39/proposal-Math.signbit

@dcodeIO dcodeIO merged commit 9948f41 into AssemblyScript:master Sep 25, 2020
@github-actions
Copy link

🎉 This PR is included in version 0.14.12 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants