-
Notifications
You must be signed in to change notification settings - Fork 756
Description
In the expression round(2rem, 1px), what would be the unit of the resulting length? Is it even defined?
Here are some test cases: https://codepen.io/maikelkrause/pen/yyBxJPg
The codepen above gives different results (for test case 2 and 3) in all three major browsers. (Note: I assumed that Chrome's implementation is the correct one so those are marked as "passing", but this is what I want to double check in this issue.) It uses tan(atan2()) to extract the scalar part of a dimensional value.
- Chrome 139: (1) 32px, (2) 32px, (3) 32px
- Firefox 142: (1) 31.9999px, (2) 31.9999px, (3) 0px
- Safari 18.6: (1) 32px, (2) 0.250549px, (3) 0.250549px
From the spec:
The
round(<rounding-strategy>?, A, B?)function contains an optional rounding strategy, and two calculations A and B, and returns the value of A, rounded according to the rounding strategy, to the nearest integer multiple of B either above or below A. The argument calculations can resolve to any<number>,<dimension>, or<percentage>, but must have a consistent type or else the function is invalid; the result’s type will be the consistent type.If A is exactly equal to an integer multiple of B,
round()resolves to A exactly
The spec mentions that the result may be (1) the nearest integer multiple of B (implies the unit of B?), or (2) A exactly (implies the unit of A?).
(This may be related to #7482.)