
%\input pgfplotsoldpgfsupp_pgfmathparse.opt.code.tex
%\beginpgfmathparsecheckfornumber

\pgfutil@ifundefined{pgfmathlessthan@}{%
	\let\pgfmathlessthan@=\pgfmathless@
	\let\pgfmathgreaterthan@=\pgfmathgreater@
}{}%


\def\pgfplotsusecompatibilityfile#1{%
	\pgfutil@IfUndefined{pgfplotsusecompatibilityfile@loaded@#1}{%
		\expandafter\gdef\csname pgfplotsusecompatibilityfile@loaded@#1\endcsname{1}%
		\input pgfplotsoldpgfsupp_#1
	}{%
		% already loaded.
	}%
}%


\def\pgfmathfloatrounddisplaystyle@shared@impl@WRONG#1#2{%
	{\toks0={#1}%
	\toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}%
	\xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
	}%
	\let\pgfmathresult=\pgfmathfloat@glob@TMP
}%

% check whether we need to load supplementary code.
% The development of pgfplots and pgf is intermingled, so pgfplots
% always uses up-to-date pgf CVS versions - the relevant complements between
% PGF 2.10 and PGF CVS are loaded here:
%
% #1: for backwards compatibility
% #2: for normal processing.
\def\pgfplots@ifneedspgfcompabitibilitycode@has@pgf@one@zero@zero#1#2{%
	%\pgfkeysifdefined{/pgf/number format/sci precision/.@cmd}{#2}{#1}%
	\pgfutil@ifundefined{pgfmathprintnumber@RELATIVE@choice@roundtofixed}{#1}{#2}%
}%

\let\pgfplots@ifneedspgfcompabitibilitycode=\pgfplots@ifneedspgfcompabitibilitycode@has@pgf@one@zero@zero

\pgfplots@ifneedspgfcompabitibilitycode
	{%
		\immediate\write16{Package pgfplots: loading complementary code for your PGF version...}
		\input pgfplotsoldpgfsupp_misc.code.tex
		\let\pgfkeysloaded=\undefined
		\input pgfplotsoldpgfsupp_pgfkeys.code.tex
		\input pgfplotsoldpgfsupp_pgfmathfloat.code.tex
		\input pgfplotsoldpgfsupp_pgflibraryplothandlers.code.tex
		\input pgfplotsoldpgfsupp_pgflibraryfpu.code.tex
		\input pgfplotsoldpgfsupp_pgfcorescopes.code.tex
		\input pgfplotsoldpgfsupp_pgfcorelayers.code.tex
	}%
	{%
		\pgfplots@iffileexists{pgflibraryfpu.code.tex}{%
			\usepgflibrary{fpu}%
		}{%
			\immediate\write16{Package pgfplots: loading FPU library which doesn't appear to exist in your PGF version...}
			\input pgfplotsoldpgfsupp_pgflibraryfpu.code.tex
		}%
	}%

\gdef\pgfplots@glob@TMPa{0}%

\def\pgfmathfloatfloor@broken#1{%
	\edef\pgfmathfloat@loc@TMPa{#1}%
	\pgfmathfloatcreate{2}{5.0}{-1}% -0.5
	\let\pgfmathfloat@loc@TMPb=\pgfmathresult
	\pgfmathfloatadd@{\pgfmathfloat@loc@TMPa}{\pgfmathfloat@loc@TMPb}%
	\expandafter\pgfmathfloatround@\expandafter{\pgfmathresult}%
}
\ifx\pgfmathfloatfloor\pgfmathfloatfloor@broken
	\gdef\pgfplots@glob@TMPa{1}%
\fi

\def\pgfmathfloor@broken#1{%
	\begingroup%
		\expandafter\pgfmath@x#1pt\relax%
		\afterassignment\pgfmath@gobbletilpgfmath@%
		\expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@%
		\expandafter\pgfmath@x#1pt\relax%
		\ifdim\pgfmath@x<0pt\relax%
			\advance\c@pgfmath@counta by -1\relax%
		\fi%
		\pgfmath@x\c@pgfmath@counta pt\relax%
		\pgfmath@returnone\pgfmath@x%
	\endgroup%
}%
\ifx\pgfmathfloor@\pgfmathfloor@broken
	\def\pgfmathfloor@#1{%
		\begingroup%
			\expandafter\pgfmath@x#1pt\relax%
			\afterassignment\pgfmathfloor@collect@remainder%
			\expandafter\c@pgfmath@counta\the\pgfmath@x\pgfmath@%
			\expandafter\pgfmath@x#1pt\relax%
			\ifdim\pgfmath@x<0pt\relax%
				\ifdim\pgfmathfloor@remainder>0pt
					\advance\c@pgfmath@counta by -1\relax%
				\else
					% ok, we stripped only '0'.
				\fi
			\fi%
			\pgfmath@x\c@pgfmath@counta pt\relax%
			\pgfmath@returnone\pgfmath@x%
		\endgroup%
	}%
	\def\pgfmathfloor@collect@remainder#1\pgfmath@{%
		\def\pgfmathfloor@remainder{#1}%
		\ifx\pgfmathfloor@remainder\pgfutil@empty
			\def\pgfmathfloor@remainder{0}%
		\fi
	}%
