Skip to content
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

[css-values-4] Distributing multiplication over sums clarification #9434

Closed
danielsakhapov opened this issue Oct 4, 2023 · 2 comments
Closed

Comments

@danielsakhapov
Copy link
Contributor

The spec says that

Internal representations of math functions are eagerly simplified to the extent possible, using standard algebraic simplifications (distributing multiplication over sums, combining similar units, etc.).

So, the case like calc(2 * (10px - 1rem)) becomes calc(20px - 2rem).

It's not clear to me if we should do the same for when we have functions inside the brackets, like:
calc(2 * (min(10px, 10%) + max(1rem, 1%)) should become calc(2 * min(10px, 10%) + 2 * max(1rem, 1%))?

Currently, no browser does calc(2 * min(10px, 10%) + 2 * max(1rem, 1%)) and just leaves the expression as it is.

So, my question is, should we distribute multiplication over sums in case when the parts are math functions?

@tabatkins @fantasai

@danielsakhapov danielsakhapov changed the title [css-values] Distributing multiplication over sums clarification [css-values-4] Distributing multiplication over sums clarification Oct 5, 2023
@danielsakhapov
Copy link
Contributor Author

Never mind, I can't read the spec...

But why don't we simplify in case of operands of the sum/sub being non-numeric?

@tabatkins
Copy link
Member

The spec doesn't do that distribution, currently, because doing so wouldn't meaningfully simplify the expression.

The current rule means that Product(Numeric, Sum(Numeric, Numeric, Numeric)) can be simplified to Sum(Numeric, Numeric, Numeric), which is a noticeable simplification; we remove one level of nesting.

But if there are math functions, like Product(Numeric, Sum(MathFn, MathFn, MathFn)), distributing the multiplication would leave you with Sum(Product(Numeric, MathFn), Product(Numeric, MathFn), Product(Numeric, MathFn)) - it's no simpler, it just inverts the order of the nested functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants