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}
{
\pgfmathsetmacro{\UABmValues}{\UABmValues[\i]}
\pgfmathparseFPU{-25500 / (\UABmValues / 1000 - 255 / 52) - 5200 - 3.0897 / 8 * \k}\i, \pgfmathresult\\
}
\end{document}
Gives:
- 4.414001000000000
- 3.483002000000000
- 3.652002000000000
- 2.221002000000000
- 0.990002
- 0.159003
- -0.571997
- -1.302997000000000
- -1.033997000000000
- -0.064996
- 1.304004000000000
When I do the same, let say, with MATLAB:
UABmValues = [14.9 15.8 17.7 18.3 19 20 21.1 22.2 24.3 26.9 30.1];
R = 30 : 5 : 80;
%prints the result to the console:
for j = 1 : 11
result = -25500 / (UABmValues(j) / 1000 - 255 / 52) - 5200 - 3.0897 / 8 * R(j);
fprintf('j=%d, ', j)
fprintf('%d.\n', result)
end
Than I get following:
- 4.261621e+00.
- 3.290914e+00.
- 3.388431e+00.
- 2.098301e+00.
- 9.151911e-01.
- 5.300458e-02.
- -7.017887e-01.
- -1.456052e+00.
- -1.139024e+00.
- -2.840543e-01.
- 1.217927e+00.
The difference is huge.
Why is it so? Any suggestions how to solve it with fpu, if at least possible?
Thank you for your help and effort in advance!




\dimenregisters for calculations, so it has the same accuracy restrictions. The smallest representable difference in a TeX\dimenis1sp, which is0.00002pt(try\the\dimexpr1sp\relax). If you need more accuracy, try the LaTeX3 FPU (loaded by thexfppackage). – Phelype Oleinik Dec 26 '19 at 12:32fphas a higher accuracy than the LaTeX3 FPU. (The latter conforms to the IEEE-754 standard, accurate to 16 significant digits or so). Butxfp(and Lua, for that matter) is fully expandable, whilefpis not. I'm not sure about Lua's accuracy. But my job description is to advertiseexpl3, so I had to suggest that ;-) – Phelype Oleinik Dec 26 '19 at 13:19xfpis fully expandable. I usefpbecause it was the only solution several years ago.I think you have wit lua IEEE 754 double precision floating point – Alain Matthes Dec 26 '19 at 14:42