\pgfmathsetmacro - dimension too large (biggest value allowed?)
You can use the fpu
library that ships with TikZ
and that pgfplots
uses internally. It allows calculations in the range from -1*10^324 to 1*10^324:
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfkeys{/pgf/fpu}
\pgfmathparse{16383+1}
\edef\tmp{\pgfmathresult}
\pgfkeys{/pgf/fpu=false}
\begin{tikzpicture}[declare function={test(\tmp) = x/\tmp;}]
\begin{axis}[samples=100,domain=0:1]
\addplot (x,{test(\tmp)});
\end{axis}
\end{tikzpicture}
\end{document}
From the pgf manual 2.10csv page 694:
It should be noted that all calculations must not exceed ±16383.99999 at any point, because the underlying computations rely on TeX dimensions. This means that many of the underlying computations are necessarily approximate and that in addition, are not very fast. TeX is, after all, a typesetting language and not ideally suited to relatively advanced mathematical operations. However, it is possible to change the computations as described in Section 76.
From the TeX Book page 114:
16383.99998 pt (TeX’s largest dimen)
In Notes On Programming in TeX Chirstian Feuersänger pointed out
The
\dimen
registers perform their arithmetic’s internally with 32 bit scaled integers, so called ‘scaled point’ with unitsp
. It holds 1 pt = 65536 sp = 216 sp. One of the 32 bits is used as sign. The total number range in pt is [−(230 − 1)/216, (230 − 1)/216 ] = [−16383.9998, +16383.9998]1.1 Please note that this does not cover the complete range of a 32 bit integer, I do not know why
I want to note my old question "Missing number" error using `\pgfmathsetmacro` with the `ifthenelse` operator, in which I observed another inconsistency in \pgfmathsetmacro
. Effectively, according to the accepted answer, this command can only set the macro in question to a TeX dimensions. Thus, it is constrained by the limitations of TeX arithmetic in addition to the limitations of being numerical in the first place. In particular, your code would work with the construct \pgfmathparse{16384}\let\tmp\pgfmathresult
even though that value exceeds TeX's capabilities, because pgfplots
uses the floating-point library and handles big numbers.