Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.
<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.

share|improve this question
8  
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). –  Mark Wibrow Oct 21 '13 at 12:18
    
@MarkWibrow That deserves to be an answer. :) –  Alenanno Oct 21 '13 at 12:22
    
@MarkWibrow: Thank you! But what does TeX mean by '19 feet'? Can you tell me where can I find that range? –  Ch'en Meng Oct 21 '13 at 12:23
2  
@Ch'enMeng TeX dimen arithmetic is not floating point: it is fixed point, basically it just does 30 bit (+sign bit) integer arithmetic in sp units. –  David Carlisle Oct 21 '13 at 13:50
1  
360pt/100 is 65536*360sp / 100 which will be calculated in integer arithmetic –  David Carlisle Oct 21 '13 at 14:03

1 Answer 1

up vote 14 down vote accepted

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.

share|improve this answer
    
could you (perhaps) add the value of the maximal dimension in the metric system inherited from the French revolution? :) –  jfbu Oct 21 '13 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 –  David Carlisle Oct 21 '13 at 14:29
    
Thank you so much, and hope this quention will help others. :) –  Ch'en Meng Oct 21 '13 at 14:38
1  
Related: some (most?) of these limitations are mentioned in the humorous presentation of Donald E. Knuth –  masu Oct 21 '13 at 22:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.