# Re: [csswg-drafts] [css-values] Consider removing asymptotic special-cases for tan() (#8527)

• From: Oriol Brufau via GitHub <sysbot+gh@w3.org>
• Date: Tue, 07 Mar 2023 17:45:26 +0000
• Message-ID: <issue_comment.created-1458580476-1678211124-sysbot+gh@w3.org>
```Context: #7441

> At the time we evaluate the tan() function the engine usually has forgotten the original specified units (we do most of the calc math in canonical units).

Precisely, `deg` is the canonical unit, so I don't see the problem. And this behavior is not some magic thing just for `deg` units, it should also happen with `tan(100grad)` or `tan(0.25turn)`.

> We already have the undefined result in the spec for radians.

But radians are fine because (from https://en.cppreference.com/w/cpp/numeric/math/tan) "no common floating-point representation is able to represent π/2 exactly, thus there is no value of the argument for which a pole error occurs" when using radians. It would make sense to undefine all units if radians were the canonical unit, but they are not.

> how every engine implements this right now implies doing maths in deg first (because that's the canonical unit)

Sounds good.

> Then convert to radians, and call `tan(<radians>)`, which does the actual tan.

Or you could use an algorithm for computing the tangent based on degrees. It's fine to have a radian-based implementation, but then before converting to radians you have to handle the special cases that won't work well in radians.

> So I guess we could convert to degrees and see if it's one of the special cases...

No, you are supposed to start from degrees which are the canonical unit, you can convert to radians as an intermediate step during calculations, but then don't convert back to degrees...

> An alternative here could be to specify some epsilon for which values very close to `pi/2`

Not opposed to that, but it should be values very close to `90deg`, since `deg` is the canonical unit. Doing the calculation in radians is an implementation detail.

--
GitHub Notification of comment by Loirooriol
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8527#issuecomment-1458580476 using your GitHub account

--
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
```

Received on Tuesday, 7 March 2023 17:45:28 UTC