Open hmenke opened 5 years ago
@hmenke, in https://github.com/pgf-tikz/pgf/issues/861#issuecomment-633431073 you stated that LUA is broken. Could you elaborate on this? What do you think the "right" result is of the above expression?
(When I calculate it using Excel I get 1.270132770125
as well.)
As you can see from the image in the first post, the only computation
mode gives a completely wrong result.
Aah, now I see. I thought "only computation" was the result not using Lua (at all).
I had a closer look and it seems that the (large) difference in the output comes from 1.40576^2
and the rest is just a subsequent error. See the red marked entry in the following image. When I replace 1.40576^2
in the expression with the result of the computation from Lua, i.e. 1.9761611776
, then the results are almost identical (the last line in the table marked in green).
When I am not mistaken the "large" difference comes from https://github.com/pgf-tikz/pgf/blob/e0b798ba19471877f80633a727c45e09439344b3/tex/generic/pgf/libraries/luamath/pgflibraryluamath.code.tex#L237-L242
All in all I wouldn't say that "Lua is broken". "Just" only computation
is a bit inaccurate which seems to be explainable from the above comment in the code. 1.40576^2
gives the same result using LaTeX/pgf calculation (only) or using only computation
.
Evaluating the whole expression not using Lua or xfp
results in a Dimension too large
error. And using fpu
then gives a result that is even more off than the only computation
result (which seems to be originated from the sqrt(a)
computation result).
So when it is known that only computation
is "inaccurate", why not (simply) use parser and computation
instead?
@Mo-Gul you confused me for a while as 1.460576^2 is 2.133 not 1.976 you intended 1.40576^2
@davidcarlisle, I am so sorry. Don't know how this typo could happen. I edited my previous post accordingly so that nobody else gets confused too.
@Mo-Gul The comment you linked applies to the line below https://github.com/pgf-tikz/pgf/blob/e0b798ba19471877f80633a727c45e09439344b3/tex/generic/pgf/libraries/luamath/pgflibraryluamath.code.tex#L239-L243 Thanks for debugging this. I'll have a closer look.
I have found part of the problem. pow
is simply not implemented.
https://github.com/pgf-tikz/pgf/blob/e0b798ba19471877f80633a727c45e09439344b3/tex/generic/pgf/libraries/luamath/pgflibraryluamath.code.tex#L307
However, the corresponding Lua code is there. Same for other functions.
https://github.com/pgf-tikz/pgf/blob/e0b798ba19471877f80633a727c45e09439344b3/tex/generic/pgf/libraries/luamath/pgf/luamath/functions.lua#L105-L108
I have to email Christian anyway, so I will ask about that.
Probably the PGF math parser evaluates subexpressions during parsing which leads to a massive loss of precision.