6

Need to do the calculaions in the tables combining two three values, I had given the codes

\documentclass[11pt,a4paper]{article}
\usepackage{array}
\newcolumntype{L}{>{\centering\arraybackslash}m{3cm}}
\usepackage{amsmath}
\usepackage{graphicx,float}
\usepackage{xcolor}
\usepackage{pgfmath}
\usepackage{calculator}
\usepackage{calculus}
\begin{document}
\flushleft
{\color{blue}
\LARGE{Powerloss Table}
}
\begin{table}[!hbt]
\begin{tabular}{|l|l|l|}\hline
 \pgfmathsetmacro{\tmp}{16383}
            % \pgfmathsetmacro{\tmp}{16384} % Error
Fault type & No of Modules Affected & Approx.power loss(W) \\\hline
    Table & 50 &\pgfmathparse{int(round(50*250))}\pgfmathresult \\\hline
Module & 20 &\pgfmathparse{int(round(20*250))}\pgfmathresult \\\hline
String & 57&\pgfmathparse{int(round(57*84))}\pgfmathresult \\\hline
Total approx. power loss (W) &\pgfmathparse{int(round(50*250)+(20*250)+(57*84))}\pgfmathresult \\\hline
Total approx. power loss (KW) &\pgfmathparse{int(round((50*250)+(20*250)+(57*84)/1000))}\pgfmathresult \\\hline
Total approx. power loss (MW) &\pgfmathparse{int(round((50*250)+(20*250)+(57*84)/1000000))}\pgfmathresult \\\hline
\end{tabular}
\end{table}
\end{document}

....

Getting the errors as

Dimension too large. \pgfmath@x

l.23 ...parse{int(round(50*250)+(20*250)+(57*84))} \pgfmathresult \\hline ? ....

1
  • I've removed the amsmath tag because that package isn't involved. May 21, 2020 at 16:44

2 Answers 2

7

Solution can be found in the answer by Schrödinger's cat. My answer provides some explanations about why you get error Dimension too large.

  • TeX has no built-in floating number representation, and all the dimensions are internally stored in a rather small unit sp, where 1pt = 65536sp. Apart from pgf library fpu and xfp package, LaTeX3 kernel also comes with a l3fp module. (The LaTeX3 kernel has been packed into the LaTeX2e format since LaTeX2e 2020-02-02.)
  • A dimension \maxdimen, initialized to 16383.99999pt, is provided by TeX formats like plainTeX and LaTeX2e to store the largest legal dimension. So the legal dimension range in TeX is [-\maxdimen, \maxdimen]. (Note when you use \the\maxdimen to output the value, you may get 16383.99998pt due to rounding off.)
  • \pgfmathparse uses pt as default unit. So \pgfmathparse{1} and \pgfmathparse{1pt} is the same. This explains why \pgfmathsetmacro{\tmp}{16384} and \pgfmathparseFPU{int(round(50*250)+(20*250)+(57*84))} (50 * 250 * 2 = 25,000 > 16,384) both raise error.
1
  • 1
    I think the answer by Schrödinger's cat is the one should be accepted. My answer only provides some background info. May 21, 2020 at 8:52
7

It is a well known problem that TeX has some maximal dimension. There are various ways to overcome this problem. Here I load the fpu library and switch it on locally. There are various alternatives, including of course the nice xfp package.

