10
\pgfkeys{/pgf/fpu} 

\pgfmathsetlengthmacro\x{5^2}
\show\x -> 25.0pt % OK, thanks.

\pgfmathparse{5cm^2}
  1. What is the meaning of ] in the following?

    \show\pgfmathresult % ->1Y2.0238983e4].
    
    \pgfkeys{/pgf/fpu/output format=sci}
    

    gives the expected format, but what is the cryptic ]?

  2. Why does this fail? Is unit not allowed in {<expr>}? The manual says \pgfmathsetlengthmacro "defines <macro> as the value of <expression> in points."

    \pgfmathsetlengthmacro\y{5cm^2} % ! Illegal unit.
    \pgfmathsetlengthmacro\y{5^2cm} % ! Illegal unit.
    \show\y
    

EDIT

Here is a minimal example:

\documentclass{article}
\usepackage{pgfplots}

\begin{document}
\pgfkeys{/pgf/fpu}
\pgfkeys{/pgf/fpu/output format=sci}
\pgfmathparse{5cm^2}
%\show\pgfmathresult % -> 2.0238983e4.

% Both of these give error:
\pgfmathsetlengthmacro\x{5mm^2}
\pgfmathsetlengthmacro\x{5^2}

\pgfkeys{/pgf/fpu=false}

\end{document}

Error msg:

! Illegal unit of measure (pt inserted).
<to be read again>
                   e
l.10 \pgfmathsetlengthmacro\x{5mm^2}
Ahmed Musa
  • 11,742

1 Answers1

9

The 1Y2.0238983e4] is the internal representation of the number. With fpu you have to explicitly specify the output format or use \pgfmathfloattofixed. The default format is float (with Y and ]), \pgfmathsetlengthmacro is not changed by the fpu library, thus the length is not a valid TeX length with format float. Examples:

\documentclass{article}
\usepackage{pgf}
\usepgflibrary{fpu}

\begingroup
  \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}
  \pgfmathsetlengthmacro\x{5^2}
  \typeout{\x}
\endgroup

\begingroup
  \pgfkeys{/pgf/fpu}
  \pgfmathparse{5^2}
  \pgfmathfloattofixed{\pgfmathresult}
  \edef\x{\pgfmathresult pt}
  \typeout{\x}
\endgroup

\begingroup
  \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}
  \pgfmathparse{5cm^2}
  \typeout{\pgfmathresult}
\endgroup

\begin{document}
\end{document}

Result:

25.0pt
25.000000000pt
20238.983000000000

More details in 36 Floating Point Unit Library.

Heiko Oberdiek
  • 271,626