Menu

#243 pow broken for non-integer bases and exponents

v1.0 (example)
closed-works-for-me
nobody
None
5
2013-07-15
2013-05-04
Edwin
No

Example:

\documentclass{article}
\usepackage{amsmath,tikz}
\begin{document}
\parindent=0em
\pgfmathsetmacro\result{pow(0.5,1.5)}
$(\tfrac12)^{3/2}\ne\result=2\sqrt2$\\
\pgfmathsetmacro\result{pow(0.5,0.5)}
$(\tfrac12)^{1/2}\ne\result=\sqrt2?$\\
\pgfmathsetmacro\result{pow(0.5,-1.5)}
$(\tfrac12)^{-3/2}\ne\result=2\sqrt2$\\
\pgfmathsetmacro\result{pow(0.5,-0.5)}
$(\tfrac12)^{-1/2}\ne\result=\sqrt2?$\\
\end{document}

Discussion

  • Hideki Isozaki

    Hideki Isozaki - 2013-07-03

    I also noticed a similar problem independently: pow(0.1, 0.5) = 3.1601, which should be
    0.3162..

    It must be a new problem because I encountered this problem when I updated TikZ/PGF.

    pow(0.1, 0.5) calls exp(-1.15063).
    At the end of \pgfmathdeclarefunction{exp},
    \pgfmathreciprocal@ is called if exp's #1 is negative.
    However, #1's value becomes positive during exp's execution,
    and reciprocal is not called.

    I have not found the true cause of this new bug, but
    I fixed this by changing the definition of pow
    in pgfmathfunctions.basic.code.tex as follows.

    At the end of \pgfmathdeclarefunction{pow}{2}{...},
    you can find \pgfmathexp@{\pgfmath@tonumber{\pgfmath@x}}.

    Please replace this line with the following two lines:
    \edef\pgf@fixedvalue{\pgfmath@tonumber{\pgfmath@x}}
    \pgfmathex@{\pgf@fixedvalue}

     
  • Hideki Isozaki

    Hideki Isozaki - 2013-07-03

    I also noticed a similar problem independently: pow(0.1, 0.5) = 3.1601, which should be
    0.3162..

    It must be a new problem because I encountered this problem when I updated TikZ/PGF.

    pow(0.1, 0.5) calls exp(-1.15063).
    At the end of \pgfmathdeclarefunction{exp},
    \pgfmathreciprocal@ is called if exp's #1 is negative.
    However, #1's value becomes positive during exp's execution,
    and reciprocal is not called.

    I have not found the true cause of this new bug, but
    I fixed this by changing the definition of pow
    in pgfmathfunctions.basic.code.tex as follows.

    At the end of \pgfmathdeclarefunction{pow}{2}{...},
    you can find \pgfmathexp@{\pgfmath@tonumber{\pgfmath@x}}.

    Please replace this line with the following two lines:
    \edef\pgf@fixedvalue{\pgfmath@tonumber{\pgfmath@x}}
    \pgfmathexp@{\pgf@fixedvalue}

     
  • Till Tantau

    Till Tantau - 2013-07-15
    • status: open --> closed-works-for-me
    • Group: --> v1.0 (example)
     
  • Till Tantau

    Till Tantau - 2013-07-15

    In the CVS, pow seems to work correctly.

     
MongoDB Logo MongoDB