Narzędzia osobiste

Jesteś w: bachotex2008-david-kastrup-pearl2.tex

# bachotex2008-david-kastrup-pearl2.tex

bachotex2008-david-kastrup-pearl2.tex — TeX document, 1 KB (1268 bytes)

## Zawartość pliku

%%% Is 2in=1in+1in?

\emergencystretch 3em
\def\stripit#1>{}
\def\showx#1{\def\x{#1}{\tt \expandafter\stripit\meaning\x}}

\TeX's arithmetic forgets to round when dealing with units.  For example, 1in
is defined to be exactly 72.27pt.  We can check that by writing
\showx{\dimen0=100in \the\dimen0} and getting \x.  % compile to see what is \x
So far, so good. But when we write \showx{\dimen0=1in \the\dimen0}, we get
\x. Oops. This becomes worse since a number called 72.27pt actually exists,
as witnessed by \showx{\dimen0=72.27pt \the\dimen0} which gives us \x.

So we have the unfortunate situation that {\tt 1in} (which should be
exactly 72.27pt) gives a number different from the number actually
called {\tt 72.27pt}.  This is because \TeX\ truncates when working
with the fractions representing exact units, but rounds when working
with decimal fractions.

\TeX\ calculates {\tt 1in} as
$$\left\lfloor 1\times{7227\over100}\times 2^{16}\right\rfloor2^{-16}$$
namely truncating the fractional calculation rather than rounding it.

Other artifacts of \TeX's fractional representation of units mean that
$\tt 2in \neq 1in+1in$: Indeed \showx{\dimen0=1in \advance\dimen0 1in
\the\dimen0 \dimen0=2in =\the\dimen0} leaves us with \x.
\end


Akcje Dokumentu