[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Groff] Arithmetic of Units

From: Michael Witten
Subject: [Groff] Arithmetic of Units
Date: Fri, 15 Oct 2010 13:08:03 -0700 (PDT)

According to:

  info '(groff)Default Units'

we have:

  5.2.1 Default Units
  Many requests take a default unit. While this can be
  helpful at times, it can cause strange errors in some
  expressions. For example, the line length request
  expects em units. Here are several attempts to get a
  line length of 3.5 inches and their results:
       3.5i      =>   3.5i
       7/2       =>   0i
       7/2i      =>   0i
       (7 / 2)u  =>   0i
       7i/2      =>   0.1i
       7i/2u     =>   3.5i
  Everything is converted to basic units first. In the
  above example it is assumed that 1i equals 240u, and
  1m equals 10p (thus 1m equals 33u). The value 7i/2 is
  first handled as 7i/2m, then converted to 1680u/66u
  which is 25u, and this is approximately 0.1i. As
  can be seen, a scaling indicator after a closing
  parenthesis is simply ignored.

     Thus, the safest way to specify measurements is
  to always attach a scaling indicator. If you want to
  multiply or divide by a certain scalar value, use `u'
  as the unit for that value.

This is apparently documenting arithmetic bugs that have
since become features. That is, under reasonable rules of
arithmetic, one would expect:

  3.5i     => 3.5i
  7/2      => 3.5                <--- Dimensionless
  7/2i     => (7/2)i  => 3.5i    <--- precedence gives (7/2)i, not 7/(2i)
  (7 / 2)u => 3.5u
  7i/2     => 3.5i
  7i/2u    => ((7i)/2)u => 3.5iu <--- WTF?

Even if you wanted to change the precedence rule with regard
to units, the results are still repulsive:

  7/2i  => 7/(2i)     => 3.5/i                  <--- Meaningless
  7i/2u => (7i)/(2u)  => (7*240u)/(2u) => 840   <--- Dimensionless

Even if you wanted to give units to each dimensionless number
before reducing the expression, the results are still repulsive
(particularly because the units of the reduction wouldn't make
any sense). Using the example:

  7i/2 => (7i)/(2m)  => (1680u)/(66u) => 25.4545...  <--- Dimensionless

or something else:

  2*2*7i/2 => (2m)*(2m)*(7i)/(2m) => 110880 u^2      <--- WTF?

Even if you wanted to force a meaningful unit on the final
reduction of an expression, the example above is incorrect:

  7/2  => (7m)/(2m) => (231u)/(66u) => 3.5 => 3.5u   <--- not 0

What is going on here?
Please correct me!

Michael Witten

reply via email to

[Prev in Thread] Current Thread [Next in Thread]