You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In #544, minimum and maximum functions have been accepted for CSS Values Level 4.
Both functions select a single computed value from a set of 1 to N values (which may be results of nested calc() expressions). This cannot be achieved with Level 3 calc() syntax.
min (minimum/minimal) chooses the smallest computed value.
max (maximum/maximal) chooses the largest computed value.
The mode function may benefit from an optional value to specify the precision, i.e. tolerance limits, when comparing (and returning) computed values.
mod(100px 10em 1vw, 1pt)
This could effectively be reused as a ‘round to nearest multiple’ function. Such a static factor is called a module or modulus, e. g. in architecture and design.
The specification must also say what to do if no computed value occurs more often than another. It may fall back to the arithmetic mean of all equally frequent values.
mod(100px 10px) /* = 55px? */
Median
The median function needs to be specified for an even number of values as well, i.e. when there is one above and one below but none at the center of the set. It may fall back to the arithmetic mean of the two values closest to the true median.
med(100px 10px) /* = 55px? */
The median could also be specified for a reduced set where redundant entries were collapsed into a unique one beforehand:
I introduced round to nearest multiple as a side effect of mod, i.e. module instead of mode, but you could make it the main feature as well. It happens quite often that designers specify a grid using one unit but some live calculations have to use a different unit. It would also help to avoid different rounding behavior in implementations that can lead to perfect alignment in one browser but not another.
Crissov
changed the title
[css-values] Functions to select one value from a set: med(), mod()
[css-values] Median and Mode functions to select a single value from a set
Feb 17, 2020
In #544, minimum and maximum functions have been accepted for CSS Values Level 4.
Both functions select a single computed value from a set of 1 to N values (which may be results of nested
calc()
expressions). This cannot be achieved with Level 3calc()
syntax.There are at least two other useful statistic measures that work the same:
Mode
The mode function may benefit from an optional value to specify the precision, i.e. tolerance limits, when comparing (and returning) computed values.
This could effectively be reused as a ‘round to nearest multiple’ function. Such a static factor is called a module or modulus, e. g. in architecture and design.
The specification must also say what to do if no computed value occurs more often than another. It may fall back to the arithmetic mean of all equally frequent values.
mod(100px 10px) /* = 55px? */
Median
The median function needs to be specified for an even number of values as well, i.e. when there is one above and one below but none at the center of the set. It may fall back to the arithmetic mean of the two values closest to the true median.
med(100px 10px) /* = 55px? */
The median could also be specified for a reduced set where redundant entries were collapsed into a unique one beforehand:
If the values closest to the center do not occur equally often, the median could be weighted instead.
The text was updated successfully, but these errors were encountered: