- status: open --> closed-fixed
- Group: --> v1.0 (example)
\pgfmathpow{0}{\x} should return 0 for all values of \x. However, when \x holds a non-integer value, the following error is thrown:
! Package PGF Math Error: I cannot calculate the logarithm of `0'.
Minimal example:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfmathpow{0}{0.5}
\end{document}
The pow function could be fixed using a check for base values of 0:
\pgfmathdeclarefunction{pow}{2}{%
\begingroup%
\pgfmath@xa=#1pt%
\pgfmath@xb=#2pt%
\ifdim\pgfmath@xa=0pt
\pgfmath@x=0pt\relax
\else
\afterassignment\pgfmath@x%
\expandafter\c@pgfmath@counta\the\pgfmath@xb\relax%
\ifnum\c@pgfmath@counta<0\relax%
\c@pgfmath@counta=-\c@pgfmath@counta%
\pgfmathreciprocal@{#1}%
\pgfmath@xa=\pgfmathresult pt\relax%
\fi
\ifdim\pgfmath@x=0pt\relax%
\pgfmath@x=1pt\relax%
\pgfmathloop%
\ifnum\c@pgfmath@counta>0\relax%
\ifodd\c@pgfmath@counta%
\pgfmath@x=\pgfmath@tonumber{\pgfmath@x}\pgfmath@xa%
\fi
\ifnum\c@pgfmath@counta>1\relax%
\pgfmath@xa=\pgfmath@tonumber{\pgfmath@xa}\pgfmath@xa%
\fi%
\divide\c@pgfmath@counta by2\relax%
\repeatpgfmathloop%
\else%
\pgfmathln@{#1}%
\pgfmath@x=\pgfmathresult pt\relax%
\pgfmath@x=\pgfmath@tonumber{\pgfmath@xb}\pgfmath@x%
\pgfmathexp@{\pgfmath@tonumber{\pgfmath@x}}%
\pgfmath@x=\pgfmathresult pt\relax%
\fi%
\fi
\pgfmath@returnone\pgf@x%
\endgroup%
}
Till Tantau
2013-07-16
Till Tantau
2013-07-16
Fixed in CVS, although the suggested change does not quite work: 0^0 == 1, so that has to be tested in addition.