Skip to content

Commit 21a5201

Browse files
committed
[css-values] More strictly define the infinity/NaN semantics for math functions.
1 parent 2bb3733 commit 21a5201

File tree

1 file changed

+37
-11
lines changed

1 file changed

+37
-11
lines changed

css-values-4/Overview.bs

+37-11
Original file line numberDiff line numberDiff line change
@@ -1829,17 +1829,34 @@ Type Checking</h4>
18291829
If it can't [=CSSNumericValue/match=] any of these,
18301830
the [=math function=] is invalid.
18311831

1832-
As a further breaking change from the previous version of this specification,
1833-
division by zero is now allowed.
1834-
Implementations must follow IEEE-754 semantics for recognition and propagation
1835-
of infinities and NaN values,
1836-
including tracking the difference between +0 and -0.
1837-
(However, CSS treats both zeroes as the same,
1838-
if a [=math function=] resolves to one of them.)
1839-
Infinities are, by definition, out-of-range for any property,
1840-
and trigger appropriate clamping at used-value time per [[#calc-range]].
1841-
If a [=math function=] would resolve to NaN,
1842-
it instead resolves to positive infinity.
1832+
Division by zero is possible,
1833+
which introduces certain complications.
1834+
[=Math functions=] follow simplified versions of IEEE-754 semantics for these operations:
1835+
1836+
* Dividing a positive value by zero produces +∞.
1837+
* Dividing a negative value by zero produces −∞.
1838+
* Adding or subtracting ±∞ to anything produces the appropriate infinity,
1839+
unless a following rule would define it as producing NaN.
1840+
* Multiplying any value by ±∞ produces the appropriate infinity,
1841+
unless a following rule would define it as producing NaN.
1842+
* Dividing any value by ±∞ produces zero,
1843+
unless a following rule would define it as producing NaN.
1844+
* Dividing zero by zero,
1845+
dividing ±∞ by ±∞,
1846+
multiplying 0 by ±∞,
1847+
adding +∞ to −∞
1848+
(or the equivalent subtractions)
1849+
produces NaN.
1850+
* Any operation with at least one NaN argument produces NaN.
1851+
1852+
If a <dfn export>top-level calculations</dfn>
1853+
(an argument to ''min()'', ''max()'', or ''clamp()'',
1854+
or a ''calc()'' that's not nested directly inside of another [=math function=])
1855+
would produce a NaN,
1856+
it instead produces +∞.
1857+
Other calculations
1858+
(such as a ''calc()'' nested directly within a [=math function=])
1859+
can produce NaN as normal.
18431860

18441861
Note: Algebraic simplifications do not affect the validity of a [=math function=] or its resolved type.
18451862
For example, ''calc(5px - 5px + 10s)'' and ''calc(0 * 5px + 10s)'' are both invalid
@@ -1956,6 +1973,15 @@ Range Checking</h4>
19561973
Note: This requires all contexts accepting ''calc()''
19571974
to define their allowable values as a closed (not open) interval.
19581975

1976+
Note: By definition,
1977+
±∞ are outside the allowed range for any property,
1978+
and will clamp to the minimum/maximum value allowed.
1979+
Even for properties that explicitly allow ''infinity'' as a keyword value,
1980+
such as 'animation-iteration-count',
1981+
will end up clamping ±∞,
1982+
as [=math functions=] can't resolve to keyword values;
1983+
the <em>numeric</em> part of the property's syntax still has a minimum/maximum value.
1984+
19591985
Additionally, if a [=math function=] that resolves to <<number>>
19601986
is used somewhere that only accepts <<integer>>,
19611987
the [=computed value=] and [=used value=] are rounded to the nearest integer,

0 commit comments

Comments
 (0)