Skip to content

Commit 0d7ba31

Browse files
committed
[css-values-4] Define 'numeric functions'. #13978
1 parent f90b03b commit 0d7ba31

1 file changed

Lines changed: 78 additions & 53 deletions

File tree

css-values-4/Overview.bs

Lines changed: 78 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,7 +3018,63 @@ Functional Notations</h2>
30183018
Other [=functional notations=] are defined in their own modules;
30193019
for example the <<color>> functions are defined in [[CSS-COLOR-4]] and [[CSS-COLOR-5]].
30203020

3021-
<h3 id="fuctional-serialization">
3021+
3022+
3023+
<h3 id='functional-numeric'>
3024+
Numeric Functions</h3>
3025+
3026+
Any [=functional notation=] that resolves solely to a [=numeric data type=]
3027+
is a <dfn export>numeric function</dfn>.
3028+
3029+
As the value of a [=numeric function=] can't, generally,
3030+
be known at parse time when range restrictions are enforced,
3031+
[=numeric functions=] returning out-of-range values
3032+
never cause a declaration to become invalid.
3033+
Instead, the value of a [=numeric function=]
3034+
is clamped to the range allowed in the context it is used
3035+
at [=computed value=] time if possible,
3036+
and at [=used value=] time otherwise.
3037+
3038+
Similarly,
3039+
if a [=numeric function=] returns a non-integer value,
3040+
but is used in a position that expects an <<integer>>,
3041+
the [=computed value=] and [=used value=]
3042+
are [=rounded to the nearest integer=].
3043+
3044+
Note: All [=math functions=] are [=numeric functions=],
3045+
but functions like ''sibling-index()'' are also [=numeric functions=]
3046+
without being [=math functions=].
3047+
3048+
<div class=example>
3049+
Since widths smaller than 0px are not allowed,
3050+
these three declarations are equivalent:
3051+
3052+
<pre>
3053+
width: calc(5px - 10px);
3054+
width: calc(-5px);
3055+
width: 0px;
3056+
</pre>
3057+
3058+
Note however that ''width: -5px'' is not equivalent to ''width: calc(-5px)''!
3059+
Out-of-range values specified <em>literally</em> are invalid at parse-time,
3060+
and cause the entire declaration to be dropped.
3061+
</div>
3062+
3063+
Note: While CSS intentionally leaves numeric precision/range UA-defined,
3064+
extremely large values (including, notably, ±∞)
3065+
will clamp to the minimum/maximum value allowed.
3066+
Even properties that can explicitly represent infinity as a keyword value,
3067+
such as 'animation-iteration-count',
3068+
will end up clamping ±∞,
3069+
as [=math functions=] can't resolve to keyword values;
3070+
the <em>numeric</em> part of the property's syntax still has an implicit minimum/maximum value.
3071+
3072+
<wpt>
3073+
css/css-values/calc-integer.html
3074+
css/css-values/calc-z-index-fractions-001.html
3075+
</wpt>
3076+
3077+
<h3 id="functional-serialization">
30223078
Serialization of Functional Notations</h3>
30233079

30243080
<div algorithm="serialize a functional notation">
@@ -3106,6 +3162,11 @@ Mathematical Expressions</h2>
31063162
...or the <<length-percentage>>/etc mixed types,
31073163
and can be used wherever such a value would be valid.
31083164

3165+
Note: [=Math functions=] differ from the more general [=numeric functions=]
3166+
because they automatically inherit the [=calculation context=] where they're used,
3167+
letting you use all the values you could use "normally" in that position,
3168+
with the same meaning they'd normally have.
3169+
31093170
<!-- Big Text: calc()
31103171

31113172
███▌ ███▌ █▌ ███▌ ██ ██
@@ -5154,53 +5215,11 @@ Computed Value</h3>
51545215
<h3 id='calc-range'>
51555216
Range Checking</h3>
51565217

