Skip to content

Commit

Permalink
[css-values-4] Add a dfn for 'round to the nearest integer', since CS…
Browse files Browse the repository at this point in the history
…S is consistent in how it does this. #5689
  • Loading branch information
tabatkins committed Oct 21, 2021
1 parent 0b0c3c5 commit b4739bc
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions css-values-4/Overview.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,13 @@ Integers: the <<integer>> type</h3>
css/CSS2/values/numbers-units-004.xht
</wpt>

Unless otherwise specified,
in the CSS specifications
<dfn for=CSS export lt="round to the nearest integer">rounding to the nearest integer</dfn>
requires rounding in the direction of +∞
when the fractional portion is exactly 0.5.
(For example, ''1.5'' rounds to ''2'', while ''-1.5'' rounds to ''-1''.)

<h4 id="combine-integers">
Computation and Combination of <<integer>></h4>

Expand All @@ -1124,8 +1131,7 @@ Computation and Combination of <<integer>></h4>
<var>p</var> &times; <var>V<sub>b</sub></var>);
that is, interpolation happens in the real number space
as for <<number>>s, and the result is converted to an <<integer>>
by rounding to the nearest integer,
with values halfway between adjacent integers rounded towards positive infinity.
by [=rounding to the nearest integer=].

<a>Addition</a> of <<integer>> is defined as
<var>V<sub>result</sub></var> =
Expand Down Expand Up @@ -3303,6 +3309,7 @@ Stepped Value Functions: ''round()'', ''mod()'', and ''rem()''</h3>

If <<rounding-strategy>> is omitted,
it defaults to ''nearest''.
(Aka [=rounding to the nearest integer=].)

Issue(5689): CSSOM needs to specify how it rounds,
and it's probably good for CSS functions to round the same way by default.
Expand Down Expand Up @@ -4135,9 +4142,8 @@ Type Checking</h3>
</div>

Additionally, [=math functions=] that resolve to <<number>>
can be used in any place that only accepts <<integer>>.
(It gets rounded to the nearest integer,
as specified in [[#calc-range]].)
can be used in any place that only accepts <<integer>>;
the value is [=rounded to the nearest integer=] as it resolves.

Operators form sub-expressions, which gain types based on their arguments.

Expand Down Expand Up @@ -4676,9 +4682,8 @@ Range Checking</h3>

Additionally, if a [=math function=] that resolves to <<number>>
is used somewhere that only accepts <<integer>>,
the [=computed value=] and [=used value=] are rounded to the nearest integer,
the [=computed value=] and [=used value=] are [=rounded to the nearest integer=],
in the same manner as clamping, above.
The rounding method must be the same as is used for animations of integer values.

<div class=example>
Since widths smaller than 0px are not allowed,
Expand Down Expand Up @@ -4995,8 +5000,9 @@ Appendix A: Recommended Minimum Ranges and Precision of Computed Values</h2>
(for example, in the ''calc()'' expression),
if the result is unsupported
it must also be clamped/rounded as necessary.
<span class="note">
Note this means that rounding errors <em>may</em> accumulate.
<span class="note">
Note this means that rounding errors <em>may</em> accumulate.
</span>
-->


Expand Down

0 comments on commit b4739bc

Please sign in to comment.
  NODES
Community 1
Note 5
os 6
text 1
Users 1
web 1