- From: Christoph Päper via GitHub <sysbot+gh@w3.org>
- Date: Tue, 26 Mar 2019 11:17:27 +0000
- To: public-css-archive@w3.org
Crissov has just created a new issue for https://github.com/w3c/csswg-drafts: == [css-values] Allow sqrt(<length-percentage>) == In b8935e7, @tabatkins has just added [trigonometric](https://drafts.csswg.org/css-values-4/#trig-funcs) and [exponential functions](https://drafts.csswg.org/css-values-4/#exponent-funcs) as discussed in #2331 to css-values. The commit includes a good explanation why `hypot(A, B)` is useful (beyond possible number range overflows) by supporting `<length>` instead of just `<number>`, like `pow(A, B)` does. However, the argument only addresses `pow(A, B)`. I wonder whether similar reasoning could be applied to `sqrt(A)` which is currently defined as a convenience alias for `pow(A, 0.5)`. Please consider to change this to `pow(A/a, 0.5)*a` where `a` is unity with the same dimension and unit as `A`, e.g. `1px` . This means, it would return the square root of the number of the value `A` using the original dimension (and unit) of `A`. (This `a` could also be exposed as a separate function, e.g. `unit(A)` with `unit(16px)`, `unit(8px + 8px)`, `unit(2 * 8px)` all yielding `1px,` and `unit(1in + 2cm)` as well because pixel is the canonical unit, while `unit(2cm)`, `unit(1cm + 1cm)` and `unit(2 * 1cm)` should yield `1cm` if possible in [css-typed-om]. I would have needed this recently to dynamically remove the length units from the translation components in a `matrix()`.) If the square root function supported `<length>`, there might be less reason for having a distinct `hypot()` function, but more reason to also introduce **`cbrt(A)`** for the cubic root and possibly **`squared(A)`** and **`cubed(A)`** for raising the number of the value `A` to the second (or third) power without affecting its unit and dimension. While the square root function can be expressed by the power function with the terminating decimal fraction `0.5` as the exponent parameter, the cubic root requires an approximation to something like `0.333` or a calculation of `1/3`. This may lead to unexpected effects due to binary rounding which could be avoided by a generic **`root(A, B)`** function which (almost) equals `pow(A, 1/B)`, or perhaps by an **`inv(A)`** or **`rec(A)`** function that inverts the value to its reciprocal, i.e. `calc(1/A)`, and could be evaluated at a later stage. Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/3764 using your GitHub account
Received on Tuesday, 26 March 2019 11:17:29 UTC