# pgfplots function x^(0.5) skipping first sample, sqrt is not

In the following example, you will see that the sample at (0,0) is not drawn using x^(0.5) (blue), with sqrt it is (green). How can you explain that?

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[samples at={0,0.02,...,1.5,2}]
\end{axis}
\end{tikzpicture}
\end{document} The sqrt function of the fpu library (which is active in PGFPlots by default) checks for the case sqrt(0), but the pow function does not check for the case 0^x. The pow function uses the equation #1^#2 = exp( #2 * ln(#1) ), so it tries to calculate the logarithm of 0, which fails, so the coordinate is discarded.

The check for 0^x can be added by redefining the \pgfmathfloatpow@ macro as follows:

\makeatletter
\def\pgfmathfloatpow@#1#2{%
\begingroup%
\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
\ifcase\pgfmathfloat@a@S\relax
% 0 ^ #2 = 0
\pgfmathfloatcreate{0}{0.0}{0}%
\else
\expandafter\pgfmathfloat@decompose@tok#2\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
\ifcase\pgfmathfloat@a@S\relax
% #1 ^ 0 = 1
\pgfmathfloatcreate{1}{1.0}{0}%
\or
% #2 > 0
\pgfmathfloatpow@@{#1}{#2}%
\or
% #2 < 0
\pgfmathfloatpow@@{#1}{#2}%
\or
% #2 = nan
\edef\pgfmathresult{#2}%
\or
% #2 = inf
\edef\pgfmathresult{#2}%
\or
% #2 = -inf
\pgfmathfloatcreate{0}{0.0}{0}%
\fi
\fi
\pgfmath@smuggleone\pgfmathresult
\endgroup
}%
\makeatother


It might be worth filing a bug report for this.

Your example could be fixed like this:

\documentclass{standalone}
\usepackage{pgfplots}

\makeatletter
\def\pgfmathfloatpow@#1#2{%
\begingroup%
\expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
\ifcase\pgfmathfloat@a@S\relax
% 0 ^ #2 = 0
\pgfmathfloatcreate{0}{0.0}{0}%
\else
\expandafter\pgfmathfloat@decompose@tok#2\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
\ifcase\pgfmathfloat@a@S\relax
% #1 ^ 0 = 1
\pgfmathfloatcreate{1}{1.0}{0}%
\or
% #2 > 0
\pgfmathfloatpow@@{#1}{#2}%
\or
% #2 < 0
\pgfmathfloatpow@@{#1}{#2}%
\or
% #2 = nan
\edef\pgfmathresult{#2}%
\or
% #2 = inf
\edef\pgfmathresult{#2}%
\or
% #2 = -inf
\pgfmathfloatcreate{0}{0.0}{0}%
\fi
\fi
\pgfmath@smuggleone\pgfmathresult
\endgroup
}%
\makeatother

\begin{document}
\begin{tikzpicture}
\begin{axis}[samples at={0,0.02,...,1.5,2}]
\end{axis}
\end{tikzpicture}
\end{document}


This has already been fixed; an upgrade to PGF 3.0.0 will remove the problem.

Here is your input file with PGF 3.0.0 : The associated lines in the PGF change log are

2013-08-24 Christian Feuersaenger <cfeuersaenger@[xxxxx]net>

- fixed bug in fpu: 0^0 and 0^x both produced nan. Now we get
0^0=1 and 0^x = 0.