Re: Modulus operator & division by values

On Fri, Jun 21, 2013 at 3:18 AM, Maël Nison <nison.mael@gmail.com> wrote:
> Hi,
>
> I've recently come across a use case where the modulus operator would have
> been useful[1], so I was wondering what were the reason which led to its
> eviction from the current spec. I have been able to find the following
> discussion[2], but I'm not sure to fully understand the argument :
>
>  1. We drop the 'mod' operator since it only makes sense when
>     both operands have the same units.
>
> In my fiddle, you can see that I'm using a 'px' modulus on a percentage, and
> I think it makes perfect sense after converting the percent into a pixel
> unit (which is probably delayed up to the rendering ?).
>
> Am I missing something ?
>
> [1] http://jsfiddle.net/bBESS/4/
> [2] http://lists.w3.org/Archives/Public/www-style/2010Jul/0442.html

The reasoning in that email is somewhat truncated.  A more expanded
version would be:

1. The mod operator, like the / operator, is invalid when the right
operand is 0.
2. We disallowed division by units at this level, so we can determine
whether the math expression is valid at parse-time, since all
divisions have only pure-numeric expressions for their right operand.
3. mod requires both sides to be the same unit; since we disallow mod
by units (by the same reasoning as /), this leaves us with mod only
working between two numbers, which is of extremely minimal utility.
4. Thus, we should exclude mod for now, and add it in when we allow
full unit algebra.

~TJ

Received on Monday, 24 June 2013 01:38:08 UTC