[csswg-drafts] [css-values] Clarifying serialization of negative zero and expression simplification (#9750)

cjpearson has just created a new issue for https://github.com/w3c/csswg-drafts:

== [css-values] Clarifying serialization of negative zero and expression simplification ==
Recently I was discussing with @emilio how signed zeroes should be serialized in calc expressions, and couldn't find a clear answer in the spec. 

For example, an expression like `max(1% / -infinity, 0%)` which should simplify to `max(-0%, 0%)`. Without knowing if the percentage basis is positive or negative, it can't be simplified further since zeroes of different signs are not considered equivalent in min/max functions.

It looks like currently Chrome and Firefox serialize this as `max(0%, 0%)` while Safari does `calc(0%)`. I'm not sure which one of these is correct. `max(-0%, 0%)` is perhaps another possibility. 

I found two parts of the spec that look to be relevant.

The [serialization steps](https://drafts.csswg.org/css-values/#calc-serialize) mention infinities and NaN but don't have any explicit instructions for negative zero. The numeric value should be clamped to the allowed range, but the allowed range may include negative values. 

[10.9.1. Infinities, NaN, and Signed Zero](https://drafts.csswg.org/css-values/#calc-ieee) mentions that if a top level calculation simplifies to a negative zero, it should be "censored into a standard representable value". 

Could that apply here? The example expression doesn't fully simplify, but the only two possible resulting values would be equivalent to 0%, so `calc(0%)` seems reasonable in this case. 

But I'm not sure if that would work if there are additional arguments. Would it also be ok to simplify something like `max(-0%, 0%, 1%)` to `max(0%, 1%)` if it's the top-level expression? Does it make sense in general to eliminate duplicated values? Safari serializes `max(1%, 1%, 1%)` as `calc(1%)`, while Chrome and Firefox keep `max(1%, 1%, 1%)`.



Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9750 using your GitHub account


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

Received on Sunday, 24 December 2023 02:54:00 UTC