Skip to content

[css-values] Behavior of NaN in pow()/hypot() #4161

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

Closed
tabatkins opened this issue Jul 30, 2019 · 3 comments
Closed

[css-values] Behavior of NaN in pow()/hypot() #4161

tabatkins opened this issue Jul 30, 2019 · 3 comments
Labels
css-values-4 Current Work

Comments

@tabatkins
Copy link
Member

While fixing #4158, I stumbled across the fact that Math.hypot(Infinity, NaN) yields Infinity, and Math.pow(NaN, 0) yields 1 (both in spec and impl). These are the only two cases in the math functions I could find where NaN wasn't "infectious".

Do we want to carry this behavior along to CSS? Should we specify that NaN is specially handled in these functions? Or perhaps officially undefine it, allowing either "infectious" or "JS" behavior as valid?

@tabatkins tabatkins added the css-values-4 Current Work label Jul 30, 2019
@Loirooriol
Copy link
Contributor

IMO the infectious behavior makes sense if when replacing each NaN argument with a variable (over non-NaN numbers), the resulting function is not constant.

But here hypot(+∞, x) must be +∞ no matter what x is, and pow(x, 0) must be 1. So extending this for NaN doesn't seem unreasonable. Though max(+∞, NaN) = NaN, so it's not much consistent.

@tabatkins
Copy link
Member Author

Right, that's clearly the logic being used here; replacing NaN with any number wont' change the result.

But yeah, max() and min() are fully infectious both in CSS and JS, so they're not consistent with the reasoning, sigh.

I'm thinking I'll just stick with infectious NaN, and call it out as an intentional divergence.

@Crissov
Copy link
Contributor

Crissov commented Jul 30, 2019

Internal consistency seems more important than external compatibility indeed, so, in CSS, NaN needs to be infectious either always or never (if treatable).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
css-values-4 Current Work
Projects
None yet
Development

No branches or pull requests

3 participants