-
Notifications
You must be signed in to change notification settings - Fork 676
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] Let B default to 1 in round(<strategy>?, A, B)
#9668
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<Frances> Alan: Moving onto the next issue, we are limited by compat concerns.<Frances> Tab: Round function takes a rounding strategy, we require the modulus to be rounded. We could omit the modulus. <emilio> q <lea> q? <astearns> ack emilio <lea> q <Frances> Emilio: It feels weird to make lengths invalid and not make it optional, such as rounding a pixel value. Default for the length would be nice. <astearns> ack lea <Frances> Tab: Rounding to one pixel as a default is not obvious, people might not care about subpixels, but rather the unit they are using. <bramus> 1 on what tab just said. <emilio> q <astearns> ack emilio <Frances> Lea: Should not have to specify 1, whereas dimensions such as length, would make more sense on what you are rounding by, pixels might not be used too much today. Would like default for lengths, possibly not pixels. <lea> qq to reply to emilio <Frances> Emilio: In length there is a single unit that other lengths end up computing to. <astearns> ack lea <Zakim> lea, you wanted to react to emilio to reply to emilio <Frances> Lea: Sensible defaults are great when centered around user needs or could be confusing. <oriol> q <Frances> Alan: It is reasonable to have numbers default to 1, but not reasonable for numbers to default to invalid for another type. <Frances> Lea: Which invalid results? <oriol> q- <lea> q? <Frances> Alan: Once taking the pattern of omitting the argument and applying it, it could create invalid creations. <florian> q <bramus> q <emilio> q <Frances> Lea: When rounding numbers will be clear, when rounding lengths will not be clear. <emilio> ack emilio <lea> q <astearns> ack Frances <astearns> ack florian <Frances> Alan: There could be a reasonable default, omit the parameter in some implications but not others. <oriol> 1 to Florian <Frances> Florian: Figuring out more syntax is necessary, you need to express something. Figuring out which syntax is implied. For rounding things, separate digits after the comma. Does 10 mean 10 digits after the period or before the period? For lengths, have to think about this stuff in what you mean. <astearns> ack bramus <lea> 1 to florian, that's exactly what I was saying too (but always good to have multiple framings) <lea> q? <Frances> Bramus: If the default only cares for one of the cases, then it's not a good default? <Frances> Alan: It could make it difficult for an author to reason whether to use the parameter or not. <astearns> ack lea <Frances> Lea: If it's the concern, round could possibly not have a default. It takes a parameter to round by. <Frances> Alan: We can likely resolve on making the change. <Frances> PROPOSAL: Allow the modulus parameter to be optional in the case of rounding numbers and default to 1 <Frances> Alan: Objections? No objections. |
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: