Bug 1531213 - Round to nearest integer per spec for calc() r=dholbert

Rounding to the nearest integer rounds in the direction of +inf when the
fractional portion is 0.5. eg: -1.5 -> -1, 1.5 -> 2

Spec: https://www.w3.org/TR/css-values-4/#css-round-to-the-nearest-integer
WPT test: https://wpt.fyi/results/css/css-values/calc-z-index-fractions-001.html

1 WPT subtest newly passes.

Differential Revision: https://phabricator.services.mozilla.com/D182745
This commit is contained in:
CanadaHonk 2023-07-04 22:13:29 +00:00
Родитель 928aff7def
Коммит c50b872101
2 изменённых файлов: 1 добавлений и 6 удалений

Просмотреть файл

@ -931,7 +931,7 @@ impl CalcNode {
input: &mut Parser<'i, 't>,
function: MathFunction,
) -> Result<CSSInteger, ParseError<'i>> {
Self::parse_number(context, input, function).map(|n| n.round() as CSSInteger)
Self::parse_number(context, input, function).map(|n| (n + 0.5).floor() as CSSInteger)
}
/// Convenience parsing function for `<length> | <percentage>`.

Просмотреть файл

@ -1,5 +0,0 @@
[calc-z-index-fractions-001.html]
expected:
if (os == "android") and fission: [OK, TIMEOUT]
[testing z-index: calc(-3 / 2)]
expected: FAIL