# Origin and formation to the ERROR ‘Dimension too large’

When I tried to compile:

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\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);
\end{tikzpicture}
\end{document}


I got:

! Dimension too large.

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.

• By default TikZ uses TeX dimensions, and dimensions must be in the range -16384 < x < 16384. It doesn't matter if the result of the entire calculation is in this range. If the range is exceeded at any point there will be an error. In this case you can reorder the calculation: (\i/100*360:1). Oct 21, 2013 at 12:18
• @MarkWibrow That deserves to be an answer. :) Oct 21, 2013 at 12:22
• @MarkWibrow: Thank you! But what does TeX mean by '19 feet'? Can you tell me where can I find that range? Oct 21, 2013 at 12:23
• @Alenanno: Absolutely! But I want to know more. :) Oct 21, 2013 at 12:24
• Change the order of operations: replace ({360 * \i / 100}:1) with ({ \i / 100 * 360}:1) Oct 21, 2013 at 12:28

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.

• could you (perhaps) add the value of the maximal dimension in the metric system inherited from the French revolution? :)
– user4686
Oct 21, 2013 at 14:23
• @jfbu I only ever think of it in pt but there was a question about feet from the OP:-) but \maxdimen is ~ 5758.3mm Oct 21, 2013 at 14:29
• Related: some (most?) of these limitations are mentioned in the humorous presentation of Donald E. Knuth
– masu
Oct 21, 2013 at 22:34