-
Notifications
You must be signed in to change notification settings - Fork 717
[css-values] Does tan(90deg) return +∞, −∞ or NaN? #4101
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
Comments
I would argue strongly for a solution that supports round-tripping, so that And being approximately consistent with JS implementations is good, too. Even if the JS results are a side effect of numerical precision limits. |
I think it's also good to preserve So assuming
|
IMO Note that |
Ah, good point. The input to tan() can be an arbitrary angle, but the output from atan will always be restricted to the base circle. But yes, once we reverse the nesting, we still want the consistent behavior. |
Interesting question! I agree that, at minimum, tan(90deg) should equal +inf. Since JS's Math.PI slightly undershoots the precise value, it happens to be true that So at least it's consistent with naive usage of JS to say that positive angles give +inf and negative give -inf. ^_^ And then yeah, that gives you roundtripping of either nesting (within the [-90deg, 90deg] range). |
Um, I only mentioned 90deg and -90deg because I assumed we would preserve the 360deg periodicity. Sure, saying This seems strange to me:
|
Interesting. I had not realized that was a direction you might be wanting. That makes some sense, tho. |
I had also assumed that keeping a consistent behavior for all equivalent angles (mod 360deg) was implied. I know there are other places where we use a towards/away from zero rule, but for trigonometry having -90deg match 270deg (and so on) is more important. |
…acting whole turns gives the same value. #4101.
@tabatkins There is some problem with your patch, |
Ah, thanks, fixed. (It was the autolinker misfiring on the division sign, thinking it was a ''for/term'' autolink.) |
From https://drafts.csswg.org/css-values/#funcdef-tan,
But it's not clear to me what
tan(90deg)
is supposed to return. Mathematically, the limit from the left is +∞ and the limit from the right is −∞, so the limit doesn't exist. Does this mean NaN? But this case is not covered in https://drafts.csswg.org/css-values/#trig-infinities, which only saysFor the inverse functions:
So I guess this should round-trip and
tan(90deg)
should be +∞ andtan(-90deg)
be -∞?ECMAScript doesn't define this case either, but I guess it can be handwaved due to floating-point precision problems, e.g.
Math.tan(Math.PI / 2)
returns16331239353195370
because π/2 can't be stored exactly. But in CSS,deg
is the canonical unit for<angle>
, and90
is an integer, so I think there shouldn't be any precision problem.The text was updated successfully, but these errors were encountered: