[Tex/LaTex] Origin and formation to the ERROR ‘Dimension too large’


When I tried to compile:

\draw[very thin, red] (0,0) circle (2);
\foreach \i in {0, 1, 2, ..., 46} \draw[very thin, red] ({360 * \i / 100}:1) circle (1);

I got:

! Dimension too large.
<recently read> \pgfmath@x 

l.6 ...thin, red] ({360 * \i / 100}:1) circle (1);

I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

And if I turn 46 to 45, say \foreach \i in {0, 1, 2, ..., 45}, that code will pass the compiling.

It seems that some value I was trying to calculate is larger than the TeX engine can handle.

After searching TeX.SX for about half an hour, I got this, this and this. These questions have been solved, however, the origin and structure of the problem still remain unclear. Hence, I decide to raise this question: what is the limit (its origin and formation), and how can I avoid it.

Any clues would be appreciated.

Best Answer

TeX dimen arithmetic is fixed point arithmetic, based on integer arithmetic of scaled points sp. 2^{16}sp=65536sp=1pt .

The maximum dimension that may be stored is saved in plain TeX and LaTeX as \maxdimen and is 2^{30}sp = 16384pt ~ 18.9ft.

Basic arithemetic (as implemented by \dimexpr for example) each subterm in the calculation, not just the final answer, needs to be within +/- \maxdimen.

Floating point packages such as fp or l3fp can handle floating point values and larger ranges but do so by avoiding TeX dimen registers and maintaining the values in macros and doing the calculations "by hand".

As well as limiting the absolute value this conversion to integer sp arithmetic limits the accuracy, for example 360/100 will be coded as 360pt/100 is 65536*360sp / 100 which already in integer arithmetic can not be calculated exactly. For use in typesetting measurements rounding error of a few sp are literally invisible to the eye so irrelevant however if TeX arithmetic is used for more extensive calculations these issues can arise, as you found.

Related Question