5157-
Parse-time range-checking of values is not performed within [=math functions=],
5158-
and therefore out-of-range values do not cause the declaration to become invalid.
5159-
However, the value resulting from a [=top-level calculation=]
5160-
must be clamped to the range allowed in the target context.
5161-
Clamping is performed on <a>computed values</a> to the extent possible,
5162-
and also on <a>used values</a>
5163-
if computation was unable to sufficiently simplify the expression
5164-
to allow range-checking.
5165-
(Clamping is not performed on <a>specified values</a>.)
5166-
5167-
Note: This requires all contexts accepting ''calc()''
5168-
to define any range restrictions as closed (not open) interval endpoints:
5169-
"greater than or equal to 0px", not "greater than 0px" or "positive lengths".
5170-
5171-
Note: While CSS intentionally leaves numeric precision/range UA-defined,
5172-
extremely large values (including, notably, ±∞)
5173-
will clamp to the minimum/maximum value allowed.
5174-
Even properties that can explicitly represent infinity as a keyword value,
5175-
such as 'animation-iteration-count',
5176-
will end up clamping ±∞,
5177-
as [=math functions=] can't resolve to keyword values;
5178-
the <em>numeric</em> part of the property's syntax still has an implicit minimum/maximum value.
5179-
5180-
Additionally, if a [=math function=] that resolves to <<number>>
5181-
is used somewhere that only accepts <<integer>>,
5182-
the [=computed value=] and [=used value=] are [=rounded to the nearest integer=],
5183-
in the same manner as clamping, above.
5184-
5185-
<div class=example>
5186-
Since widths smaller than 0px are not allowed,
5187-
these three declarations are equivalent:
5188-
5189-
<pre>
5190-
width: calc(5px - 10px);
5191-
width: calc(-5px);
5192-
width: 0px;
5193-
</pre>
5194-
5195-
Note however that ''width: -5px'' is not equivalent to ''width: calc(-5px)''!
5196-
Out-of-range values <em>outside</em> ''calc()'' are syntactically invalid,
5197-
and cause the entire declaration to be dropped.
5198-
</div>
5199-
5200-
<wpt>
5201-
css/css-values/calc-integer.html
5202-
css/css-values/calc-z-index-fractions-001.html
5203-
</wpt>
5218+
The clamping/rounding behavior of [=numeric functions=]
5219+
is, for [=math functions=],
5220+
only performed on the results of a [=top-level calculation=].
5221+
Nested [=math functions=] forming a [=calculation tree=]
5222+
neither clamp nor round.
52045223

52055224

52065225
<!-- Big Text: serial
@@ -5221,6 +5240,12 @@ Serialization</h3>
52215240
To <dfn export>serialize a math function</dfn> |fn|:
52225241

52235242
1. If the root of the [=calculation tree=] |fn| represents
5243+
is an unresolved [=numeric function=]
5244+
that is not a [=math function=],
5245+
serialize that function as normal
5246+
and return the result.
5247+
5248+
2. If the root of the [=calculation tree=] |fn| represents
52245249
is a numeric value
52255250
(number, percentage, or dimension),
52265251
and the serialization being produced is of a [=computed value=] or later,
@@ -5229,7 +5254,7 @@ Serialization</h3>
52295254
then serialize the value as normal
52305255
and return the result.
52315256

5232-
2. If |fn| represents an infinite or NaN value:
5257+
3. If |fn| represents an infinite or NaN value:
52335258
1. Let |s| be the [=string=] "calc(".
52345259
2. Serialize the keyword ''infinity'', ''-infinity'', or ''NaN'',
52355260
as appropriate to represent the value,
@@ -5245,7 +5270,7 @@ Serialization</h3>
52455270
and append it to |s|.
52465271
4. Append ")" to |s|, then return it.
52475272

5248-
3. If the [=calculation tree’s=] root node is a numeric value,
5273+
4. If the [=calculation tree’s=] root node is a numeric value,
52495274
or a [=calc-operator node=],
52505275
let |s| be a string initially containing "calc(".
52515276

@@ -5255,7 +5280,7 @@ Serialization</h3>
52555280
(such as "sin" or "max"),
52565281
followed by a "(" (open parenthesis).
52575282

5258-
4. For each child of the root node,
5283+
5. For each child of the root node,
52595284
[=serialize the calculation tree=].
52605285
If a result of this serialization starts with a "(" (open parenthesis)
52615286
and ends with a ")" (close parenthesis),
@@ -5264,9 +5289,9 @@ Serialization</h3>
52645289
using ", " (comma followed by space),
52655290
then append the result to |s|.
52665291

5267-
5. Append ")" (close parenthesis) to |s|.
5292+
6. Append ")" (close parenthesis) to |s|.
52685293

5269-
6. Return |s|.
5294+
7. Return |s|.
52705295
</div>
52715296

52725297
<div algorithm>

0 commit comments

Comments
 (0)