\fi

\pgfutil@IfUndefined{pgfmathifexpression}{%
	\def\pgfmathifexpression#1#2#3{%
		\pgfmathparse{#1}%
		\pgfmath@iftrue{#2}{#3}%
	}
	\def\pgfmath@iftrue{%
		\ifdim\pgfmathresult pt=1.0pt %
			\let\pgfmath@next=\pgfutil@firstoftwo
		\else
			\let\pgfmath@next=\pgfutil@secondoftwo
		\fi
		\pgfmath@next
	}%
	\gdef\pgfplots@glob@TMPa{1}%
}{}%

\pgfutil@ifundefined{pgfmathfloat@iftrue@}{
	\gdef\pgfplots@glob@TMPa{1}%
}
{}%

\if1\pgfplots@glob@TMPa
	\immediate\write16{Package pgfplots: loading complementary arithmetics for your pgf version...}
	\input pgfplotsoldpgfsupp_pgflibraryfpu.code.tex
	\input pgfplotsoldpgfsupp_pgfmathfloat.code.tex
\fi

\pgfutil@IfUndefined{pgfmathdeclarefunction}{
	\pgfplots@warning{Parts of pgfplots require PGF 2.10; you have PGF 2.00 . Consider upgrading if you experience problems.}%
}{%
}%

\pgfutil@IfUndefined{pgfutilifcontainsmacro}{%
	\gdef\pgfplots@glob@TMPa{1}%
}{%
	\gdef\pgfplots@glob@TMPa{0}%
}%
\if1\pgfplots@glob@TMPa
	\begingroup
	\catcode`\|=0
	\catcode`\\=12
	|gdef|pgfutil@backslash@as@other{\}%
	|endgroup
	\def\pgfutil@command@to@string#1#2{%
		\expandafter\pgfutil@command@to@string@@\meaning#1\pgfutil@EOI{#2}%
	}%
	\xdef\pgfutil@glob@TMPa{\meaning\pgfutil@empty}%
	\expandafter\def\expandafter\pgfutil@command@to@string@@\pgfutil@glob@TMPa#1\pgfutil@EOI#2{%
		\def#2{#1}%
	}%
	\def\pgfutilifcontainsmacro#1#2#3{%
		\def\pgf@marshal{#1}%
		\pgfutil@command@to@string\pgf@marshal\pgf@marshal
		\edef\pgf@marshal{\noexpand\pgfutil@in@{\pgfutil@backslash@as@other}{\pgf@marshal}}%
		\pgf@marshal
		\ifpgfutil@in@
			\def\pgf@marshal{#2}%
		\else
			\def\pgf@marshal{#3}%
		\fi
		\pgf@marshal
	}%
\fi

\pgfutil@IfUndefined{pgfapplistnewempty}{%
	\immediate\write16{Package pgfplots: loading complementary utilities for your pgf version...}
	\csname newtoks\endcsname\t@pgf@toka
	\csname newtoks\endcsname\t@pgf@tokb
	\csname newtoks\endcsname\t@pgf@tokc
	\gdef\pgfutil@advancestringcounter{\pgfplotsutil@advancestringcounter}%
	\input pgfplotsoldpgfsupp_pgfutil-common-lists.tex
}{}%

\pgfutil@IfUndefined{pgfmathiftrigonometricusesdeg}{%
	\pgfutil@ifundefined{pgfmathdeclarefunction}{%
		% PGF 2.00 !? Well, trig format won't work here.
	}{%
		\input pgfplotsoldpgfsupp_trig_format.code.tex
	}%
}{}%

\def\pgfmathfloat@install@unimplemented@broken#1{%
	\expandafter\pgfmathfloat@prepareuninstallcmd\csname pgfmath@#1@\endcsname%
	\expandafter\def\csname pgfmath#1@\endcsname##1{\pgfmathfloat@notimplemented{#1}}%
}

\ifx\pgfmathfloat@install@unimplemented\pgfmathfloat@install@unimplemented@broken
	\def\pgfmathfloat@install@unimplemented#1{%
		\expandafter\pgfmathfloat@prepareuninstallcmd\csname pgfmath#1@\endcsname%
		\expandafter\def\csname pgfmath#1@\endcsname##1{\pgfmathfloat@notimplemented{#1}}%
	}%
