当我计算某些东西时,有时中间结果对于系统来说太大了pgf
。可以使用fpu
库。我在TikZ & PGF
手动的(见第 627 页),这里和这里但我仍然收到此错误:
Paragraph ended before `\pgfflt@readlowlevelfloat` was complete.
怎么了?
这是我的代码:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{fpu}
\begin{document}
%data values:
\def\RTable{{100,100.391,100.781,101.172,101.562,101.953,102.343,102.733,103.123,103.513,103.903,104.292,104.682,105.071,105.46,105.849,106.238,106.627,107.016,107.405,107.794,108.182,108.57,108.959,109.347,109.735,110.123,110.51,110.898,111.286,111.673,112.06,112.447,112.835,113.221,113.608,113.995,114.382,114.768,115.155,115.541,115.927,116.313,116.699,117.085,117.47,117.856,118.241,118.627,119.012,119.397,119.782,120.167,120.552,120.936,121.321,121.705,122.09,122.474,122.858,123.242,123.626,124.009,124.393,124.777,125.16,125.543,125.926,126.309,126.692,127.075,127.458,127.84,128.223,128.605,128.987,129.37,129.752,130.133,130.515,130.897}}
%prints the result to the console:
\pgfkeys{/pgf/fpu}
\foreach \i in {0, ..., 80}
{
\pgfmathparse{abs(\RTable[\i] - 100 - 3.0897 / 8 * \i)}\i, \pgfmathresult\\
}
\pgfkeys{/pgf/fpu=false}
\end{document}
更新:
\documentclass{scrartcl}
\usepackage{tikz}
\usetikzlibrary{fpu}
\newcommand\pgfmathparseFPU[1]{
\begingroup
\pgfkeys{
/pgf/fpu,
/pgf/fpu/output format = fixed
}
\pgfmathparse{#1}
\pgfmathsmuggle
\pgfmathresult
\endgroup}
\begin{document}
%data values:
\def\UABmValues{{14.9, 15.8, 17.7, 18.3, 19, 20, 21.1, 22.2, 24.3, 26.9, 30.1}}
%prints the result to the console:
\foreach[count = \i from 0] \k in {30, 35, ..., 80}
{
\pgfmathparseFPU{-25500 / (\UABmValues[\i] / 1000 - 255 / 52) - 5200 - 3.0897 / 8 * \k}\i, \pgfmathresult\\
}
\end{document}
并得到
Paragraph ended before `\pgfflt@readlowlevelfloat` was complete.
错误。我错在哪里?
提前感谢您的帮助和努力!
答案1
听起来像是 LaTeX3 FPU 的工作:
\documentclass{article}
\usepackage{expl3}
\ExplSyntaxOn
\cs_new_eq:NN \fpeval \fp_eval:n
\cs_new_eq:NN \clistitem \clist_item:Nn
\cs_new_eq:NN \foreachint \int_step_inline:nnnn
\ExplSyntaxOff
\begin{document}
%data values:
\def\RTable{100,100.391,100.781,101.172,101.562,101.953,102.343,102.733,103.123,103.513,103.903,104.292,104.682,105.071,105.46,105.849,106.238,106.627,107.016,107.405,107.794,108.182,108.57,108.959,109.347,109.735,110.123,110.51,110.898,111.286,111.673,112.06,112.447,112.835,113.221,113.608,113.995,114.382,114.768,115.155,115.541,115.927,116.313,116.699,117.085,117.47,117.856,118.241,118.627,119.012,119.397,119.782,120.167,120.552,120.936,121.321,121.705,122.09,122.474,122.858,123.242,123.626,124.009,124.393,124.777,125.16,125.543,125.926,126.309,126.692,127.075,127.458,127.84,128.223,128.605,128.987,129.37,129.752,130.133,130.515,130.897}
%prints the result to the console:
\foreachint{1}{1}{81}{%
#1,
\fpeval{abs(\clistitem\RTable{#1} - 100 - 3.0897 / 8 * (#1 - 1))}\\
}
\end{document}
(惯例expl3
是从 1 开始索引,因为这与最常见的用例一致:排版。因此,我从一开始对列表进行索引,但对于等式本身将其更正为从零开始索引。)