\documentclass[11pt,a4paper]{article}
\usepackage{geometry}
\usepackage{array}
\newcolumntype{L}{>{\centering\arraybackslash}m{3cm}}
\usepackage{amsmath}
\usepackage{pgf,pgfmath}
\usepgflibrary{fpu}
\newcommand\pgfmathparseFPU[1]{\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\pgfmathparse{#1}%
\pgfmathsmuggle\pgfmathresult\endgroup}%
\begin{document}
\flushleft
{\color{blue}
\LARGE{Powerloss Table}
}
\begin{table}[!hbt]
\begin{tabular}{|l|l|l|}\hline
 \pgfmathsetmacro{\tmp}{16383}
            % \pgfmathsetmacro{\tmp}{16384} % Error
Fault type & No of Modules Affected & Approx.power loss(W) \\\hline
    Table & 50 &\pgfmathparseFPU{int(round(50*250))}\pgfmathprintnumber\pgfmathresult \\\hline
Module & 20 &\pgfmathparseFPU{int(round(20*250))}\pgfmathprintnumber\pgfmathresult \\\hline
String & 57&\pgfmathparseFPU{int(round(57*84))}\pgfmathprintnumber\pgfmathresult \\\hline
Total approx. power loss (W) & & \pgfmathparseFPU{int(round(50*250)+(20*250)+(57*84))}\pgfmathprintnumber\pgfmathresult \\\hline
Total approx. power loss (KW) && \pgfmathparseFPU{int(round((50*250)+(20*250)+(57*84)/1000))}\pgfmathprintnumber\pgfmathresult \\\hline
Total approx. power loss (MW) &&\pgfmathparseFPU{int(round((50*250)+(20*250)+(57*84)/1000000))}\pgfmathprintnumber\pgfmathresult \\\hline
\end{tabular}
\end{table}
\end{document}

enter image description here

Please note that I added empty columns and also the geometry package because the table is a tiny bit too wide. This is all off-topic, though.

ADDENDUM: Here is a version with different bracketing, with which I get the numbers from your comments.

\documentclass[11pt,a4paper]{article}
\usepackage{geometry}
\usepackage{array}
\newcolumntype{L}{>{\centering\arraybackslash}m{3cm}}
\usepackage{amsmath}
\usepackage{pgf,pgfmath}
\usepgflibrary{fpu}
\newcommand\pgfmathparseFPU[1]{\begingroup%
\pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
\pgfmathparse{#1}%
\pgfmathsmuggle\pgfmathresult\endgroup}%
\begin{document}
\flushleft
{\color{blue}
\LARGE{Powerloss Table}
}
\begin{table}[!hbt]
\begin{tabular}{|l|l|l|}\hline
 \pgfmathsetmacro{\tmp}{16383}
            % \pgfmathsetmacro{\tmp}{16384} % Error
Fault type & No of Modules Affected & Approx.power loss(W) \\\hline
    Table & 50 &\pgfmathparseFPU{int(round(50*250))}\pgfmathprintnumber\pgfmathresult \\\hline
Module & 20 &\pgfmathparseFPU{int(round(20*250))}\pgfmathprintnumber\pgfmathresult \\\hline
String & 57&\pgfmathparseFPU{int(round(57*84))}\pgfmathprintnumber\pgfmathresult \\\hline
Total approx. power loss (W) & & \pgfmathparseFPU{int(round(50*250)+(20*250)+(57*84))}\pgfmathprintnumber\pgfmathresult \\\hline
Total approx. power loss (KW) && \pgfmathparseFPU{((50*250)+(20*250)+(57*84))/1000}\pgfmathprintnumber\pgfmathresult \\\hline
Total approx. power loss (MW) &&\pgfmathparseFPU{(50*250)+(20*250)+(57*84))/1000000}\pgfmathresult \\\hline
\end{tabular}
\end{table}
\end{document}

enter image description here

Notice that

\pgfmathparseFPU{(50*250)+(20*250)+(57*84))/1000000}

divides the whole sum while

\pgfmathparseFPU{int(round((50*250)+(20*250)+(57*84)/1000000))}

divides only the last term (and truncates the result).

5
  • Thank for Your help to get solve this problem, but the last line while I am dividing the whole equation with 1000000 the point values should come to dispaly as the power loss in mw for ex, 0.0228 , but it is coming as 0 for me, can you please help me in this
    – Tamil
    May 21, 2020 at 7:47
  • 1
    @Tamil If you replace \pgfmathprintnumber\pgfmathresult by just \pgfmathresult the result will not be truncated. However, if you use int in the expression of course there won't be digits.
    – user194703
    May 21, 2020 at 7:49
  • 1
    @Tamil Please see my update. I think there is little confusion about how the brackets are to be set.
    – user194703
    May 21, 2020 at 8:01
  • Thank you very much , Now got it with the results, thanks for explaining and solving the problem
    – Tamil
    May 21, 2020 at 8:24
  • 1
    @Tamil You're welcome! While I do not understand why my answer got unaccepted I accept your decision.
    – user194703
    May 21, 2020 at 8:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .