8

When I calculate something, sometimes become the interim results to big for the pgf system. One can use the fpu library. I read about it in the TikZ & PGF manual (see page 627), here and here but I still get this error:

Paragraph ended before `\pgfflt@readlowlevelfloat` was complete.

What is wrong?

Here is my code:

\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}

Update:

I'am using a macro from here (thanks to Schrödinger's cat). See my MWE:

\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}

and get still a

Paragraph ended before `\pgfflt@readlowlevelfloat` was complete.

error. What do am I wrong?

Thank you for your help and effort in advance!

6
  • I'm not sure this can be fixed, as pgfmath is constantly converting back and forth between text, dimen registers and fpu registers (which is why I regard it as a dancing bear). Jan 15 '17 at 20:58
  • Hello everybody! Has no one of the professionals a proposal for a solution?
    – Su-47
    Jan 20 '17 at 20:25
  • Note that \pgfkeys{pgf/fpu=false} will not do what it says on the tin unless it has recently been fixed.
    – cfr
    Jan 21 '17 at 2:19
  • 1
    I feel you should ask a new question on this since you got already a nice answer. \foreach[count = \i from 0] \k in {30, 35, ..., 80} { \pgfmathsetmacro{\myval}{\UABmValues[\i]} \pgfmathparseFPU{-25500/(\myval/1000-255/52)-5200-3.0897/8*\k}\i, \pgfmathresult\\ } works. As of now, fpu does not support a couple of things, including integer manipulation, and this kind of list extraction. So you need to extract the entry without fpu.
    – user194703
    Dec 12 '19 at 17:22
  • 1
    @Su-47 I think Alain Matthes answer is good. Please note that none of the systems can really compete with a computer algebra system. A radically new version of TeX would be require to really lift the internal limitations, but AFAIK there is no plan to ever set up a new TeX. Please also note that IMHO it is better to wait using expl3 until it is in a state where you can be sure that what you wrote will still work in a year from now. Since you seem to be using MatLab, you can always produce the data with this tool and then plot it with pgfplots or datavisualization.
    – user194703
    Dec 26 '19 at 15:40
11

Sounds like a job for the 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}

(The convention in expl3 is to index from 1 as this aligns with the most common use case: typesetting. I've therefore indexed the list from one but corrected to index from zero for the equation itself.)

4
  • Hello @Joseph Wright! Thank you for your answer I tested it. 1. Of course it works, but the index variable should begin by zero (for my special purpose). 2. The results of your answer are different. The correct results should look like a downwards parabola see here. Results of your answer looks like a opened upwards parabola. Maybe I do something wrong. 3. Anyway I can't use your answer in my question (see the link above). What do you say?
    – Su-47
    Jan 23 '17 at 12:45
  • 1
    @Su-47 I don't know what you mean about 'the link above'
    – Joseph Wright
    Jan 23 '17 at 16:56
  • 1
    The link in point 2 probably (tex.stackexchange.com/questions/348739/…). Jan 23 '17 at 17:17
  • Hello @Joseph Wright and @Torbjørn T.! Sorry for the long absence. Thank you for your comments. Torbjørn T. is right I meant this link. Now the result is right. But as I said in my last comment, I can't use the above answer to solve my another question (see the link above). If I understand correctly currently there is no way to use arrays and fpu together in TikZ? Is there an another solution, maybe an another data structures as arrays?
    – Su-47
    Jan 28 '17 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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