-
Notifications
You must be signed in to change notification settings - Fork 719
[css-values] Let B default to 1 in round(?, A, B)
#9668
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
Comments
Does it have to be invalid? Isn't it possible to just assume the same type for B in that case? I.e. Sebastian |
No, that would be bad. Let's say It could work by saying that step defaults to one canonical unit, but in |
Right, that's precisely why it requires a unit right now - we can't have the unit depend on the input (for the reasons given, plus things like
Yes, we could do this. Is there a particular reason to do so, tho? |
It just seems strange to require the |
Converting the unit before rounding is totally unexpected from an author's standpoint.
The point was for rounding when only having a single unit. So, Allowing to omit B for numbers but not dimensions or percentages may cause confusion.
Not just spoken languages but also also in many programming languages you can omit the precision - or even don't have a way to define one like in JavaScript. Sebastian |
Would Making the precision default to |
That's pretty fragile, and it means that And In-flight edit: lol, @jfkthame makes the exact same points. Anyway, if impls want to change the defaulting rules to allow a default of |
I agree with @SebastianZ and @Loirooriol that it would be unintuitive for authors if the rounding base defaulted to My educated guess is that the most common use case by far will be rounding (calculated) lengths to whole pixels. Since Another viable solution I see would be to treat a Finally, instead of defaulting to
|
I strongly disagree that rounding to "whole pixels" is the most common case for rounding lengths. I think that's actually an extremely rare case; subpixel lengths are usually just fine to work with. Similarly, rounding to the nearest degree doesn't seem particularly useful for most cases. The canonical unit is quite arbitrary, and generally speaking I don't think people will commonly be rounding to 1 of any unit; the rounding precision depends intimately on what one is actually trying to accomplish.
That's just a less powerful version of the current argument, where you're limited to precisions that are a power of 10 of some unit. It also has all the existing problems of a default rounding precision.
These either continue to have the existing problems of a default rounding precision, or are equivalent to just providing a trivial value. |
That's true in any case, as Though we could also define that the unit of the first operand is used. So
The precision is not unpredictable, it is unit-based.
The point is to provide a reasonable fallback / default. Authors will still be advised to provide a rounding interval if they want to influence the rounding precision.
Note that Firefox already ships the Sebastian |
This would violate commutativity. And in fact serialization sorts summation operands alphabetically by their units, so this wouldn't roundtrip. And anyways it's seems very unintuitive to me. |
Ultimately, trying to infer a rounding precision from the source unit is going to fail in lots of cases, and even when it works, there's zero guarantee that it'll produce a useful value. The current spec makes it trivial to round to any unit you like ( |
It just occurred to me that with keywords in the second parameter, Either However, authors would probably want arbitrary precision there, which would be crude to support with keywords and always remain incomplete. Treat this as a devil’s advocate proposal then. |
That's out of the scope of this issue, which is to make B optional in certain cases. Sebastian |
That is exactly why I did not open another issue. My idea was that if we were to add keywords to the last argument in order to have one of them as an omitable default, we could shoehorn this in as well. By the way, I reread the original issue #2513, where much of this thread had already been discussed, and I rediscovered #4440 which I totally had forgotten about. It is related but also quite different. |
Strong +1 to defaulting B to 1. It makes sense to require the unit for anything with a unit, and there is no widespread precedent for that in other languages. However, writing (while we're at it, why are we using commas here? It doesn't match the "we use commas only for repetition" pattern. How about |
We use commas mostly for repetition, and sometimes for more general argument separation when the grammars would be ambiguous or at least unclear for authors to be adjacent. That latter reason is what applies here (and for all the math functions) - the arguments aren't numbers, they're calculations, and the bounds of a calculation aren't super clear visually on their own. |
The CSS Working Group just discussed The full IRC log of that discussion |
This got cut off from the meeting notes, as the switch to the next topic happened a bit too soon, but we resolved on the PROPOSAL as listed in the meeting notes:
|
I get the reasoning for requiring a precision in most cases. However, as I mentioned in #2513 (comment), it seems fine to omit it for numbers.
So if B becomes optional, defaulting to 1, it will be possible to do things like
while
round(2.3em)
will continue being invalid due to the type mismatch between A and B.The text was updated successfully, but these errors were encountered: