[cssvalues4] calc() function with real number halfway between 2 adjacent integers
Status
()
People
(Reporter: bugzilla, Unassigned)
Tracking
(Blocks 2 bugs, {testcase})
Firefox Tracking Flags
(firefox67 affected)
Details
When a calc() function's simplified expression is a real number halfway between 2 adjacent numbers and the property accepts only an integer, then such simplified expression should be rounded _ towards positive infinity _.
"
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/cssvalues4/#calcrange
"
(...) 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/cssvalues4/#combineintegers
Test:
zindex: calc(3 / 2); /* 1.5 should be rounded up to 1 */
http://w3ctest.org/css/cssvalues/calczindexfractions001.html
More info in this thread:
http://lists.w3.org/Archives/Public/wwwstyle/2018Dec/0027.html
Right now, no browser passes the
zindex: calc(3 / 2)
test.
Reporter  
Updated•3 months ago

Comment 1•3 months ago


Are browsers interoperable? If so, maybe it would be better to change the spec.
Updated•3 months ago

Comment 2•3 months ago


Yes, this is how I implemented bug 1440251 I guess. We could change that from round() to (n + 0.5).floor().
Though I'd appreciate to know the reasoning for this behavior (I asked in the wwwstyle thread above).
Reporter  
Comment 3•3 months ago


Browsers do not interoperate:
https://wpt.fyi/results/css/cssvalues/calczindexfractions001.html?label=stable&aligned
https://wpt.fyi/results/css/cssvalues/calczindexfractions001.html?label=master&aligned
"Most programming languages round halfway values away from zero,
Javascript's Math.round being the notable exception (...)"
http://lists.w3.org/Archives/Public/wwwstyle/2018Dec/0026.html
So I checked this specific issue with JS:

    
 Math.floorMath.roundMath.ceil 
    

    
 3.1  3  3  4 
    

    
 3.5  3  4  4 
    

    
 3.9  3  4  4 
    

    
 1.1  2  1  1 
    

    
 1.5  2  1  1 
    

    
 1.9  2  2  1 
    

Firefox 60.4.0 ESR and Chromium 71 both report:
Math.floor(1.1)
2
Math.floor(1.5)
2
Math.floor(1.9)
2
Math.round(1.1)
1
Math.round(1.5)
1
Math.round(1.9)
2
Math.ceil(1.1)
1
Math.ceil(1.5)
1
Math.ceil(1.9)
1
and
Math.round(1.5)
2
Anyway... I have no preference either way on this issue and on changing the spec.
Updated•2 months ago

Description
•