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}]
\addplot[green,thick]{sqrt(x)};
\addplot[blue,thick]{x^0.5};
\end{axis}
\end{tikzpicture}
\end{document}