# Re: [css3-values] calc() division with units

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Wed, 29 May 2013 08:36:44 -0700
Message-ID: <CAAWBYDAWY9jGJ25b4K+X7zJPofJgr=mQ1h5QiEwv_UceYGuaKQ@mail.gmail.com>
To: John Mellor <johnme@chromium.org>
Cc: www-style list <www-style@w3.org>
On Wed, May 29, 2013 at 6:51 AM, John Mellor <johnme@chromium.org> wrote:
> Some interesting use cases for calc() currently seem impossible due to the
> way units work when dividing values.
>
> For example to (roughly) estimate the height of a long line of text which
> has wrapped on a narrow screen, you need to divide the total width of the
> line of text by the viewport width. Supposing you know the text contains 237
> characters:
>
> number of lines ~= 237ex / 100vw
>
>
> So if your line-height is 1.2em, you might try to estimate the wrapped
> height using:
>
> height: calc(237ex / 100vw * 1.2em)
>
>
> Mathematically, this is fine, as <length>/<length>*<length> == <length>.
>
> But 8.1.2. Type Checking for '/' requires "check that the right side is
> <number>", and so this expression is (unnecessarily) deemed invalid.
>
> Can we relax this requirement, and just require the final computed value to
> be of an appropriate type?

Full unit algebra was more complicated than deemed necessary for level
1 of calc(), especially since it creates opportunities for
division-by-zero that can't be determined at parse time.  (Right now,
the only way to get a division by zero is to use a literal zero or a
purely numeric expression that evaluates to zero, which can be
determined immediately.)

We do plan to try and do unit algebra in the next version of the
Values spec, though.

~TJ
Received on Wednesday, 29 May 2013 15:37:35 UTC

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