Thanks for the links to other issues. I had seen some of them but not most of them.
I had seen the one for
if. That one is for a different kind of
if. It was correctly rejected for being too powerful. It could be used in any context and refer to properties of the element like
width: if(width < 500px, 600px, 400px). It could also be used like
if(p, 5%, blue).
The one I proposed only outputs a number and, though I did not specify, it does not have a mechanism to refer to the element, just
attr, the results of other numeric functions, and literals.
With it, you could compute the sign of x as
if(var(--x) > 0) - if(var(--x) < 0). If
x = 0, it’s
0 - 0 = 0. If
x < 0, it’s
0 - 1 = -1. If
x > 0, it’s
1 - 0 = 1. Since
abs(x) can be defined as
x*sgn(x), you also get that for free (though abs and sgn are both probably common enough to deserve shorthands.)
In general, it makes it easy to “toggle” terms on and off in an expression, like
width: calc(100px + 50px*if(var(--x) < 10) - 50px*if(var(--y) > 20)) which can be 50, 100, or 150px wide dependent on the values of x and y.
A useful related function would be
media(q) that returns 1 if the media query
q holds and 0 otherwise. Then you could just do
--do-animations: media((prefers-reduced-motion)) instead of defining it to 1 and then redefining it to 0 in a media query.
I’m not sure I see the point of
avg, etc. Without lists, you always know how many quantities are involved so
sum(1, 2, 3) isn’t much better than
calc(1 + 2 + 3). With lists you’d need to add all kinds of list functions too. It’s also unclear to me why one would need to compute the arithmetic mean in css.