-
Notifications
You must be signed in to change notification settings - Fork 1
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
±0 handling #14
Comments
I would indeed expect: Math.clamp(-0, 0, Infinity) // +0
Math.clamp(0, -0, Infinity) // +0, because it's greater than -0
Math.clamp(-0, -Infinity, 0) // -0, because it's less than +0
Math.clamp(0, -Infinity, -0) // -0 |
Another possible option would be to treat Which means: Math.clamp(-0, 0, Infinity) // -0, because it's the first argument
Math.clamp(0, -0, Infinity) // +0, because it's the first argument
Math.clamp(-0, -Infinity, 0) // -0, because it's the first argument
Math.clamp(0, -Infinity, -0) // -0, because it's the first argument It also means the following, by the same logic: Math.clamp(0, -0, -0); // +0
Math.clamp(0, 0, -0); // +0 This last one, |
They're not equal, though - if you divide them into 1, you get opposite signed results. |
Depends on the definition of equals. And less than. And greater than. I would personally expect That's at least my gut reaction to this. I'm going to try and see if I can come up with an actual use-case for |
Finding a real use-case for this sort of thing turns out to be really hard. But what I did find out, was that I do think it would be good to explicitly decide what the following will return: I'd assume that we'd want this behavior: Math.clamp(0, -0, -0); // => -0
Math.clamp(-0, 0, 0); // => 0 And for these, I have no idea: Math.clamp(0, 0, -0); // => ??
Math.clamp(-0, 0, -0); // => ?? |
providing an upper bound that's less than the lower bound throws a RangeError, so both would throw. |
As the current draft:
The behavior is:
I couldn't find the discussion about the behavior related to ±0, and I'm also curious about the rationale behind it.
BTW, I also suggest change the spec text to make the return value much clear:
The text was updated successfully, but these errors were encountered: