- From: Tab Atkins Jr. via GitHub <sysbot+gh@w3.org>
- Date: Mon, 11 Jul 2022 21:13:19 +0000
- To: public-css-archive@w3.org
> For example, the following are equivalent despite having completely different units. Those two are absolutely not equivalent (unless the viewport is 100px wide), and if an implementation is treating them as having the same value it's buggy, just at a basic definitional level. Looking at all the rest of your example, phew, yeah the WK implementation appears to be *completely* wrong when working with dimensions; that behavior is nonsensical. > My question: what should the behavior be when the units of the arguments are different, but the types are the same? What should happen if a calculation cannot be simplified to a single number? You resolve them as far as you can, given the value stage you're at. If you can't fully resolve the two arguments to the same canonical unit, then the function can't resolve yet, and will have to wait until later in the value pipeline. See <https://drafts.csswg.org/css-values/#calc-simplification> and <https://drafts.csswg.org/css-values/#calc-computed-value> for details - at computed value time we resolve everything as much we can, including resolving functions to their answers if possible, but if it's not yet possible then we wait for used-value time, when it's guaranteed to be possible. For example, `atan2(90px, 90vw)` is resolvable at computed-value time, since the viewport units are resolvable to px at computed-value time. Both arguments get converted to the canonical length unit - `px`, then the function is resolved accordingly. `atan2(90px, 50%)`, tho, might not be resolveable at computed-value time, depending on what property it's used in. For 'width', for example, %s don't resolve at computed-value time; they need to wait for used-value time so they can resolve against layout information. So `width: calc(100px * atan2(90px, 50%) / 360deg);` won't simplify at all at computed-value time (every unit is either in the canonical unit already, or can't be resolved), and then at used-value time will be able to simplify to a value. > Perhaps a better question: why does this function accept units at all? Why not only allow calculations that resolve to a <number> similar to some of the other math functions? Since the units aren't actually used, it just seems confusing. The units *are* used, WebKit's impl is just completely broken. atan2() takes a coordinate pair, and it's reasonable to specify a coordinate pair with dimensions, when lengths are relevant to what you're doing. For example, knowing the angle formed by moving 90px up and 90vw sideways is meaningful! > So it seems the webkit implementation is buggy then, and it would be good to add some new tests to WPT where different units are used between the arguments. Yeah, I wouldn't have imagined an implementation like this would have been reviewed in the first place, so we definitely need some tests to make sure they're definitely failing. -- GitHub Notification of comment by tabatkins Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7482#issuecomment-1180875952 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Monday, 11 July 2022 21:13:22 UTC