Skip to content

Commit

Permalink
[css-values-4] Undefine the value of tan() at the asymptotes. #8527
Browse files Browse the repository at this point in the history
  • Loading branch information
tabatkins committed Apr 6, 2023
1 parent f5dffeb commit 328ddb3
Showing 1 changed file with 49 additions and 21 deletions.
70 changes: 49 additions & 21 deletions css-values-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3425,17 +3425,55 @@ Argument Ranges</h4>

In ''tan(A)'', if A is one of the asymptote values
(such as ''90deg'', ''270deg'', etc),
the result must be +∞ for ''90deg'' and all values a multiple of ''360deg'' from that
(such as ''-270deg'' or ''450deg''),
and −∞ for ''-90deg'' and all values a multiple of ''360deg'' from that
(such as ''-450deg'' or ''270deg'').

Note: This is only relevant for units that can exactly represent the asymptotic values,
such as ''deg'' or ''grad''.
''rad'' cannot,
and so whether the result is a very large negative or positive value
can depend on rounding and precise details of how numbers are internally stored.
It's recommended you don't depend on this behavior if using such units.
the result is <strong>explicitly undefined</strong>.
If an implementation is capable of exactly representing these inputs,
it <em>should</em> return
+∞ for the asymptotes at <code>90deg + N*360deg</code>,
and −∞ for the asymptotes at <code>-90deg + N*360deg</code>,
but implementations are not required to be able to exactly represent these inputs
(and if they can't, will return whatever the correct numeric answer is
for the closest approximation to the input
they are capable of representing).
Authors <em>must not</em> rely on ''tan()'' returning any particular value
for these inputs.

<details class=note>
<summary>Why are these undefined?</summary>

The tangent function is <em>discontinuous</em> at its asymptotes:
it approaches infinity from one side
<em>and</em> negative infinity from the other side,
and isn't defined at the exact values of the asymptote.

Further, whether or not the asymptotic values
are exactly representable in implementations
depends on how they internally store and manipulate angles;
when written in degrees the values are simple (''90deg'', etc),
but in radians the values are transcendental (''pi / 2'', etc)
and cannot be exactly represented.
So, even defining a specific behavior for these values is difficult;
if an implementation uses radians internally,
it would have to do some fuzzy matching
to return the defined value
when the input is <em>sufficiently close</em> to the asymptote.

The other major language for the Web, JavaScript,
exposes these functions as taking radians only,
so it can't hit the exact asymptotes either
(and this true for most other computer languages, too).
Authors writing code in JS, then,
can't rely on any specific behavior for these values either,
and it's unlikely that their needs in CSS are significantly different.

The suggested behavior for implementations that can exactly represent the asymptote values
preserves round-tripping with the ''atan()'' function:
''tan(atan(X))'' and ''atan(tan(X))''
will both return (approximately) X
for all possible X values,
given this definition.
It also means that within the supported output range of ''atan()'',
the function is continuous.
</details>

In ''asin(A)'' or ''acos(A)'',
if A is less than -1 or greater than 1,
Expand Down Expand Up @@ -3518,16 +3556,6 @@ Argument Ranges</h4>
as implemented by most programming languages,
in particular as implemented in JS.

Note: The behavior of ''tan(90deg)'',
while not constrained by JS behavior
(because the JS function's input is in radians,
and one cannot perfectly express a value of π/2 in JS numbers),
is defined so that roundtripping of values works;
''tan(atan(infinity))'' yields +∞,
''tan(atan(-infinity))'' yields −∞,
''atan(tan(90deg))'' yields ''90deg'',
and ''atan(tan(-90deg))'' yields ''-90deg''.


<h3 id=exponent-funcs>
Exponential Functions: ''pow()'', ''sqrt()'', ''hypot()'', ''log()'', ''exp()''</h3>
Expand Down

0 comments on commit 328ddb3

Please sign in to comment.