W3C home > Mailing lists > Public > www-style@w3.org > December 2018

Re: [css-values] Rounding a real number to an integer

From: Gérard Talbot <www-style@gtalbot.org>
Date: Wed, 19 Dec 2018 15:37:31 -0500
To: Simon Fraser <smfr@me.com>
Cc: fantasai <fantasai.lists@inkedblade.net>, W3C www-style mailing list <www-style@w3.org>, Emilio Cobos Álvarez <emilio@crisal.io>
Message-ID: <6c26b2f48daaf4d13e5fef19e164425b@gtalbot.org>
Le 2018-12-19 11:55, Gérard Talbot a écrit :
> Le 2018-12-19 01:29, Simon Fraser a écrit :
>>> On Dec 18, 2018, at 6:15 PM, Gérard Talbot <www-style@gtalbot.org> 
>>> wrote:
>>> 
>>> Le 2018-12-18 19:58, fantasai a écrit :
>>>> On 12/15/18 6:46 PM, Gérard Talbot wrote:
>>>>> Le 2018-12-15 19:46, Gérard Talbot a écrit :
>>>>>> Hello,
>>>>>> "
>>>>>> (...) 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_*.
>>>>>> "
>>>>>> CSS4 Values, section 5.1.1. Combination of <integer>
>>>>>> https://www.w3.org/TR/css-values-4/#combine-integers
>>>>>> So
>>>>>> 'z-index: -1.5'
>>>>>> should be converted to 'z-index: -1' and not to 'z-index: -2'
>>>>>> while
>>>>>> 'z-index: 1.5'
>>>>>> should be converted to 'z-index: 2'.
>>>>> Oops.. I meant
>>>>> 'z-index: calc(-1.5)'
>>>>> should compute to 'z-index: -1' and not to 'z-index: -2'
>>>>> while
>>>>> 'z-index: calc(1.5)'
>>>>> should compute to 'z-index: 2'.
>>>>>> Is my interpretation of the spec correct?
>>>> Afaict it is correct. If that's not what implementations do,
>>>> though, let us know as we may need to adjust the spec. :)
>>>> ~fantasai
>>> 
>>> Firefox 66 buildID=20181218191030 resolves 'z-index: calc(-3 / 2)' to 
>>> 'z-index: -2' not as 'z-index: -1' in:
>>> http://www.gtalbot.org/BrowserBugsSection/CSS3Values/calc-negative-fraction-001.html
>>> 
>>> Chromium 73.0.3645.0 passes (false positive)
>>> http://www.gtalbot.org/BrowserBugsSection/CSS3Values/calc-negative-fraction-001.html
>>> but that is because 'z-index: calc(-3 / 2)' is not resolved, is not 
>>> handled at all.
>>> 
>>> - - - - -
>>> 
>>> Chromium 71, Chromium 73.0.3645.0 and Epiphany 3.31.3-3-g64a3330ce 
>>> (WebKitGTK+ 2.23.1) fail
>>> http://www.gtalbot.org/BrowserBugsSection/CSS3Values/calc-positive-fraction-001.html
>>> 
>>> Firefox 66 buildID=20181218191030 passes
>>> http://www.gtalbot.org/BrowserBugsSection/CSS3Values/calc-positive-fraction-001.html 
>>> <http://www.gtalbot.org/BrowserBugsSection/CSS3Values/calc-positive-fraction-001.html>
>> 
>> Be careful with your test case.
> 
> If you are referring to calc-negative-fraction-001, then it may be
> possible to make that test more reliable, more trustworthy. I have not
> thought about this.
> 

I can not find a quick and easy way to make calc-negative-fraction-001 
test more reliable, more constraining. An alternative would be to append 
these 2 sub-tests

,
   {
     specified: "calc(-1.5)",
     computed: "-1",
     description: "Accepts a negative <number> and then rounds halfway 
between adjacent integers toward positive infinity",
   }
,
   {
     specified: "calc(-3 / 2)",
     computed: "-1",
     description: "Accepts <integer> / <integer> and then rounds halfway 
between adjacent integers toward positive infinity",
   }


into Emilio's
http://w3c-test.org/css/css-values/calc-integer.html
test.

Gérard

> 
>> Chrome and WebKit treat the calc as
>> invalid (for some reason they don’t accept <number> / <number>), so
>> the used value for z-index ends up as auto, but your testcase shows
>> green in that case.
>> 
>> Simon
> 
> The test is for CSS4 Values compliance.
> 
> "
> 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, in the same manner as clamping, above. The
> rounding method must be the same as is used for animations of integer
> values.
> "
> CSS4 Values, section 9.1.4. Range Checking
> https://www.w3.org/TR/css-values-4/#calc-range
> 
> I have not found where that rounding method is given for animations of 
> integers.
> 
> More info:
> [css-values] calc() should round when it's used as an <integer>
> https://github.com/w3c/csswg-drafts/issues/2337
> 
> Additional test: calc-integer by Emilio Cobos Álvarez
> http://w3c-test.org/css/css-values/calc-integer.html
> 
> Gérard
Received on Wednesday, 19 December 2018 20:37:59 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 19 December 2018 20:38:00 UTC