# PGF Dimension too large

I am trying to create mental math worksheets that extend math facts from 6*7=___ to something like 6*700000=_________.

Apparently, though PGF and/or TeX cannot handle numbers bigger than around 16000. [I find this bizarre; it strikes me as the kind of problem a computer programmer might have run into in 1953.]

What is the easiest fix for this?

I've found two related threads (link 1, link 2). I'm wondering if I should:

1. Stick to those threads and start fiddling around with \ifnum counters, \exp13, and \fpeval, etc. [no idea what these are]. The explanations in the thread were a little jargon-rich for me, but I can handle it. It would take a while, but it's how I've learned a lot of LaTeX, TikZ, and PGF so far.
2. Find another resource to tell me what those commands do.
3. Search for some easier third way to program worksheets to handle these (fairly trivial) calculations.

Thanks!

This code does not compile when \PowerOfTen becomes so big that other numbers exceed ~16000.

\documentclass{article}

\usepackage{pgf}
\pgfmathsetseed{\number\pdfrandomseed}

\newcommand{\InitVariables}
{\pgfmathrandominteger{\FactorA}{1}{10}
\pgfmathdeclarerandomlist{PowerOfTen}{{1}{10}{100}{1000}{10000}}
\pgfmathrandomitem{\PowerOfTen}{PowerOfTen}
\xdef\PowerOfTen{\PowerOfTen}
\pgfmathrandominteger{\FactorBInteger}{1}{10}
\pgfmathsetmacro{\FactorB}{int(\FactorBInteger*\PowerOfTen)}
\pgfmathsetmacro{\Product}{int(\FactorA*\FactorB)}
}

\setlength{\parindent}{0cm}

\begin{document}

\section*{Scaled Up Times Tables Exercises}

\InitVariables

FactorA = \FactorA

FactorBInteger= \FactorBInteger

PowerOfTen = \PowerOfTen

FactorB = \FactorB

FactorA x FactorB = Product

$$\FactorA\times\FactorB=\Product$$

\end{document}


## 1 Answer

You can turn on the Floating Point Unit Library for extra precision (Chapter 54 of the current PGF manual).

\documentclass{article}
\usepackage{pgf}
\usepgflibrary{fpu}

\pgfmathsetseed{\number\pdfrandomseed}

\newcommand{\InitVariables}{
\pgfkeys{/pgf/fpu}
% OPTIONAL: Output format: float, sci, fixed
% DEFAULT: float
\pgfkeys{/pgf/fpu/output format=float}
\pgfmathrandominteger{\FactorA}{1}{10}%
\pgfmathdeclarerandomlist{PowerOfTen}{{1}{10}{100}{1000}{10000}}%
\pgfmathrandomitem{\PowerOfTen}{PowerOfTen}%
\pgfmathrandominteger{\FactorBInteger}{1}{10}%
\pgfmathsetmacro{\FactorB}{int(\FactorBInteger*\PowerOfTen)}%
\pgfmathsetmacro{\Product}{int(\FactorA*\FactorB)}%
% These two will only work with output format=float, otherwise comment out
\pgfmathfloattoint{\FactorB}\pgfmathresult\let\FactorB\pgfmathresult%
\pgfmathfloattoint{\Product}\pgfmathresult\let\Product\pgfmathresult%
\pgfkeys{/pgf/fpu=false}%
}

\setlength{\parindent}{0cm}

\begin{document}

\section*{Scaled Up Times Tables Exercises}

\InitVariables

FactorA = \FactorA

FactorBInteger= \FactorBInteger

PowerOfTen = \PowerOfTen

FactorB = \FactorB

FactorA x FactorB = \Product

$$\FactorA\times\FactorB=\Product$$

\end{document} it strikes me as the kind of problem a computer programmer might have run into in 1953.

Well add two-ish more decades and TeX is that old.

• Haha, you beat me to the punch by 10 seconds. Ah well, I shall remove my answer then; seems a slight bit redundant now. As a side note for OP: The FPU library is documented in Chapter 54 of the PGF manual. – alpenwasser Dec 28 '17 at 8:37
• @alpenwasser Oh sorry I didn't see. I can delete this as well since you also have the output format part. Would you care combining these answers? I'm too lazy for that in the holiday season eheh. I absolutely have no problem with it. Please let me know – percusse Dec 29 '17 at 11:01
• No problem at all; I've added the output format remark to your answer to combine the two. There was one pecular thing though: When trying to compile your code (without the output format stuff -- just copy-pasted as-was), I needed to remove the \show commands from the two \pgfmathfloattoint lines, otherwise it refused compile (using pdflatex on Linux, PGF version 3.0.1a). Not sure if I'm doing something wrong there since it seemed to have worked fine for you. – alpenwasser Dec 29 '17 at 22:19
• @alpenwasser I've just forgotten to remove them. Thank you – percusse Dec 29 '17 at 23:01
• Thanks! First question: When I copy the code exactly, \FactorB and \Product are both printed right below the section header. Why? – WeCanLearnAnything Dec 30 '17 at 15:38