\fi


\ifpgfplots@LUA@supported
	\def\PATCH@pgfmath@local@function@body#1;{%
		\def\pgfmath@local@body{#1}%
		\begingroup%
			\c@pgf@counta=0\relax%
			\ifx\pgfmath@local@args\pgfmath@empty%
				\expandafter\pgfmath@toks\expandafter=\expandafter{\pgfmath@local@body}%
			\else%
				\pgfmath@toks={}%
				\expandafter\pgfmath@local@function@@body\pgfmath@local@args,,%
			\fi%
			\xdef\pgfmath@local@temp{%
				\noexpand\pgfmathnotifynewdeclarefunction{\pgfmath@local@name}{\the\c@pgf@counta}%
					{\the\pgfmath@toks}%
			}%
		\endgroup%
		\pgfmath@local@temp%
	}
	% #1: the name
	% #2: the number of arguments <n>
	% #3: a math expression containing '#1', '#2', ... ,'#'<n>
	% This callback is overwritten by pgflibraryluamath.
	\def\PATCH@pgfmathnotifynewdeclarefunction#1#2#3{%
		\pgfmathdeclarefunction{#1}{#2}{\pgfmathparse{#3}}%
	}%
	%
	% currently, pgfplots does NOT call directly call any TeX macros
	% from this library - but it relies on the fact that "trig
	% format", \pgfmathsetseed and other configuration macros also
	% mirror their values in LUA.
	% And this mirroring is done in library luamath:
	\def\pgfplots@glob@TMPa{3.0.0}%
	\ifx\pgfversion\pgfplots@glob@TMPa
		% 3.0.0 does not have the (correct) luamath library.
		\let\pgfmathnotifynewdeclarefunction=\PATCH@pgfmathnotifynewdeclarefunction
		\let\pgfmath@local@function@body=\PATCH@pgfmath@local@function@body
		\pgfplotsusecompatibilityfile{pgflibraryluamath.code.tex}
	\else
		\let\PATCH@pgfmathnotifynewdeclarefunction@orig=\pgfmathnotifynewdeclarefunction
		\let\PATCH@pgfmathsetseed@pgfbasic = \pgfmathsetseed
		\pgfutil@IfFileExists{pgflibraryluamath.code.tex}{%
			% ah - we have a very recent version of PGF.
			% Well, it will hopefully come with a suitable version of the
			% luamath library! Use it.
			\usepgflibrary{luamath}%
		}{%
			% hm. PGF 2.10 ?
			%
			% FIXME
			%\pgfplots@LUA@supportedfalse
		}%
		%
		\gdef\pgfplots@glob@TMPa{1}% "is up to date = 1"
		\def\pgfplots@glob@TMPa{3.0.1}%
		\ifx\pgfversion\pgfplots@glob@TMPa
			\gdef\pgfplots@glob@TMPa{0}% "is up to date = 0"
		\else
			\def\pgfplots@glob@TMPa{3.0.1a}%
			\ifx\pgfversion\pgfplots@glob@TMPa
				\gdef\pgfplots@glob@TMPa{0}% "is up to date = 0"
			\fi
		\fi
		\if0\pgfplots@glob@TMPa
			% 3.0.1 does not have the (correct) luamath library.
			\pgfutil@directlua{%
		      package.loaded["pgf.luamath.functions"]=nil;
		      package.loaded["pgf.luamath.parser"]=nil;
			  pgfluamathfunctions = nil;
			  pgfluamathparser = nil}
			\pgfplotsusecompatibilityfile{pgflibraryluamath.code.tex}
			% ATTENTION: see 'pgfplots.lua' which ALSO loads these items
			% FIXME : some .lua files reference outdated
			% tonumber/tostring functions!
			\pgfutil@directlua{%
		      pgfplots.pgfluamathfunctions = pgfluamathfunctions;
			  pgfplots.pgfluamathparser = pgfluamathparser}%
			\let\pgfmathnotifynewdeclarefunction@orig=\PATCH@pgfmathnotifynewdeclarefunction@orig
			\let\pgfmathsetseed@pgfbasic=\PATCH@pgfmathsetseed@pgfbasic
			\pgfplots@log4{luamath library shipped with pgf \pgfversion\space is outdated; using a substitute shipped with pgfplots}%
		\else
			\pgfplots@log4{luamath library shipped with pgf \pgfversion\space is up-to-date}%
		\fi
	\fi
