Re: [css3-*] Review of functional syntax in CSS

On Fri, Jan 27, 2012 at 2:56 AM, Christoph Päper
<christoph.paeper@crissov.de> wrote:
> Tab Atkins Jr.:
>> On Thu, Jan 26, 2012 at 11:06 AM, Christoph Päper
>>>
>>> Would it make sense then to leave out “round”, i.e. ‘up()’, ‘down()’ etc.?
>>
>> We discussed using floor/ceil like most languages do,
>
> I think this pair of functions is usually used without a parameter and they round to the closest upper or lower integer, whereas “round” often has a parameter to specify the number of digits after the decimal divider. Therefore
>
>  floor(foo) == down(foo, 0)
>  ceil(foo)  == up(foo, 0)
>
> This, of course, only applies to unitless numbers, not CSS values. We could construct a difference, though:
>
>  floor(4em, 1.5em) = 3em = down(4em, 1.5em)
>  floor(5em, 1.5em) = 3em ≠ down(5em, 1.5em) = 4.5em
>
> ‘floor’ and ‘ceil’ would use only those multiples of the modulus that are integers. I don’t know if that’s a desirable feature, but it supports not to choose these names for standard rounding up and down.
> I could also see them differ for negative values instead. (Btw., I think negative moduli should work just fine. Do we need ‘abs()’, though?)
>
>  floor(-4em, 1.5em) = -3em   ≠ down(-4em, 1.5em) = -4.5em
>  ceil(-4em, 1.5em)  = -4.5em ≠ up(-4em, 1.5em)   = -3em
>
> Rounding direction:
>  floor:  0
>   ceil: ±∞
>   down: –∞
>     up: +∞
>
> Rounding to odd or even, however, is a feature that is useful to have in CSS, because it will result in better distributed sums of rounded values:
>
>        0.5 + 1.5                      = 2.0
>  round(0.5 + 1.5)        = round(2.0) = 2.0
>  round(0.5) + round(1.5) = 1.0 + 2.0  = 3.0
>  up(0.5) + up(1.5)       = 1.0 + 2.0  = 3.0
>  down(0.5) + down(1.5)   = 0.0 + 3.0  = 3.0
>  odd(0.5) + odd(1.5)     = 1.0 + 1.0  = 2.0
>  even(0.5) + even(1.5)   = 0.0 + 2.0  = 2.0
>
> … unless you mix them:
>
>  up(0.5) + down(1.5)     = 1.0 + 1.0  = 2.0
>  down(0.5) + up(1.5)     = 0.0 + 2.0  = 2.0
>  odd(0.5) + even(1.5)    = 1.0 + 2.0  = 3.0
>  even(0.5) + odd(1.5)    = 0.0 + 1.0  = 1.0

Now justify all of these with use-cases.  ^_^  The use-case for
round-up/round-down, btw, is CJK typography, which often wants
containers to have a width/height that is a multiple of the em box.
They're also likely useful for various and sundry things in calc().

>> but I can't consistently spell ceil correctly,
>
> Spelling arguments come up on a regular basis and, not being a native speaker, always puzzle me.

What's puzzling?  Does the fact that you're a non-native speaker make
spelling uniformly easy or uniformly hard?

~TJ

Received on Friday, 27 January 2012 16:23:41 UTC