Skip to content
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

Special handling for NaN #8

Open
CanadaHonk opened this issue Oct 10, 2024 · 6 comments
Open

Special handling for NaN #8

CanadaHonk opened this issue Oct 10, 2024 · 6 comments

Comments

@CanadaHonk
Copy link
Owner

Not sure on details but it will likely have to be specially handled, as it should be rejected in modern proposals: https://github.com/tc39/how-we-work/blob/main/normative-conventions.md#number-taking-inputs-should-reject-nan

@Richienb
Copy link
Collaborator

Richienb commented Oct 10, 2024

We could replace this: https://github.com/Richienb/proposal-math-clamp/blob/fbf4b5a1173996cfc896ebdcd6c6a3e747d79e29/spec.html#L18C6-L18C54
with If _max_ is neither *undefined*, *null* nor *NaN*, then
and do something similar for min

If an argument to a built-in function is expected to be a non-NaN Number

I don't think the rule applies to us because we intentionally define NaN as "no bound"

@ljharb
Copy link

ljharb commented Oct 10, 2024

  • if the value is NaN, either throw, or return NaN (i prefer "return NaN", and i think that convention doesn't necessarily constrain us here)
  • if the lower bound is NaN, throw
  • if the upper bound is NaN, throw

@CanadaHonk
Copy link
Owner Author

Fixed in 513523e

@CanadaHonk
Copy link
Owner Author

Reopening to allow for discussion

@CanadaHonk CanadaHonk reopened this Oct 10, 2024
@theScottyJam
Copy link

if the value is NaN, either throw, or return NaN (i prefer "return NaN", and i think that convention doesn't necessarily constrain us here)

I would prefer for this to throw - but that's mostly because I wish that all operations that currently return NaN would throw instead - NaN is, after all, nothing more than a way to represent an error in a calculation, and I would rather that errors throw earlier instead of causing weird bugs later.

In practice, from my understanding, it's better for operators such as division to return NaN instead of throwing an error simply because it's more performant that way (at least, that's what I've heard). But I don't know if the same argument applies to a clamping function - especially if we're considering it to throw when other arguments are NaN..

@ljharb
Copy link

ljharb commented Oct 11, 2024

I think that there's definitely a potential for Math.clamp to be used in a hot path along with other math operations, which would mean that the code already has to guard against NaN, so there's no added hazard here from it.

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

No branches or pull requests

4 participants