W3C home > Mailing lists > Public > www-style@w3.org > June 2013

Re: Modulus operator & division by values

From: MaŽl Nison <nison.mael@gmail.com>
Date: Tue, 25 Jun 2013 15:58:02 +0200
Message-ID: <CANiF4iBJwMVOWjCvME6SKU_05k8SVAZ7=sQY97_ue9SVtokotg@mail.gmail.com>
To: "Tab Atkins Jr." <jackalmage@gmail.com>
Cc: www-style list <www-style@w3.org>
Thanks. However, I still don't understand something :

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

Why can't we have a division by units and a parse-time validation of the
expression ? For example, "100px/(43px - 43px)" is invalid and can as
easily be detected as such than "100px/(43 - 43)" (since both of them are
absolute). It seems to me that the main problem is about relative units
such as percentages or em ("100px / 100%" could be invalid at runtime), or
expression derivating from one of those units ("100px / (100px - 100%)").

Also, why should the two operands have the same unit ? Can't the right
operand be coerced into the left operand unit ?


On 24 June 2013 03:37, Tab Atkins Jr. <jackalmage@gmail.com> wrote:

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



-- 
MaŽl Nison
JS Github hipster, Assistant C++ chez Epitech
Received on Tuesday, 25 June 2013 13:58:51 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:39:12 UTC