error in `\pgfmath@basic@pow@` with non-integer exponent
When fpu is loaded, it saves the TeX-register-based math routines \pgfmath<name>@ under the names \pgfmath@basic@<name>@, where they can still be accessed. However, this does not seem to work as expected with \pgfmath@basic@pow@:
Minimal working example (MWE)
\input pgf
\usepgflibrary{fpu}
\pgfkeys{/pgf/fpu}
\catcode`@=11
% these are okay:
\pgfmathpow{0.4}{2.1}
\pgfmath@basic@pow@{0.4}{2.0}
% this causes fpu to complain:
\pgfmath@basic@pow@{0.4}{2.1}
\end
! Package PGF Math Error: Sorry, an internal routine of the floating point unit
got an ill-formatted floating point number `0.4'. The unreadable part was near
'0.4'...
Maybe this is because \pgfmath@basic@pow@ still invokes \pgfmathln@ when the exponent is not an integer, but \pgfmathln@ has at this point been replaced with \pgfmathfloatln@?
Maybe this is because
\pgfmath@basic@pow@still invokes\pgfmathln@when the exponent is not an integer, but\pgfmathln@has at this point been replaced with\pgfmathfloatln@?
Sounds likely but \pgfmath@basic@... are internal functions (as the @ suggests) and therefore not part of the user interface. Why are you trying to use them?
Maybe this is because
\pgfmath@basic@pow@still invokes\pgfmathln@when the exponent is not an integer, but\pgfmathln@has at this point been replaced with\pgfmathfloatln@?
After expanding \pgfmath@basic@pow@{0.4}{2.1} using unravel package and checking the definition of function pow. Yes, it is.
\pgfmath@basic@...are internal functions (as the@suggests) and therefore not part of the user interface. Why are you trying to use them?
I am writing a package and would like to use pgf's maths engine for some computations. The package does not depend on fpu, but I would like it not to break when it is loaded together with fpu, and so have included checks to use the \pgfmath@basic@<name>@ macros in place of \pgfmath<name>@ when fpu is loaded—this is where I encountered the error.
I am writing a package and would like to use
pgf's maths engine for some computations.
Going off on a bit of a tangent, but why don't you use LaTeX3's FPU? This works:
\input expl3-generic
\ExplSyntaxOn
\cs_new_eq:NN \fpeval \fp_eval:n
\ExplSyntaxOff
\fpeval{0.4^2.1}
\fpeval{0.4^2.0}
\end
Is your package a PGF/TikZ library? If not, you are probably better served by xfp (as pointed out by Phelype Oleinik).
Going off on a bit of a tangent, but why don't you use LaTeX3's FPU? This works:
This looks lovely. I must admit I'm not as familiar as I would like with LaTeX, 2ε or 3, so thank you for pointing out this option to me! I think either using the expl3 fpu, or even sticking with pgf and simply reformulating my computations to avoid pow in favour of exp and ln, would suffice for what I am trying to do.
Is your package a PGF/TikZ library? If not, you are probably better served by
xfp(as pointed out by Phelype Oleinik).
It's currently being implemented as a pgf library that declares some functions to be recognised by pgfmath.
In any case, even though this issue is not something that would trouble the user who interacts only with the "public" \pgfmath<name> macros & \pgfmathparse, I'd like to mention that the access to the TeX-register maths routines as \pgfmath@basic@<name>@ for package/library authors is advertised in the FPU section in the pgf manual, so this issue is indeed something one can come across without doing a Bad Thing and writing code that depends on undocumented implementation details :(