\fi

\def\pgf@plotgnuplot@luatex@eight@seven[#1]#2{%
  \pgf@resample@plottrue%
  \pgfutilpreparefilename{#1.gnuplot}%
  \let\pgf@plotgnuplotfile=\pgfretval
  \pgfutilpreparefilename{#1.table}%
  \let\pgf@plottablefile=\pgfretval
  \let\pgf@plottablefile@quoted=\pgfretvalquoted
  % Check, whether it is up-to-date
  \openin\pgfutil@inputcheck=\pgf@plotgnuplotfile\relax
  \ifeof\pgfutil@inputcheck%
  \else%
    \pgfutil@read\pgfutil@inputcheck to\pgf@temp% ignored
    \pgfutil@read\pgfutil@inputcheck to\pgf@plot@line%
    \closein\pgfutil@inputcheck
    \edef\pgf@plot@code{#2\space}%
    \ifx\pgf@plot@code\pgf@plot@line%
      \openin\pgfutil@inputcheck=\pgfretval\relax
      \ifeof\pgfutil@inputcheck%
      \else%
        \closein\pgfutil@inputcheck
        \pgf@resample@plotfalse%
      \fi%
    \fi%
  \fi
  \ifpgf@resample@plot%
    \immediate\openout\pgf@plotwrite=\pgf@plotgnuplotfile\relax
    \immediate\pgfutil@write\pgf@plotwrite{\pgf@gnuplot@head}%
    \immediate\pgfutil@write\pgf@plotwrite{#2}%
    \immediate\closeout\pgf@plotwrite%
    \pgfutil@shellescape{%
      \pgfkeysvalueof{/pgf/plot/gnuplot call} \pgf@plotgnuplotfile}%
  \fi%
%  \let\pgf@savedparsexyline=\pgf@parsexyline%
%  \let\pgf@parsexyline=\pgf@parsegnuplotxyline%
  \pgfplotxyfile{\pgf@plottablefile}%
%  \let\pgf@parsexyline=\pgf@savedparsexyline%
}

\pgfutil@IfUndefined{pgfutil@shellescape}{%
	\def\pgfutil@shellescape{\pgfplots@shellescape}%
	\let\pgf@plotgnuplot=\pgf@plotgnuplot@luatex@eight@seven
}{%
	% ok, plot function is up-to-date
}%

\def\pgfmathfloatmod@broken#1#2{%
	\begingroup
	\pgfmathfloatdivide@{#1}{#2}%
	\pgfmathfloatint@{\pgfmathresult}%
	\let\pgfmathfloat@loc@TMPa=\pgfmathresult
	\pgfmathfloatmultiply@{\pgfmathfloat@loc@TMPa}{#2}%
	\let\pgfmathfloat@loc@TMPb=\pgfmathresult
	\pgfmathfloatsubtract@{#1}{\pgfmathfloat@loc@TMPb}%
	\pgfmath@smuggleone\pgfmathresult
	\endgroup
}

\ifx\pgfmathfloatmod@\pgfmathfloatmod@broken
	\def\pgfmathfloatmod@#1#2{%
		\begingroup
		\pgfmathfloattoint{#1}%
		\let\pgfmathfloat@loc@TMPa=\pgfmathresult
		\pgfmathfloattoint{#2}%
		\let\pgfmathfloat@loc@TMPb=\pgfmathresult
		\c@pgfmath@counta=\pgfmathfloat@loc@TMPa\relax
		\divide\c@pgfmath@counta by\pgfmathfloat@loc@TMPb\relax
		\expandafter\pgfmathfloatparsenumber\expandafter{\the\c@pgfmath@counta}%
		%
		\let\pgfmathfloat@loc@TMPa=\pgfmathresult
		\pgfmathfloatmultiply@{\pgfmathfloat@loc@TMPa}{#2}%
		\let\pgfmathfloat@loc@TMPb=\pgfmathresult
		\pgfmathfloatsubtract@{#1}{\pgfmathfloat@loc@TMPb}%
		\pgfmath@smuggleone\pgfmathresult
		\endgroup
	}
\fi

\pgfutil@IfUndefined{pgfutilsolvetwotwoleqfloat}{%
	\input pgfplotsoldpgfsupp_leq.code.tex
}{}%

\pgfutil@IfUndefined{pgfutilifstartswith}{%
	\let\pgfutilifstartswith=\pgfplotsutilifstartswith
}{}

\endinput
