W3C home > Mailing lists > Public > www-style@w3.org > January 2012

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

From: Christoph Päper <christoph.paeper@crissov.de>
Date: Fri, 27 Jan 2012 11:56:32 +0100
Message-Id: <E098AC08-849C-454C-8D9A-1D240808401B@crissov.de>
To: www-style list <www-style@w3.org>
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

> 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.

PS: Maybe rounding better was a part of ‘calc’:
    calc(<expression> [round <modifier>? <modulus>]? )
Received on Friday, 27 January 2012 10:57:06 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:49 GMT