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] Simplification changes semantics #9437

Closed
sesse opened this issue Oct 4, 2023 · 3 comments
Closed

[css-values-4] Simplification changes semantics #9437

sesse opened this issue Oct 4, 2023 · 3 comments

Comments

@sesse
Copy link
Contributor

sesse commented Oct 4, 2023

Hi,

I noticed that css-values-4 says that we should “simplify” a * (b + c) to ab + ac. However, in practice this means web pages will change; as long as all browsers implement these values as floats, these are not equivalent.

Even barring overflow and underflow cases, something as innocent as floor(3 * (4/3 + 1)) will be different from (3 * (4/3) + 3) (one becomes 6, the other becomes 7). For a case that doesn't involve floor(), 3 * (1 + 7/6) will round to 6 before and 7 now. (In the context of the standard, that would be someone writing e.g. calc(3 * (1px + 7em/6)) assuming em = 1px, just for the sake of the example.)

Constant folding makes sense, but is this really a good thing?

@tabatkins
Copy link
Member

Many details of float handling can change things that depend on precise integers and non-dyadic rationals. Distribution can, sure, but just addition can result in things not adding up to exactly what you'd expect. CSS doesn't even specify the float size; pure numbers will probably be doubles, but impls use fixed point for lengths (with different bases!), so even trivial values can trigger browser differences.

The overall conclusion is just that CSS math is very rarely that dependent on exact results.

@tabatkins
Copy link
Member

Gonna go ahead and close this; the only possible "fix" would be to go full JS and say that all CSS math is done in IEEE-754 doubles, with a precisely defined order of operations for all mathematical stuff. That's definitely not going to happen, since impls purposely use non-doubles for a number of reasons.

So yeah, CSS math is gonna (continue to) be somewhat underdefined.

@sesse
Copy link
Contributor Author

sesse commented Oct 23, 2023

Note that CSSOM already specifies a strict order of operations, so implementations are not really that free in practice.

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

No branches or pull requests

2 participants