diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/math')
14 files changed, 5150 insertions, 2528 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex index c901c3972f1..9c51dc46117 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmath.code.tex @@ -7,4 +7,11 @@ % % See the file doc/generic/pgf/licenses/LICENSE for more details. -\input pgfmathcalc.code.tex
\ No newline at end of file +\input pgfmathcalc.code.tex + +\ifx\pgfkeysloaded\undefined + \let\pgfkeysloaded=\relax +\else + \expandafter\input pgfmathfloat.code.tex +\fi + diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex index 29a2be58693..c1f099ce160 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathcalc.code.tex @@ -13,8 +13,8 @@ \input pgfmathutil.code.tex \input pgfmathparser.code.tex -\input pgfmathoperations.code.tex -\input pgfmathbase.code.tex +\input pgfmathfunctions.code.tex +%\input pgfmathbase.code.tex % \pgfmathsetlength, \pgfmathaddtolength % @@ -85,7 +85,8 @@ \def\pgfmathsetcount#1#2{% \expandafter\pgfmath@onquick#2\pgfmath@% {% - #1#2\relax% + \afterassignment\pgfmath@gobbletilpgfmath@% + #1#2\relax\pgfmath@% }% {% \pgfmathparse{#2}% @@ -105,7 +106,10 @@ \def\pgfmathaddtocount#1#2{% \expandafter\pgfmath@onquick#2\pgfmath@% {% - \advance#1#2\relax% + \edef\pgfmath@addtocounttemp{\the#1}% + \afterassignment\pgfmath@gobbletilpgfmath@% + #1#2\relax\pgfmath@% + \advance#1\pgfmath@addtocounttemp\relax% }% {% \edef\pgfmath@addtocounttemp{\the#1}% @@ -240,14 +244,327 @@ % \pgfmath@onquick+0pt\pgfmath@{is quick}{is slow} \def\pgfmath@onquick{% - \afterassignment\pgfmath@afterquick% - \let\pgfmath@next=% + \futurelet\pgfmath@next% + \pgfmath@@onquick} +\def\pgfmath@@onquick#1\pgfmath@{% + \ifx\pgfmath@next+% + \let\pgfmath@next=\pgfmath@firstoftwo% + \else% + \let\pgfmath@next=\pgfmath@secondoftwo% + \fi% + \pgfmath@next% +} + +% *** The following commands DO NOT WORK without the rest of PGF *** +% +% (a dumping ground for stuff that doesn't really belong anywhere else) + +% \pgfmathanglebetweenpoints +% +% Define \pgfmathresult as the angle between points #1 and #2 +% Should get the quadrants right as well. +% +\def\pgfmathanglebetweenpoints#1#2{% + \begingroup% + \pgf@process{\pgfpointdiff{#1}{#2}}% + % + % First approximate the angle of the external point... + % + \pgf@xa\pgf@x% + \pgf@ya\pgf@y% + \pgf@xb\pgf@x% + \pgf@yb\pgf@y% + \ifdim\pgf@xa<0pt\relax% + \pgf@xa-\pgf@xa% + \fi% + \ifdim\pgf@ya<0pt\relax% + \pgf@ya-\pgf@ya% + \fi% + \ifdim\pgf@ya>\pgf@xa% + \pgf@x\pgf@xa% + \pgf@y\pgf@ya% + \else% + \pgf@x\pgf@ya% + \pgf@y\pgf@xa% + \fi% + \ifdim\pgf@y=0pt\relax% + \pgf@x0pt% + \else% + \pgfmathreciprocal@{\pgfmath@tonumber{\pgf@y}}% + \pgf@x\pgfmathresult\pgf@x% + \fi% + \multiply\pgf@x1000\relax% + \afterassignment\pgfmath@gobbletilpgfmath@% + \expandafter\c@pgf@counta\the\pgf@x\relax\pgfmath@% + \expandafter\pgf@x\csname pgfmath@atan@\the\c@pgf@counta\endcsname pt\relax% + \ifdim\pgfmath@ya>\pgfmath@xa\relax% + \pgf@x-\pgf@x% + \advance\pgf@x90pt% + \fi% + \ifdim\pgf@xb<0pt% + \ifdim\pgf@yb>0pt% + \pgf@x-\pgf@x% + \fi% + \advance\pgf@x180pt\relax% + \else% + \ifdim\pgf@yb<0pt% + \pgf@x-\pgf@x% + \advance\pgf@x360pt\relax% + \fi\fi% + \pgfmath@returnone\pgf@x% + \endgroup% } -\def\pgfmath@afterquick#1\pgfmath@{% - \ifx\pgfmath@next+% - \expandafter\pgfmath@firstoftwo% - \else% - \expandafter\pgfmath@secondoftwo% - \fi% -}
\ No newline at end of file +% +% \pgfmathrotatepointaround +% +% Rotate point #1 about point #2 by #3 degrees. +% +\def\pgfmathrotatepointaround#1#2#3{% + \pgf@process{% + \pgf@process{#1}% + \pgf@xc=\pgf@x% + \pgf@yc=\pgf@y% + \pgf@process{#2}% + \pgf@xa\pgf@x% + \pgf@ya\pgf@y% + \pgf@xb\pgf@x% + \pgf@yb\pgf@y% + \pgf@x=\pgf@xc% + \pgf@y=\pgf@yc% + \advance\pgf@x-\pgf@xa% + \advance\pgf@y-\pgf@ya% + \pgfmathsetmacro\angle{#3}% + \pgfmathsin@{\angle}% + \let\sineangle\pgfmathresult% + \pgfmathcos@{\angle}% + \let\cosineangle\pgfmathresult% + \pgf@xa\cosineangle\pgf@x% + \advance\pgf@xa-\sineangle\pgf@y% + \pgf@ya\sineangle\pgf@x% + \advance\pgf@ya\cosineangle\pgf@y% + \pgf@x\pgf@xb% + \pgf@y\pgf@yb% + \advance\pgf@x\pgf@xa% + \advance\pgf@y\pgf@ya% + }% +} + +% \pgfmathanglebetweenlines +% +% Calculate the clockwise angle between a line from point #1 +% to point #2 and a line from #3 to point #4. +% +\def\pgfmathanglebetweenlines#1#2#3#4{% + \begingroup% + \pgfmathanglebetweenpoints{#1}{#2}% + \let\firstangle\pgfmathresult% + \pgfmathanglebetweenpoints{#3}{#4}% + \let\secondangle\pgfmathresult% + \ifdim\firstangle pt>\secondangle pt\relax% + \pgfmathadd@{\secondangle}{360}% + \let\secondangle\pgfmathresult% + \fi% + \pgfmathsubtract@{\secondangle}{\firstangle}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% \pgfmathpointreflectalongaxis +% +% Reflects point #2 around an axis centered on #2 at an angle #3. +% +\def\pgfmathreflectpointalongaxis#1#2#3{% + \pgf@process{% + \pgfmathanglebetweenpoints{#2}{#1}% + \pgfmath@tempdima\pgfmathresult pt\relax% + \pgfmathparse{#3}% + \advance\pgfmath@tempdima-\pgfmathresult pt\relax% + \pgfmath@tempdima-2.0\pgfmath@tempdima% + \pgfmathrotatepointaround{#1}{#2}{\pgfmath@tonumber{\pgfmath@tempdima}}% + }% +} + + + +% \pgfmathpointintersectionoflineandarc +% +% A bit experimental at the moment: +% +% Locates the point where a line crosses an eliptical arc. If the line +% does not cross the arc, a meaningless point will result. +% +% #1 the point of the line on the "convex" side of the arc. +% #2 the point of the line on the "concave" side of the arc. +% #3 the center of the eliptical arc. +% #4 start angle of the arc. +% #5 end angle of the arc. +% #6 radii of the arc. +% +\def\pgfmathpointintersectionoflineandarc#1#2#3#4#5#6{% + \pgf@process{% + % + % Get the required angle. + % + \pgfmathanglebetweenpoints{#2}{#1}% + \let\x\pgfmathresult% + % + % Get the radii of the arc. + % + \pgfmath@in@{and }{#6}% + \ifpgfmath@in@% + \pgf@polar@#6\@@% + \else% + \pgf@polar@#6 and #6\@@% + \fi% + \edef\xarcradius{\the\pgf@x}% + \edef\yarcradius{\the\pgf@y}% + % + % Get the start and end angles of the arc... + % + \pgfmathsetmacro\s{#4}% + \pgfmathsetmacro\e{#5}% + % + % ...and also with rounding. + % + \pgfmathmod@{\s}{360}% + \ifdim\pgfmathresult pt<0pt\relax% + \pgfmathadd@{\pgfmathresult}{360}% + \fi% + \let\ss\pgfmathresult% + \pgfmathmod@{\e}{360}% + \ifdim\pgfmathresult pt<0pt\relax% + \pgfmathadd@{\pgfmathresult}{360}% + \fi% + \let\ee\pgfmathresult% + % + % Hackery for when arc straddles zero. + % + \ifdim\ee pt<\ss pt\relax% + \pgfmathadd@{\x}{180}% + \pgfmathmod@{\pgfmathresult}{360}% + \let\x\pgfmathresult% + \fi% + \def\m{360}% Measure of nearness. + \pgfmathadd@{\s}{\e}% + \pgfmathdivide@{\pgfmathresult}{2}% + \let\n\pgfmathresult% The best estimate (default to middle of arc). + \pgfmathloop% + \pgfmathadd@{\s}{\e}% + \pgfmathdivide@{\pgfmathresult}{2}% + \let\p\pgfmathresult% + \ifdim\p pt=\s pt\relax% + \else% + \pgfmathanglebetweenpoints{#2}{% + \pgfpointadd{#3}{% + \pgf@x\xarcradius\relax% + \pgfmathcos@{\p}% + \pgf@x\pgfmathresult\pgf@x% + \pgf@y\yarcradius\relax% + \pgfmathsin@{\p}% + \pgf@y\pgfmathresult\pgf@y% + }% + }% + % + % Hackery for when arc straddles zero. + % + \ifdim\ee pt<\ss pt\relax% + \pgfmathadd@{\pgfmathresult}{180}% + \pgfmathmod@{\pgfmathresult}{360}% + \fi% + \let\q\pgfmathresult% + % + % More hackery... + % + \ifdim\x pt>335pt\relax% + \ifdim\q pt<45pt\relax% + \pgfmathadd@{\q}{360}% + \let\q\pgfmathresult% + \fi% + \fi% + \ifdim\x pt=\q pt% Found it! + \pgfmathbreakloop% Breaks after current iteration is complete. + \else + \ifdim\x pt<\q pt\relax% + \let\e\p% + \else% + \let\s\p% + \fi% + \fi% + \pgfmathsubtract@{\x}{\q}% + \pgfmathabs@{\pgfmathresult}% + % + % Save the estimate if it is better than any previous estimate. + % + \ifdim\pgfmathresult pt<\m pt\relax% + \let\m\pgfmathresult% + \let\n\p% + \fi% + \repeatpgfmathloop% + \pgfpointadd{#3}{\pgfpointpolar{\n}{\xarcradius and \yarcradius}}% + }% +} + +% \pgfmathangleonellipse +% +% Find the angle corresponding to a point on the border of an ellispe. +% +% #1 - the point on the border. +% #2 - the radii of the ellipse. +% +\def\pgfmathangleonellipse#1#2{% + \begingroup% + \pgfmath@in@{and }{#2}% + \ifpgfmath@in@% + \pgf@polar@#2\@@% + \else% + \pgf@polar@#2 and #2\@@% + \fi% + \pgf@xa\pgf@x% + \pgf@ya\pgf@y% + \pgf@process{#1}% + \ifdim\pgf@x=0pt\relax% + \pgfutil@tempdima1pt\relax% + \else% + \pgfutil@tempdima\pgf@x% + \pgfmathdivide@{\pgfmath@tonumber{\pgf@xa}}{\pgfmath@tonumber{\pgfutil@tempdima}}% + \pgfutil@tempdima\pgfmathresult pt\relax% + \fi% + \ifdim\pgf@y=0pt\relax% + \pgfutil@tempdima1pt\relax% + \else% + \pgfmathdivide@{\pgfmath@tonumber{\pgf@y}}{\pgfmath@tonumber{\pgf@ya}}% + \pgfutil@tempdima\pgfmathresult\pgfutil@tempdima% + \pgfmathatan@{\pgfmath@tonumber{\pgfutil@tempdima}}% + \fi% + % + \pgfutil@tempdima\pgfmathresult pt\relax% + \ifdim\pgfutil@tempdima<0pt\relax% + \advance\pgfutil@tempdima360pt\relax% + \fi% + \ifdim\pgf@x<0pt\relax% + \ifdim\pgf@y=0pt\relax% + \pgfutil@tempdima180pt\relax% + \else% + \ifdim\pgf@y<0pt\relax% + \advance\pgfutil@tempdima180pt\relax% + \else% + \advance\pgfutil@tempdima-180pt\relax% + \fi% + \fi% + \else% + \ifdim\pgf@x=0pt\relax% + \ifdim\pgf@y<0pt\relax% + \pgfutil@tempdima270pt\relax% + \else% + \pgfutil@tempdima90pt\relax% + \fi% + \else% + \ifdim\pgf@y=0pt\relax% + \pgfutil@tempdima0pt\relax% + \fi% + \fi% + \fi% + \pgfmath@returnone\pgfutil@tempdima% + \endgroup% +} diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex new file mode 100644 index 00000000000..722856f3628 --- /dev/null +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex @@ -0,0 +1,2376 @@ +% Copyright 2008 by Christian Feuersaenger +% +% This file may be distributed and/or modified +% +% 1. under the LaTeX Project Public License and/or +% 2. under the GNU Public License. +% +% See the file doc/generic/pgf/licenses/LICENSE for more details. +% +% This file contains methods for basic floating point arithmetics, rounding +% to arbitrary precision and number pretty printing. +% +% Version 1.0 2008/09/17 + +\global\newif\ifpgfmathfloatcomparison +\newif\ifpgfmathfloatroundhasperiod +\newif\ifpgfmathprintnumberskipzeroperiod + + +% used internally in grouped macros: +\toksdef\pgfmathfloat@tmptoks=1 +\newif\ifpgfmathfloat@fixed@digits@after@period +\newif\ifpgfmathfloatroundmayneedrenormalize +\toksdef\pgfmathfloat@a@Mtok=0 + +%% WARNING: avoid conflicting register names! +\let\pgfmathfloat@a@S=\c@pgf@counta +\let\pgfmathfloat@a@M=\pgf@xa +\let\pgfmathfloat@a@E=\c@pgf@countb +\let\pgfmathfloat@b@S=\c@pgf@countc +\let\pgfmathfloat@b@M=\pgf@xb +\let\pgfmathfloat@b@E=\c@pgf@countd + +% can be changed with options. +\def\pgfmathfloat@round@precision{2} + +\gdef\pgfmathfloat@glob@TMP{} + + +% Computes a normalised floating point representation for #1 of the +% form +% [FLAGS] MANTISSE EXPONENT +% meaning +% [+-]X.XXXXXXX*10^C +% where +% X.XXXXXX is a mantissa with first number != 0, C is an integer and +% FLAGS contains the sign and some other special cases. +% +% This method does NOT use TeX Registers to represent the numbers! The +% computation is COMPLETELY STRING BASED. +% This allows numbers such at 10000000 or 5.23e-10 to be represented +% properly, although TeX-registers would produce overflow/underflow +% errors in these cases. +% +% It is to be used to compute logs, because log(X*10^Y) = log(X) + log(10)*Y +% +% Arguments: +% #1: an arbitrary number which shall be parsed. Maybe a macro. +% Examples: +% [+-]XXXXX.XXXXXX +% [+-]XXXXX.XXXXXXeXXXX +% [+-]0.0000XXXXXX +% [+-]0.0000XXXXXXeXXXX +% [+-]inf +% nan +% Maybe a macro containing such a number. +% +% Return value: +% \pgfmathresult will be \def'ed to +% FLAGS MANTISSE 'e' EXPONENT +% where +% FLAGS is a number in [0-5] where +% 0 == '0' (the number is +- 0.0), +% 1 == '+', +% 2 == '-', +% 3 == 'not a number' +% 4 == '+ infinity' +% 5 == '- infinity' +% +% MANTISSE is a normalised number 1 <= M < 10. It always contains a +% period and at least one digit after the period. +% +% EXPONENT is an integer value. +% +% Example: +% \pgfmathfloatparsenumber{1} +% -> \pgfmathresult = 11.0e0 +% \pgfmathfloatparsenumber{141.212} +% -> \pgfmathresult = 11.41212e2 +\def\pgfmathfloatparsenumber#1{% + \begingroup + \edef\pgfmathresult{#1}% + \expandafter\pgfflt@impl\pgfmathresult\pgfflt@EOI + \ifpgfmathfloatparsenumberpendingperiod + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.0}% + \fi + \pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% + \pgfmath@smuggleone\pgfmathresult + \endgroup +} + +% The same as \pgfmathfloatparsenumber, but does not perform sanity checking. +% FIXME: there is no longer any difference here. +\let\pgfmathfloatqparsenumber=\pgfmathfloatparsenumber + +% Takes a floating point number #1 as input and writes flags to count +% register #2, mantissa to dimen register #3 and exponent to count +% register #4. +\def\pgfmathfloattoregisters#1#2#3#4{% + \expandafter\pgfmathfloat@decompose#1\relax{#2}{#3}{#4}% +} + +% the same, but writes the mantissa into a token register. +\def\pgfmathfloattoregisterstok#1#2#3#4{% + \expandafter\pgfmathfloat@decompose@tok#1\relax{#2}{#3}{#4}% +} + +% Extracts the flags of #1 into the count register #2. +\def\pgfmathfloatgetflags#1#2{% + \expandafter\pgfmathfloat@decompose@F#1\relax{#2}% +} +% Extracts the flags of #1 into the macro #2. +\def\pgfmathfloatgetflagstomacro#1#2{% + \expandafter\pgfmathfloat@decompose@Fmacro#1\relax{#2}% +}% + +% Extracts the mantissa of #1 into the dimen register #2. +\def\pgfmathfloatgetmantissa#1#2{% + \expandafter\pgfmathfloat@decompose@M#1\relax{#2}% +} +\let\pgfmathfloatgetmantisse=\pgfmathfloatgetmantissa +% Extracts the mantissa of #1 into the token register #2. +\def\pgfmathfloatgetmantissatok#1#2{% + \expandafter\pgfmathfloat@decompose@Mtok#1\relax{#2}% +} +\let\pgfmathfloatgetmantissetok=\pgfmathfloatgetmantissatok +% Extracts the exponent of #1 into the count register #2. +\def\pgfmathfloatgetexponent#1#2{% + \expandafter\pgfmathfloat@decompose@E#1\relax{#2}% +} + + +% Assigns \pgfmathresult to be a float encoded as +% <FLAGS><MANTISSE>e<EXPONENT> +% +% example: +% \pgfmathfloatcreate{1}{2.0}{10} +% \pgfmathfloat@to@FMeE@style\pgfmathresult +% -> +% \pgfmathresult is now '12.0e10' regardless of the internal float +% format. +\def\pgfmathfloat@to@FMeE@style#1{\expandafter\pgfmathfloat@to@FMeE@style@#1\relax\relax}% +\def\pgfmathfloat@to@FMeE@style@#1#2{% + \ifx#2Y% + \expandafter\pgfmathfloat@to@FMeE@style@@% + \else + \expandafter\pgfmathfloat@to@FMeE@style@error% + \fi + #1#2% +}% +\def\pgfmathfloat@to@FMeE@style@@#1Y#2e#3]\relax\relax{\def\pgfmathresult{#1#2e#3}}% +\def\pgfmathfloat@to@FMeE@style@error#1\relax\relax{% + \begingroup + \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}% + \xdef\pgfmathfloat@decompose@TMP{% + \noexpand\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% + }% + \endgroup + \pgfmathfloat@decompose@TMP +}% + + +% decomposes a lowlevel floating point representation into flags, +% mantissa and exponent. +% +% #4: integer register for the flags. +% #5: dimen registers for the mantissa. +% #6: integer register for the exponent. +% +% \expandafter\pgfmathfloat@decompose\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@M\pgfmathfloat@a@E +% -> the three temp registers contain flags, mantissa and exponent +\def\pgfmathfloat@decompose#1#2{% sanitize! + \ifx#2Y% + \expandafter\pgfmathfloat@decompose@% + \else + \expandafter\pgfmathfloat@decompose@error% + \fi + #1#2% +} +\def\pgfmathfloat@decompose@#1Y#2e#3]\relax#4#5#6{% + #4=#1\relax + #5=#2pt % keep space here. + #6=#3\relax% +} + +% overloaded, #5 needs to be a token register for the mantissa. +% @see also \pgfmathfloatvalueof which does also employ the load +% level repr. +% \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E +% -> the three temp registers contain flags, mantissa and exponent +\def\pgfmathfloat@decompose@tok#1#2{% + \ifx#2Y% + \expandafter\pgfmathfloat@decompose@tok@% + \else + \expandafter\pgfmathfloat@decompose@tok@error% + \fi + #1#2% +}% +\def\pgfmathfloat@decompose@tok@#1Y#2e#3]\relax#4#5#6{% + #4=#1\relax + #5={#2}% + #6=#3\relax% +} +% overloaded, returns only ONE of the three components into #4: +% \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S +% -> \pgfmathfloat@a@S contains the flags field. +\def\pgfmathfloat@decompose@F#1#2{% + \ifx#2Y% + \expandafter\pgfmathfloat@decompose@F@% + \else + \expandafter\pgfmathfloat@decompose@F@error% + \fi + #1#2% +}% +\def\pgfmathfloat@decompose@Fmacro#1#2{% + \ifx#2Y% + \expandafter\pgfmathfloat@decompose@Fmacro@% + \else + \expandafter\pgfmathfloat@decompose@F@error% + \fi + #1#2% +}% +\def\pgfmathfloat@decompose@M#1#2{% + \ifx#2Y% + \expandafter\pgfmathfloat@decompose@M@% + \else + \expandafter\pgfmathfloat@decompose@M@error% + \fi + #1#2% +}% +\def\pgfmathfloat@decompose@E#1#2{% + \ifx#2Y% + \expandafter\pgfmathfloat@decompose@E@% + \else + \expandafter\pgfmathfloat@decompose@E@error% + \fi + #1#2% +}% +\def\pgfmathfloat@decompose@Mtok#1#2{% + \ifx#2Y% + \expandafter\pgfmathfloat@decompose@Mtok@% + \else + \expandafter\pgfmathfloat@decompose@Mtok@error% + \fi + #1#2% +}% +\def\pgfmathfloat@decompose@F@#1Y#2e#3]\relax#4{#4=#1\relax}% +\def\pgfmathfloat@decompose@Fmacro@#1Y#2e#3]\relax#4{\def#4{#1}}% +\def\pgfmathfloat@decompose@M@#1Y#2e#3]\relax#4{#4=#2pt}% +\def\pgfmathfloat@decompose@Mtok@#1Y#2e#3]\relax#4{#4={#2}}% +\def\pgfmathfloat@decompose@E@#1Y#2e#3]\relax#4{#4=#3\relax}% + +\def\pgfmathfloat@decompose@error#1\relax#2#3#4{% + \begingroup + \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}% + \xdef\pgfmathfloat@decompose@TMP{% + \noexpand#2=\the\pgfmathfloat@a@S\space + \noexpand#3=\the\pgfmathfloat@a@Mtok pt + \noexpand#4=\the\pgfmathfloat@a@E\space + }% + \endgroup + \pgfmathfloat@decompose@TMP +}% +\def\pgfmathfloat@decompose@tok@error#1\relax#2#3#4{% + \begingroup + \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}% + \xdef\pgfmathfloat@decompose@TMP{% + \noexpand#2=\the\pgfmathfloat@a@S\space + \noexpand#3={\the\pgfmathfloat@a@Mtok}% + \noexpand#4=\the\pgfmathfloat@a@E\space + }% + \endgroup + \pgfmathfloat@decompose@TMP +}% +\def\pgfmathfloat@decompose@F@error#1\relax#2{% + \begingroup + \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}% + \xdef\pgfmathfloat@decompose@TMP{\noexpand#2=\the\pgfmathfloat@a@S\space}% + \endgroup + \pgfmathfloat@decompose@TMP +}% +\def\pgfmathfloat@decompose@M@error#1\relax#2{% + \begingroup + \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}% + \xdef\pgfmathfloat@decompose@TMP{\noexpand#2=\the\pgfmathfloat@a@Mtok pt }% + \endgroup + \pgfmathfloat@decompose@TMP +}% +\def\pgfmathfloat@decompose@Mtok@error#1\relax#2{% + \begingroup + \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}% + \xdef\pgfmathfloat@decompose@TMP{\noexpand#2={\the\pgfmathfloat@a@Mtok}}% + \endgroup + \pgfmathfloat@decompose@TMP +}% +\def\pgfmathfloat@decompose@E@error#1\relax#2{% + \begingroup + \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}% + \xdef\pgfmathfloat@decompose@TMP{\noexpand#2=\the\pgfmathfloat@a@E\space}% + \endgroup + \pgfmathfloat@decompose@TMP +}% +% Takes a floating point number #1 as input and writes flags to macro +% #2, mantissa to macro #3 and exponent to macro #4. +\def\pgfmathfloattomacro#1#2#3#4{% + \begingroup + \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \xdef\pgfmathfloat@glob@TMP{% + \noexpand\def\noexpand#2{\the\pgfmathfloat@a@S}% + \noexpand\def\noexpand#3{\the\pgfmathfloat@a@Mtok}% + \noexpand\def\noexpand#4{\the\pgfmathfloat@a@E}% + }% + \endgroup + \pgfmathfloat@glob@TMP +} + + +% Defines \pgfmathresult as the floating point number encoded by +% the flags #1, mantissa #2 and exponent #3. +% +% All arguments are characters and will be expanded using '\edef'. +\def\pgfmathfloatcreate#1#2#3{% + \edef\pgfmathresult{#1Y#2e#3]}% +}% +% This is the character present in any low-level floating point +% number. It is assumed to be the SECOND character of a float (after +% the flags integer). +\def\pgfmathfloat@POSTFLAGSCHAR{Y} + + + +% Converts a composed floating point representation to fixed point. +% +% Example: +% \pgfmathfloattofixed{142e1} +% -> \pgfmathresult = 42.0 +\def\pgfmathfloattofixed@#1{% + \begingroup + \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \ifcase\pgfmathfloat@a@S + \def\pgfmathresult{0.0}% + \or + \expandafter\pgfmathfloattofixed@impl\the\pgfmathfloat@a@Mtok\relax + \or + \expandafter\pgfmathfloattofixed@impl\the\pgfmathfloat@a@Mtok\relax + \pgfmathfloat@a@Mtok=\expandafter{\pgfmathresult}% + \edef\pgfmathresult{-\the\pgfmathfloat@a@Mtok}% + \or\def\pgfmathresult{nan}% + \or\def\pgfmathresult{inf}% + \or\def\pgfmathresult{-inf}% + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup +} +\let\pgfmathfloattofixed=\pgfmathfloattofixed@ + +% Converts a float to an integer (in integer format). +% +% @see \pgfmathfloatint +\def\pgfmathfloattoint#1{% + \pgfmathfloattofixed{#1}% + \expandafter\pgfmathfloattoint@@\pgfmathresult\relax +}% +\def\pgfmathfloattoint@@#1.#2\relax{% + \def\pgfmathresult{#1}% +}% + +% Converts a floating point number to scientific format 1.234e5. +% +% This operation is very fast. +\def\pgfmathfloattosci@#1{% + \begingroup + \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \ifcase\pgfmathfloat@a@S + \def\pgfmathresult{0.0e0}% + \or + \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok e\the\pgfmathfloat@a@E}% + \or + \edef\pgfmathresult{-\the\pgfmathfloat@a@Mtok e\the\pgfmathfloat@a@E}% + \or\def\pgfmathresult{nan}% + \or\def\pgfmathresult{inf}% + \or\def\pgfmathresult{-inf}% + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup +}% +\let\pgfmathfloattosci=\pgfmathfloattosci@ + +% Expands a floating point number to scientific format 1.234e5. +% +% This operation is very fast. +\def\pgfmathfloatvalueof#1{\expandafter\pgfmathfloatvalueof@@#1\relax}% +\def\pgfmathfloatvalueof@@#1Y#2e#3]\relax{% + \ifcase#1 % + 0.0e0% + \or + #2e#3% + \or + -#2e#3% + \or nan% + \or inf% + \or -inf% + \fi +}% + + +% Rounds a fixed point number #1 to \pgfmathfloat@round@precision digits precision and returns +% the result into \pgfmathresult. +% +% Any trailing zeros after the period are discarded. +% See \pgfmathroundtozerofill if you want trailing zeros and fixed +% width. +% +% This method is PURELY text based and can work with arbirtrary +% precision (well, limited to TeX's stack size and integer size). +% +% Examples: +% \pgfmathroundto{1} +% -> \pgfmathresult = '1' +% +% \pgfmathroundto{19999.9996} +% -> \pgfmathresult = '20000' +% +% Arguments: +% #1 may be either a number or a macro (\pgfmathresult is allowed) expanding to a number. +% +% SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set. +\def\pgfmathroundto#1{% + \pgfmathfloatroundhasperiodtrue + \begingroup + \pgfmathfloat@fixed@digits@after@periodfalse + \pgfmathroundto@impl{#1}% + \pgfmath@smuggleone\pgfmathresult + \endgroup +} + + +% Overloaded method. +% +% This variant always uses a FIXED number behind the period and fills +% in zeros if necessary. +% Examples: +% \pgfmathroundtozerofill{1} +% -> \pgfmathresult = '1.00' +% +% \pgfmathroundtozerofill{19999.9996} +% -> \pgfmathresult = '20000.00' +% +% SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set. +\def\pgfmathroundtozerofill#1{% + \pgfmathfloatroundhasperiodtrue + \begingroup + \pgfmathfloat@fixed@digits@after@periodtrue + \pgfmathroundto@impl{#1}% + \pgfmath@smuggleone\pgfmathresult + \endgroup +} + +% see \pgfmathprintnumber@fixed@style for docs +\def\pgfmathprintnumber@fixed@styleDEFAULT#1#2#3e#4\relax{% + \begingroup + \pgfkeysgetvalue{/pgf/number format/set decimal separator}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP + \pgfkeysgetvalue{/pgf/number format/@dec sep mark}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK + \pgfkeysgetvalue{/pgf/number format/set thousands separator}\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP + \c@pgf@counta=#4\relax + \ifnum#2=0 + \c@pgf@counta=0 + \fi + \def\pgfmathresult{}% + \ifpgfmathfloatroundhasperiod + \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@period#1\pgfmathfloat@EOI + \else + \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI% + \begingroup + \toks0=\expandafter{\pgfmathresult}% + \toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK}% + \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }% + \endgroup + \let\pgfmathresult=\pgfmathfloat@glob@TMP + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup +} +\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@period#1.#2\pgfmathfloat@EOI{% + \ifpgfmathprintnumberskipzeroperiod + \def\pgfmathfloat@loc@TMPb{#1}% + \ifx\pgfmathfloatparsenumber@tok@ZERO\pgfmathfloat@loc@TMPb + \else + \def\pgfmathfloat@loc@TMPc{-0}% + \ifx\pgfmathfloat@loc@TMPc\pgfmathfloat@loc@TMPb + \def\pgfmathresult{-}% + \else + \def\pgfmathfloat@loc@TMPc{+0}% + \ifx\pgfmathfloat@loc@TMPc\pgfmathfloat@loc@TMPb + \def\pgfmathresult{+}% + \else + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI + \fi + \fi + \fi + \else + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI + \fi + \begingroup + \toks0=\expandafter{\pgfmathresult}% + \toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK}% + \toks2=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP #2}% + \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 }% + \endgroup + \let\pgfmathresult=\pgfmathfloat@glob@TMP +}% +\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod{% + \ifx\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP\pgfutil@empty + \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{% + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}% + \else + \ifnum\c@pgf@counta<0\relax + \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{% + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}% + \else + \ifnum\c@pgf@counta<\pgfkeysvalueof{/pgf/number format/min exponent for 1000 sep}\relax + \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{% + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}% + \else + \advance\c@pgf@counta by1 % counta:= total number of digits, N. + \c@pgf@countb=\c@pgf@counta + \divide\c@pgf@countb by3 % countb := N DIV 3 + \c@pgf@countc=\c@pgf@countb + \multiply\c@pgf@countc by3 + \advance\c@pgf@counta by-\c@pgf@countc% now counta := N MOD 3 + \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{% + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printsign + }% + \fi + \fi + \fi + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT +} +\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printsign#1{% + \def\pgfmathfloat@loc@TMPb{#1}% + \ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@MINUS + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}% + \let\pgfmathfloat@loc@TMPb=\pgfutil@empty + \else + \ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@PLUS + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}% + \let\pgfmathfloat@loc@TMPb=\pgfutil@empty + \else + \ifpgfmathprintnumber@showpositive + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult +}% + \fi + \fi + \fi + \ifnum\c@pgf@counta>0 + \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{% + \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printtrailingdigits\pgfmathfloat@loc@TMPb + }% + \else + \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{% + \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird\pgfmathfloat@loc@TMPb + }% + \fi + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT +} +\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printtrailingdigits#1#2{% + \ifcase\c@pgf@counta + \or + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}% + \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{% + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird#2% + }% + \or + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1#2}% + \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{% + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird% + }% + \fi + \ifnum\c@pgf@countb>0\relax + \begingroup + \toks0=\expandafter{\pgfmathresult}% + \toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP}% + \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }% + \endgroup + \let\pgfmathresult=\pgfmathfloat@glob@TMP + \fi + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT +} +\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird#1#2#3{% + \ifnum\c@pgf@countb>0\relax + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1#2#3}% + \advance\c@pgf@countb by-1 + \ifnum\c@pgf@countb>0\relax + \begingroup + \toks0=\expandafter{\pgfmathresult}% + \toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP}% + \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }% + \endgroup + \let\pgfmathresult=\pgfmathfloat@glob@TMP + \fi + \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{% + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird% + }% + \else + % in thise case, #1#2#3 are expected to be + % \pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI + %-------------------------------------------------- + % \def\pgfmathfloat@loc@TMPb{\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI}% + % \def\pgfmathfloat@loc@TMPc{#1#2#3}% + % \ifx\pgfmathfloat@loc@TMPc\pgfmathfloat@loc@TMPb + % \else + % \pgfmath@error{INTERNAL ERROR in fixed style - The input sequence did not terminate as expected; which indicates a wrong exponent argument provided to \string\pgfmathprintnumber@fixed@style}{}% + % \fi + %-------------------------------------------------- + \let\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT=\relax + \fi + \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT +} +\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall#1{% + \def\pgfmathfloat@loc@TMPb{#1}% + \let\pgfmathfloat@loc@TMPc=\pgfutil@empty + \ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@MINUS + \else + \ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@PLUS + \else + \ifpgfmathprintnumber@showpositive + \def\pgfmathfloat@loc@TMPc{+}% + \fi + \fi + \fi + \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall@\pgfmathfloat@loc@TMPc#1% +} +\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall@#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI{% + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}% +}% + +% @deprecated. It has been replaced by \pgfmathprintnumber@fixed@styleDEFAULT +% #1 maybe a macro +\def\pgfmathprintnumber@fixed@stylePERIOD#1#2#3e#4\relax{% + \def\pgfmathresult{#1}% +} + +% @deprecated. It has been replaced by \pgfmathprintnumber@fixed@styleDEFAULT +% #1 maybe a macro +\def\pgfmathprintnumber@fixed@styleCOMMA#1#2#3e#4\relax{% + \ifpgfmathfloatroundhasperiod + \expandafter\pgfmathprintnumber@fixed@styleCOMMA@impl#1\pgfmathfloat@EOI + \else + \def\pgfmathresult{#1}% + \fi +} +\def\pgfmathprintnumber@fixed@styleCOMMA@impl#1.#2\pgfmathfloat@EOI{\def\pgfmathresult{#1{,}#2}} + +% The default style to display fixed point numbers. +% +% It does not apply numerics, but it is responsable to typeset the +% rounded number. +% It can access the \ifpgfmathfloatroundhasperiod boolean. +% +% Arguments: +% #1#2#3e#4\relax + +% Input: +% #1 the fixed point number to be displayed (maybe a macro). +% #2#3e#4: the (possibly unformatted) floating point representation +% which belongs to #1. This format is returned (only!) by +% \pgfmathfloat@to@FMeE@style. +% It is used to determine sign and exponent. +\let\pgfmathprintnumber@fixed@style=\pgfmathprintnumber@fixed@styleDEFAULT + + +% Rounds a normalized floating point number to \pgfmathfloat@round@precision +% digits precision and writes the result to \pgfmathresult. +% +% This method uses \pgfmathroundto for the mantissa. +% +% @see pgfmathfloatroundzerofill +% +% SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set to +% whether the final mantissa #5 has a period or not. +\def\pgfmathfloatround#1{% + \pgfmathfloatroundhasperiodtrue + \begingroup + \pgfmathfloat@fixed@digits@after@periodfalse + \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \pgfmathfloatround@impl + \pgfmath@smuggleone\pgfmathresult + \endgroup +} + +% Overload. +% +% This method uses a fixed width for the mantissa and fills in zeros +% if necessary. +% +% This method uses \pgfmathroundtozerofill for the mantissa. +% +% SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set to +% whether the final mantissa #5 has a period or not. +\def\pgfmathfloatroundzerofill#1{% + \pgfmathfloatroundhasperiodtrue + \begingroup + \pgfmathfloat@fixed@digits@after@periodtrue + \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \pgfmathfloatround@impl + \pgfmath@smuggleone\pgfmathresult + \endgroup +} + +\newif\ifpgfmathfloatround@allow@empty@mantissa +\def\pgfmathfloatround@mantissa@ONE{1.0}% + +% #1: sign +% #2: mantissa +% #3: exponent +% #4: CODE to display if the mantissa is drawn. +% This code will be shown just before the exponent. +% Example: #4=\cdot +% #5: CODE to display if the mantissa is NOT draw. (unused currently) +% Might be used to display '10^1' instead of '1*10^1'. +% #6: CODE to display the exponent. +\def\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax#4#5#6{% + \pgfkeysgetvalue{/pgf/number format/@sci exponent mark}\pgfmathfloatrounddisplaystyle@e@mark + \ifcase#1\relax + \pgfmathprintnumber@fixed@style{#2}#1#2e0\relax% + \expandafter\pgfmathfloatrounddisplaystyle@shared@impl@\expandafter{\pgfmathresult}{#4#6}% + \or\pgfmathprintnumber@fixed@style{#2}#1#2e0\relax% + \expandafter\pgfmathfloatrounddisplaystyle@shared@impl@\expandafter{\pgfmathresult}{#4#6}% + \or\pgfmathprintnumber@fixed@style{-#2}#1#2e0\relax% + \expandafter\pgfmathfloatrounddisplaystyle@shared@impl@\expandafter{\pgfmathresult}{#4#6}% + \or + \pgfmathfloatrounddisplaystyle@shared@impl@@{\hbox{NaN}}{}% + \or + \ifpgfmathprintnumber@showpositive + \pgfmathfloatrounddisplaystyle@shared@impl@@{+\infty}{}% + \else + \pgfmathfloatrounddisplaystyle@shared@impl@@{\infty}{}% + \fi + \or + \pgfmathfloatrounddisplaystyle@shared@impl@@{-\infty}{}% + \fi +} + +% #1: the part before the exponent code +% #2: the part for the exponent code. +\def\pgfmathfloatrounddisplaystyle@shared@impl@#1#2{% + {\toks0={#1}% + \toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}% + \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }% + }% + \let\pgfmathresult=\pgfmathfloat@glob@TMP +}% +% Same as \pgfmathfloatrounddisplaystyle@shared@impl@, but it also +% inserts the '@dec sep mark' at the end. +\def\pgfmathfloatrounddisplaystyle@shared@impl@@#1#2{% + {\toks0={#1}% + \toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}% + \pgfkeysgetvalue{/pgf/number format/@dec sep mark}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK + \toks2=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK}% + \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 }% + }% + \let\pgfmathresult=\pgfmathfloat@glob@TMP +} + +\def\pgfmathfloatrounddisplaystyle@std#1#2e#3\relax{% + \pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{\cdot}{}{10^{#3}}% +} +\def\pgfmathfloatrounddisplaystyle@subscript#1#2e#3\relax{% + \pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}{_{#3}}% +} +\def\pgfmathfloatrounddisplaystyle@superscript#1#2e#3\relax{% + \pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}{^{#3}}% +} +\def\pgfmathfloatrounddisplaystyle@e#1#2e#3\relax{% + \ifnum#3<0\relax + {\count0=#3\relax + \multiply\count0 by-1 + \xdef\pgfmathfloat@glob@TMP{e{-}\the\count0}% + }% + \let\pgfmathresult=\pgfmathfloat@glob@TMP + \else + \def\pgfmathresult{e{+}#3}% + \fi + \def\pgfmathfloat@loc@TMPb{\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}}% + \expandafter\pgfmathfloat@loc@TMPb\expandafter{\pgfmathresult}% +} +\def\pgfmathfloatrounddisplaystyle@E#1#2e#3\relax{% + \ifnum#3<0\relax + {\count0=#3\relax + \multiply\count0 by-1 + \xdef\pgfmathfloat@glob@TMP{E{-}\the\count0}% + }% + \let\pgfmathresult=\pgfmathfloat@glob@TMP + \else + \def\pgfmathresult{E{+}#3}% + \fi + \def\pgfmathfloat@loc@TMPb{\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}}% + \expandafter\pgfmathfloat@loc@TMPb\expandafter{\pgfmathresult}% +} + +\def\pgfmathfloatrounddisplaystyle@generic#1#2e#3\relax{% + \begingroup + \pgfkeysvalueof {/pgf/number format/sci generic/@/.@cmd}{#3}{#1}{#2}\pgfeov + \pgfkeysgetvalue{/pgf/number format/sci generic/mantissa sep}\pgfmathdisplay@aftermantissa + \pgfkeysgetvalue{/pgf/number format/sci generic/empty mantissa sep}\pgfmathdisplay@nomantissa + \pgfkeysgetvalue{/pgf/number format/sci generic/exponent}\pgfmathdisplay@e + \toks0=\expandafter{\pgfmathdisplay@aftermantissa}% + \toks1=\expandafter{\pgfmathdisplay@nomantissa}% + \toks2=\expandafter{\pgfmathdisplay@e}% + \xdef\pgfmathfloat@glob@TMP{\noexpand\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\noexpand\relax{\the\toks0}{\the\toks1}{\the\toks2}}% + \endgroup + \pgfmathfloat@glob@TMP +} + +% A macro which takes the argument '<SIGN><MANTISSE>e<EXPONENT>' and +% expands to the final TeX-representation for that floating point +% number. +% +% PRECONDITION: +% the floating point number has already been rounded properly and +% the mantissa has been rounded correcty. +% +% The argument needs to be in the format returned by +% \pgfmathfloat@to@FMeE@style and terminated by '\relax'. +\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@std +\newif\ifpgfmathfloat@usezerofill@sci +\newif\ifpgfmathfloat@usezerofill@fixed +\newif\ifpgfmathprintnumber@assumemathmode +\newif\ifpgfmathprintnumber@showpositive +\newif\ifpgfmathprintnumber@frac@warn +\newif\ifpgfmathprintnumber@frac@whole + +\long\def\pgfmathfloatfrac@verbatim#1#2{#1/#2}% + +\pgfkeys{% + /pgf/number format/.is family, + /pgf/number format, + fixed/.code= \pgfmath@set@number@printer{pgfmathprintnumber@FIXED}, + sci/.code= \pgfmath@set@number@printer{pgfmathprintnumber@SCI}, + std/.code= {\pgfmath@set@number@printer{pgfmathprintnumber@STD}\pgfmathprintnumber@STD@setparam{#1}}, + std/.default=,% + int detect/.code= \pgfmath@set@number@printer{pgfmathprintnumber@INT@DETECT}, + int trunc/.code= \pgfmath@set@number@printer{pgfmathprintnumber@INT@TRUNC}, + frac/.code= \pgfmath@set@number@printer{pgfmathprintnumber@frac},% + frac TeX/.initial=\frac, + frac whole format/.code={\def\pgfmathresult{#1}}, + frac denom/.initial=, + frac whole/.is if=pgfmathprintnumber@frac@whole, + frac whole=true, + frac shift/.initial=4, + frac warning/.is if=pgfmathprintnumber@frac@warn, + frac warning=true, + assume math mode/.is if=pgfmathprintnumber@assumemathmode, + assume math mode/.default=true, + fixed zerofill/.is if= pgfmathfloat@usezerofill@fixed, + fixed zerofill/.default=true, + sci zerofill/.is if= pgfmathfloat@usezerofill@sci, + sci zerofill/.default=true, + zerofill/.style= {/pgf/number format/fixed zerofill=#1,/pgf/number format/sci zerofill=#1}, + zerofill/.default= true, + precision/.store in= \pgfmathfloat@round@precision, + sci precision/.code={% + \edef\pgfmathfloat@loc@TMPa{#1}% + \ifx\pgfmathfloat@loc@TMPa\pgfutil@empty + \def\pgfmathprintnumber@sci@precision{\pgfmathfloat@round@precision}% + \else + \let\pgfmathprintnumber@sci@precision=\pgfmathfloat@loc@TMPa + \fi + },% + sci precision/.default=, + sci precision=, + fixed default/.code= {\let\pgfmathprintnumber@fixed@style=\pgfmathprintnumber@fixed@styleDEFAULT}, + set decimal separator/.initial=, + dec sep/.style={/pgf/number format/set decimal separator=#1}, + @dec sep mark/.initial=, + @sci exponent mark/.initial=, + set thousands separator/.initial=, + 1000 sep/.style={/pgf/number format/set thousands separator=#1}, + min exponent for 1000 sep/.initial=0, + use period/.style= {/pgf/number format/set decimal separator={.},/pgf/number format/set thousands separator={{{,}}}}, + use comma/.style= {/pgf/number format/set decimal separator={{{,}}},/pgf/number format/set thousands separator={.}}, + showpos/.is if=pgfmathprintnumber@showpositive, + showpos/.default=true, + print sign/.is if=pgfmathprintnumber@showpositive, + print sign/.default=true, + skip 0./.is if=pgfmathprintnumberskipzeroperiod, + skip 0./.default=true, + skip 0.= false, + use period, + sci 10^e/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@std}, + sci 10e/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@std}, + sci e/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@e}, + sci E/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@E}, + sci subscript/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@subscript}, + sci superscript/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@superscript}, + sci generic/.code= {% + \let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@generic + \pgfkeysdefargs{/pgf/number format/sci generic/@}% + {##1##2##3}% + {\pgfqkeys{/pgf/number format/sci generic}{#1}}% + }, + sci generic/mantissa sep/.initial=,% + sci generic/empty mantissa sep/.initial=,% + sci generic/mantisse sep/.style={/pgf/number format/sci generic/mantissa sep={#1}},% + sci generic/empty mantisse sep/.style={/pgf/number format/sci generic/empty mantissa sep={#1}},% + sci generic/exponent/.initial=,% + sci generic/.value required, + verbatim/.code={% + \pgfqkeys{/pgf/number format}{% + sci generic={mantissa sep=,exponent={e##1}}, + 1000 sep=, + skip 0.=false, + print sign=false, + dec sep=., + assume math mode, + frac TeX=\pgfmathfloatfrac@verbatim, + frac whole format/.code={\def\pgfmathresult{##1 }}, + @dec sep mark=, + @sci exponent mark=, + }% + }, +% sci may skip mantissa/.is if=pgfmathfloatround@allow@empty@mantissa, +% sci may skip mantissa/.default=true, +} + + + +\def\pgfmathprintnumber@STD#1{% + % parse the input: + \pgfmathfloatparsenumber{#1}% + \pgfmathfloat@to@FMeE@style\pgfmathresult + \expandafter\pgfmathprintnumber@STD@issci\pgfmathresult\relax +} + +\def\pgfmathprintnumber@STD@setparam#1{% + \edef\pgfmathfloat@loc@TMPb{#1}% + \ifx\pgfmathfloat@loc@TMPb\pgfutil@empty + % DEFAULT for lower and upper bound. + \def\pgfmathprintnumber@STD@getlowerbound{% + \c@pgf@counta=\pgfmathfloat@round@precision\relax + \divide\c@pgf@counta by-2\relax + }% + \def\pgfmathprintnumber@STD@upperbound{4}% + \else + \expandafter\pgfutil@in@\expandafter:\expandafter{\pgfmathfloat@loc@TMPb}% + \ifpgfutil@in@ + % we have -4:5 or something like that. + % parse both values: + \def\pgfmathfloat@loc@TMPa##1:##2\relax{% + \edef\pgfmathprintnumber@STD@getlowerbound{% + \noexpand\c@pgf@counta=##1\space + }% + \edef\pgfmathprintnumber@STD@upperbound{##2}% + }% + \expandafter\pgfmathfloat@loc@TMPa\pgfmathfloat@loc@TMPb\relax + \else + % we have just the lower bound: + \def\pgfmathprintnumber@STD@upperbound{4}% + \edef\pgfmathprintnumber@STD@getlowerbound{% + \noexpand\c@pgf@counta=\pgfmathfloat@loc@TMPb\space + }% + \fi + \fi +}% + +\def\pgfmathprintnumber@STD@issci#1#2e#3\relax{% + \expandafter\ifnum#1<3 + \expandafter\ifnum#3>\pgfmathprintnumber@STD@upperbound\relax + \pgfmathprintnumber@SCI@issci#1#2e#3\relax% + \else + \begingroup + \pgfmathprintnumber@STD@getlowerbound + \ifnum#3<\c@pgf@counta + \pgfmathprintnumber@SCI@issci#1#2e#3\relax% + \else + \pgfmathprintnumber@FIXED@issci#1#2e#3\relax% + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup + \fi + \else% nan or inf: + \pgfmathfloatrounddisplaystyle#1#2e#3\relax% + \fi +} + +\def\pgfmathprintnumber@frac#1{% + % parse the input: + \pgfmathfloatparsenumber{#1}% + \pgfmathfloatgetfrac{\pgfmathresult}% + \expandafter\pgfmathprintnumber@frac@formatresult\pgfmathresult +} +\def\pgfmathprintnumber@frac@issci#1#2e#3\relax{% + \pgfmathfloatcreate{#1}{#2}{#3}% + \pgfmathfloatgetfrac{\pgfmathresult}% + \expandafter\pgfmathprintnumber@frac@formatresult\pgfmathresult +} +\def\pgfmathprintnumber@frac@formatresult#1#2#3{% + \begingroup + \pgfkeysgetvalue{/pgf/number format/frac TeX}\pgfmathresult + \toks0=\expandafter{\pgfmathresult}% + \def\pgfmathfloat@loc@TMPa{#1}% + \ifx\pgfmathfloat@loc@TMPa\pgfutil@empty + \ifpgfmathprintnumber@showpositive + \def\pgfmathfloat@loc@TMPa{+}% + \fi + \else + \ifx\pgfmathfloat@loc@TMPa-% + \else + \ifx\pgfmathfloat@loc@TMPa+% + \else + \ifpgfmathprintnumber@showpositive + \edef\pgfmathfloat@loc@TMPa{+\pgfmathfloat@loc@TMPa}% + \fi + \def\pgfmathfloat@loc@TMPb{\pgfkeysvalueof{/pgf/number format/frac whole format/.@cmd}}% + \expandafter\pgfmathfloat@loc@TMPb\pgfmathfloat@loc@TMPa\pgfeov + \let\pgfmathfloat@loc@TMPa=\pgfmathresult + \fi + \fi + \fi + \toks1=\expandafter{\pgfmathfloat@loc@TMPa}% + \edef\pgfmathresult{% + \the\toks1 \ifnum#2=0 \else\the\toks0 {#2}{#3}\fi% + }% + \pgfmath@smuggleone\pgfmathresult + \endgroup +}% + +% Defines \pgfmathresult to contain three sets of braces containing +% the sign (optionally containing any components >1), the numerator and the denominator for #1. +% +% \pgfmathfloatgetfrac{0.5} -> \pgfmathresult contains {}{1}{2} +% \pgfmathfloatgetfrac{-0.5} -> \pgfmathresult contains {-}{1}{2} +% \pgfmathfloatgetfrac{1.5} -> \pgfmathresult contains {1}{1}{2} +% +% special cases: +% \pgfmathfloatgetfrac{0} -> \pgfmathresult contains {0}{0}{1} +% \pgfmathfloatgetfrac{1} -> \pgfmathresult contains {1}{0}{1} +% +% The numerator and denominator is always a number (not empty) +\def\pgfmathfloatgetfrac#1{% + \pgfutil@ifundefined{pgfmathfloatmultiply@}{% + \PackageError{tikz}{Sorry, the number format 'frac' requires '\string\usetikzlibrary{fpu}' (and, optionally, \string\usepackage{fp}) in order to work correctly}{}% + \edef\pgfmathresult{{#1}{0}{1}}% + }{% + \pgfmathfloatgetfrac@{#1}% + }% +}% +\def\pgfmathfloatgetfrac@#1{% + \begingroup + \edef\pgfmathfloat@arg{#1}% + \expandafter\pgfmathfloat@decompose@tok\pgfmathfloat@arg\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \def\pgfmathfloat@loc@TMPa{0}% + \ifcase\pgfmathfloat@a@S + % #1 = 0: + \def\pgfmathresult{{0}{0}{1}}% + \or% #1 > 0 + \pgfmathfloat@a@S=1 + \def\pgfmathfloat@loc@TMPa{1}% + \or% #1 < 0 + \pgfmathfloat@a@S=-1 + \def\pgfmathfloat@loc@TMPa{1}% + \or + \edef\pgfmathresult{{}{NaN}{1}}% + \or + \edef\pgfmathresult{{}{\infty}{1}}% + \or + \edef\pgfmathresult{{-}{\infty}{1}}% + \fi + \if1\pgfmathfloat@loc@TMPa + \ifnum\pgfmathfloat@a@E<0 + \def\pgfmathfloat@wholenumber{}% + \else + \pgfmathfloatcreate{1}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% + \pgfmathfloattofixed\pgfmathresult% + \def\pgfmathfloat@loc@TMPa##1.##2\relax{% + \def\pgfmathfloat@wholenumber{##1}% + \pgfmathfloatparsenumber{0.##2}% + }% + \expandafter\pgfmathfloat@loc@TMPa\pgfmathresult\relax + \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@b@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \fi + % + \def\pgfmathfloat@loc@TMPa##1.##2\relax{% + \def\pgfmathfloat@mantissa@first{##1}% + \def\pgfmathfloat@mantissa@ltone{0.##2}% + }% + \expandafter\pgfmathfloat@loc@TMPa\the\pgfmathfloat@a@Mtok\relax + % + \def\pgfmathfloat@loc@@to@int##1.##2\relax##3{% + ##3=##1 + \ifdim0.##2pt>0.5pt + \advance##3 by1 + \fi + }% + % + % alias registers names: + \let\pgfmathresultnumerator=\pgfmathfloat@b@S + \let\pgfmathresultdenom=\pgfmathfloat@b@E + % + \pgfkeysgetvalue{/pgf/number format/frac denom}\pgfmath@target@denominator + \ifx\pgfmath@target@denominator\pgfutil@empty + % + \pgfmathfloat@a@E=-\pgfmathfloat@a@E + \ifdim\pgfmathfloat@mantissa@ltone pt=0pt + \def\pgfmathfloat@factor{1}% + \edef\pgfmathfloat@scaled@numerator{\the\pgfmathfloat@a@Mtok}% + \else + % FIXME : this here is numerically instable. + % + % The errors of 1/r are magnified by 10^k which + % doesn't work. + \pgfutil@ifundefined{FPdiv}{% + \pgfmathfloatparsenumber{\pgfmathfloat@mantissa@ltone}% + \pgfmathfloatreciprocal@{\pgfmathresult}% + }{% + % \usepackage{fp}. + % yields higher absolute precision. + \FPmessagesfalse% + \FPdebugfalse% + \FPdiv\pgfmathresult{1}{\pgfmathfloat@mantissa@ltone}% + \pgfmathfloatparsenumber{\pgfmathresult}% + }% + \let\pgfmathfloat@inv=\pgfmathresult + \pgfmathfloatcreate{1}{1.0}{\pgfkeysvalueof{/pgf/number format/frac shift}}% + \let\pgfmathfloat@scalebaseten=\pgfmathresult + \pgfmathfloatmultiply@{\pgfmathfloat@inv}{\pgfmathfloat@scalebaseten}% + \let\pgfmathfloat@factor=\pgfmathresult + % + \expandafter\pgfmathfloatparsenumber\expandafter{\the\pgfmathfloat@a@Mtok}% + \let\pgfmathfloat@loc@TMPa=\pgfmathresult + \pgfmathfloatmultiply@{\pgfmathfloat@factor}{\pgfmathfloat@loc@TMPa}% + \pgfmathfloattofixed\pgfmathresult + \let\pgfmathfloat@scaled@numerator=\pgfmathresult + % + \pgfmathfloattofixed\pgfmathfloat@factor + \expandafter\pgfmathfloat@loc@@to@int\pgfmathresult\relax{\pgfmathfloat@b@S}% + \edef\pgfmathfloat@factor{\the\pgfmathfloat@b@S}% + \fi + % + % + \pgfmathresultdenom=\pgfmathfloat@factor\relax + \pgfmathfloat@multiply@ten@to@the@E\pgfmathresultdenom + % + \expandafter\pgfmathfloat@loc@@to@int\pgfmathfloat@scaled@numerator\relax{\pgfmathresultnumerator}% + %\message{scale = \pgfmathfloat@factor; Z = \the\pgfmathresultnumerator\space ( von \pgfmathfloat@scaled@numerator), N = \the\pgfmathresultdenom.}% + % + \pgfmathgreatestcommondivisor{\pgfmathresultnumerator}{\pgfmathresultdenom}% + \divide\pgfmathresultnumerator by\pgfmathresult\relax + \divide\pgfmathresultdenom by\pgfmathresult\relax + \ifpgfmathprintnumber@frac@warn + \ifnum\pgfmathresultdenom>1000 + \pgfutil@ifundefined{FPdiv}{% + \pgfmathfloattosci@\pgfmathfloat@arg + \immediate\write16{! Package pgf /pgf/number format/frac warning=true: /pgf/number format/frac of `\pgfmathresult' = \the\pgfmathresultnumerator\space / \the\pgfmathresultdenom\space might be large due to instabilities. Try \string\usepackage{fp} to improve accuracy.}% + }{}% + \fi + \fi + \else + % use target denominator: + \pgfmathresultdenom=\pgfmath@target@denominator\relax + \pgfmathfloatcreate{1}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}% + \pgfmathfloattofixed\pgfmathresult + \pgf@xa=\pgfmathresult pt + \multiply\pgf@xa by\pgfmathresultdenom + \edef\pgfmathfloat@scaled@numerator{\pgf@sys@tonumber\pgf@xa}% + \expandafter\pgfmathfloat@loc@@to@int\pgfmathfloat@scaled@numerator\relax{\pgfmathresultnumerator}% + \fi + \ifpgfmathprintnumber@frac@whole + \else + \ifx\pgfmathfloat@wholenumber\pgfutil@empty + \else + \count0=\pgfmathfloat@wholenumber\relax + \multiply\count0 by\pgfmathresultdenom + \advance\pgfmathresultnumerator by\count0 + \def\pgfmathfloat@wholenumber{}% + \fi + \fi + \ifnum\pgfmathfloat@a@S<0 + \edef\pgfmathresult{{-\pgfmathfloat@wholenumber}{\the\pgfmathresultnumerator}{\the\pgfmathresultdenom}}% + \else + \edef\pgfmathresult{{\pgfmathfloat@wholenumber}{\the\pgfmathresultnumerator}{\the\pgfmathresultdenom}}% + \fi + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup +}% +\def\pgfmathfloat@gobble@until@relax#1\relax{} + +% computes the greatest common divisor of two integer numbers (in +% integer arithmetics). +\def\pgfmathgreatestcommondivisor#1#2{% + \begingroup + \count0=#1\relax + \count1=#2\relax + \ifnum\count0=0 + \edef\pgfmathresult{\the\count1}% + \else + \pgfmathgreatestcommondivisor@loop + \edef\pgfmathresult{\the\count0}% + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup +} +\def\pgfmathgreatestcommondivisor@loop{% + \ifnum\count1=0 + \else + \ifnum\count0>\count1 + \advance\count0 by-\count1 + \else + \advance\count1 by-\count0 + \fi + \expandafter\pgfmathgreatestcommondivisor@loop + \fi +}% + +% multiplies a TeX register by 10^E where E is stored in the register +% \pgfmathfloat@a@E (and it should be positive!)% +% +% #1 a TeX register +\def\pgfmathfloat@multiply@ten@to@the@E#1{% + \ifnum\pgfmathfloat@a@E>0 + \multiply#1 by10 + \advance\pgfmathfloat@a@E by-1 + \def\pgfmathfloat@multiply@ten@to@the@E@next{\pgfmathfloat@multiply@ten@to@the@E{#1}}% + \else + \let\pgfmathfloat@multiply@ten@to@the@E@next=\relax% + \fi + \pgfmathfloat@multiply@ten@to@the@E@next +}% + +\def\pgfmathprintnumber@INT@TRUNC#1{% + \pgfmathfloatparsenumber{#1}% + \pgfmathfloat@to@FMeE@style\pgfmathresult + \expandafter\pgfmathprintnumber@INT@TRUNC@issci\pgfmathresult\relax +} + +\def\pgfmathprintnumber@INT@TRUNC@impl#1.#2\relax#3#4e#5\relax{% + \pgfmathfloatroundhasperiodfalse + \pgfmathprintnumber@fixed@style{#1}#3#4e#5\relax% +} +\def\pgfmathprintnumber@INT@TRUNC@issci#1#2e#3\relax{% + \ifnum#1<3\relax + \pgfmathfloatcreate{#1}{#2}{#3}% + \pgfmathfloattofixed{\pgfmathresult}% + \expandafter\pgfmathprintnumber@INT@TRUNC@impl\pgfmathresult\relax#1#2e#3\relax + \else + \pgfmathfloatrounddisplaystyle#1#2e#3\relax% + \fi +} + +% Invokes '#2' if '#1' is actually an integer or '#3' if not. +% +% As a side--effect, \pgfretval will be set to the integer value if it +% actually *is* an integer. Otherwise, \pgfretval will contain the +% parsed floating point number. +% +% #1 a number constant (not necessarily a parsed float). +\def\pgfmathifisint#1#2#3{% + \gdef\pgfmathfloatisint@@{0}% + \begingroup + \pgfmathfloatparsenumber{#1}% + \let\pgfretval\pgfmathresult + \pgfmathfloat@to@FMeE@style\pgfmathresult + \expandafter\pgfmathfloatisint@\pgfmathresult\relax + \pgfmath@smuggleone\pgfretval + \endgroup + \if1\pgfmathfloatisint@@ #2\else #3\fi +}% +\def\pgfmathfloatisint@#1#2e#3\relax{% + \ifnum#1<3\relax + \pgfmathfloatcreate{#1}{#2}{#3}% + \pgfmathfloattofixed{\pgfmathresult}% + \def\pgfmathfloat@round@precision{6}% + \expandafter\pgfmathroundto\expandafter{\pgfmathresult}% + \ifpgfmathfloatroundhasperiod + \else + \let\pgfretval\pgfmathresult% + \gdef\pgfmathfloatisint@@{1}% + \fi + \fi +} + +\def\pgfmathprintnumber@INT@DETECT#1{% + \pgfmathfloatparsenumber{#1}% + \pgfmathfloat@to@FMeE@style\pgfmathresult + \expandafter\pgfmathprintnumber@INT@DETECT@issci\pgfmathresult\relax +} + +\def\pgfmathprintnumber@INT@DETECT@issci#1#2e#3\relax{% + \begingroup + \ifnum#1<3\relax + \pgfmathfloatcreate{#1}{#2}{#3}% + \pgfmathfloattofixed{\pgfmathresult}% + \let\pgfmathfloat@round@precision@=\pgfmathfloat@round@precision + \def\pgfmathfloat@round@precision{6}% + \expandafter\pgfmathroundto\expandafter{\pgfmathresult}% + \let\pgfmathfloat@round@precision=\pgfmathfloat@round@precision@ + \ifpgfmathfloatroundhasperiod + \pgfmathprintnumber@SCI@issci#1#2e#3\relax + \else + \expandafter\pgfmathprintnumber@fixed@style\expandafter{\pgfmathresult}#1#2e#3\relax + \fi + \else + \pgfmathfloatrounddisplaystyle#1#2e#3\relax% + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup +} + +\def\pgfmathprintnumber@FIXED#1{% + \pgfmathfloatparsenumber{#1}% + \pgfmathfloat@to@FMeE@style\pgfmathresult + \expandafter\pgfmathprintnumber@FIXED@issci\pgfmathresult\relax +} + +\def\pgfmathprintnumber@FIXED@issci#1#2e#3\relax{% + \begingroup + \ifnum#1<3 + \pgfmathfloatcreate{#1}{#2}{#3}% + \pgfmathfloattofixed{\pgfmathresult}% + \ifpgfmathfloat@usezerofill@fixed + \expandafter\pgfmathroundtozerofill\expandafter{\pgfmathresult}% + \else + \expandafter\pgfmathroundto\expandafter{\pgfmathresult}% + \fi + \ifpgfmathfloatroundmayneedrenormalize + \pgfmathfloat@a@E=#3\relax + \advance\pgfmathfloat@a@E by1 + \edef\pgfmathfloat@loc@TMPb{\noexpand\pgfmathprintnumber@fixed@style{\pgfmathresult}#1#2e\the\pgfmathfloat@a@E}% + \pgfmathfloat@loc@TMPb\relax% + \else + \expandafter\pgfmathprintnumber@fixed@style\expandafter{\pgfmathresult}#1#2e#3\relax% + \fi + \else% nan or inf: + \pgfmathfloatrounddisplaystyle#1#2e#3\relax% + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup +} + + +\def\pgfmathprintnumber@SCI#1{% + \pgfmathfloatparsenumber{#1}% + \pgfmathfloat@to@FMeE@style\pgfmathresult + \expandafter\pgfmathprintnumber@SCI@issci\pgfmathresult\relax +} + +\def\pgfmathprintnumber@SCI@issci#1#2e#3\relax{% + \begingroup + \pgfmathfloatcreate{#1}{#2}{#3}% + \edef\pgfmathfloat@round@precision{\pgfmathprintnumber@sci@precision}% + \ifpgfmathfloat@usezerofill@sci + \pgfmathfloatroundzerofill{\pgfmathresult}% + \else + \pgfmathfloatround{\pgfmathresult}% + \fi + \pgfmathfloat@to@FMeE@style\pgfmathresult + \expandafter\pgfmathfloatrounddisplaystyle\pgfmathresult\relax + \pgfmath@smuggleone\pgfmathresult + \endgroup +} + +% Prints argument #1 using the current pretty printer environment (all +% variables in /pgf/number format). +% +% You may specify optional arguments with \pgfmathprintnumber[...]. +\def\pgfmathprintnumber{% + % \protect allows to supply \pgfmathprintnumber inside of latex + % captions. The \csname yields \relax in case protect is undefined. + \pgf@texdist@protect\pgfmathprintnumber@protected +}% +\def\pgfmathprintnumber@protected{% + \pgfutil@ifnextchar[% + {\pgfmathprintnumber@OPT}% + {\pgfmathprintnumber@noopt}% +} + +\def\pgfmathprintnumber@noopt#1{% + \pgfmathprintnumber@{#1}% + \ifpgfmathprintnumber@assumemathmode + \pgfmathresult + \else + \pgfutilensuremath{\pgfmathresult}% + \fi +}% +\def\pgfmathprintnumber@OPT[#1]#2{% + \begingroup + \pgfqkeys{/pgf/number format}{#1}% + \pgfmathprintnumber@{#2}% + \ifpgfmathprintnumber@assumemathmode + \pgfmathresult + \else + \pgfutilensuremath{\pgfmathresult}% + \fi + \endgroup +}% + +% As \pgfmathprintnumber, but it produces its output into the second +% argument. +\def\pgfmathprintnumberto{% + \pgfutil@ifnextchar[% + {\pgfmathprintnumberto@OPT}% + {\pgfmathprintnumberto@noopt}% +} + +\def\pgfmathprintnumberto@noopt#1#2{% + \begingroup + \pgfmathprintnumber@{#1}% + \ifpgfmathprintnumber@assumemathmode + \global\let\pgfmathfloat@glob@TMP=\pgfmathresult + \else + \toks0=\expandafter{\pgfmathresult}% + \xdef\pgfmathfloat@glob@TMP{\noexpand\pgfutilensuremath{\the\toks0 }}% + \fi + \endgroup + \let#2=\pgfmathfloat@glob@TMP +}% +\def\pgfmathprintnumberto@OPT[#1]#2#3{% + \begingroup + \pgfqkeys{/pgf/number format}{#1}% + \pgfmathprintnumber@{#2}% + \ifpgfmathprintnumber@assumemathmode + \global\let\pgfmathfloat@glob@TMP=\pgfmathresult + \else + \toks0=\expandafter{\pgfmathresult}% + \xdef\pgfmathfloat@glob@TMP{\noexpand\pgfutilensuremath{\the\toks0 }}% + \fi + \endgroup + \let#3=\pgfmathfloat@glob@TMP +}% + + +% Changes the current number pretty printer to #1. +% +% #1 is the macro base name for the pretty print routine, without the +% leading '\'. +\def\pgfmath@set@number@printer#1{% + \expandafter\let\expandafter\pgfmathprintnumber@\csname #1\endcsname + \expandafter\let\expandafter\pgfmathprintnumber@issci\csname #1@issci\endcsname +} + +\pgfkeys{/pgf/number format/std} + +%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% IMPL +% +%%%%%%%%%%%%%%%%%%%%%%%%%% + +% equals only itsself when compared with \ifx: +\def\pgfmathfloat@EOI{\pgfmathfloat@EOI}% + +% Re-use counters internally. +% +% They are always grouped and only used inside of the rounding +% routines. +\let\c@pgfmathroundto@prec=\pgfmathfloat@b@S% ATTENTION: DOUBLE-USED REGISTERS! +\let\c@pgfmathroundto@offsetbehindperiod=\pgfmathfloat@b@E +\newcount\c@pgfmathroundto@lastzeros + +\newif\ifpgfmathround@impl@PREPERIOD@is@negative@zero + +% PRECONDITION: +% \ifpgfmathfloatroundhasperiod=\iftrue holds outside of the +% current TeX group. +% +% POSTCONDITION: +% \ifpgfmathfloatroundhasperiod will be set correctly AFTER the +% current TeX group. +% \ifpgfmathfloatroundmayneedrenormalize will be set globally +\def\pgfmathroundto@impl#1{% + \edef\pgfmathround@input{#1}% + \global\pgfmathfloatroundmayneedrenormalizefalse + \pgfmathfloat@tmptoks={}% + \let\pgfmathround@next=\pgfutil@empty + \let\pgfmathround@cur=\pgfutil@empty + \let\pgfmathresult=\pgfutil@empty + \expandafter\c@pgfmathroundto@prec\pgfmathfloat@round@precision\relax + \c@pgfmathroundto@lastzeros=0 + \c@pgfmathroundto@offsetbehindperiod=-1 % means: no period found so far + \pgfmathround@impl@PREPERIOD@is@negative@zerotrue + \expandafter\pgfmathroundto@impl@ITERATE@NODOT@firstcall\pgfmathround@input\pgfmathfloat@EOI +} + +% \pgfmathroundto implementation in WORDS: +% +% coarse idea: +% 1. collect all digits/sign BEFORE the first period in REVERSE order +% 2. then, collect UP TO \prec digits after the period in REVERSE order +% Steps 1. and 2. lead to the digit [sign] sequence +% "x_{-p} x_{-p+1} ... x_{-2} x_{-1} '.' x_0 ... x_r" +% where 'r' is the total number of digits. The integer 'p' denotes the +% ACTUALLY collected number of digits behind the period. +% +% Let 'k' be the desired precision. +% +% Please note that pgfmathroundto rounds the mantissa, that means |abs(x)|. +% +% There are exactly TWO cases: +% 1. The case with p<=k and x_{-p-1} = end of input. +% 2. The case with p=k and x_{-p-1} is a further, next character. +% +% Then, for case 1.): +% discard any unused zeros at the tail of our number (possibly +% including the period) +% +% and in case 2.) +% if NEXT DIGIT < 5: +% do exactly the same as in case 1.) above and discard any +% following digits. +% else +% let q := -p +% while(x_q = 9 and q<=r ) +% if q>=0 +% set x_q = '0' +% else +% discard digit x_q='9' +% fi +% ++q +% if q=0 +% discard the period +% fi +% end while +% if q = r+1 +% insert a '1' +% else +% set x_q = x_q + 1 +% fi +% fi +% +% All these loops have been implemented in spaghetti-code below. +% Sorry, I fear its hard to understand. In principle, everything is +% realised using more or less finite state machines (with some number +% counting logic). +% +% Some comments: +% - The token register \pgfmathfloat@tmptoks is used to accumulate the REVERSED input number. +% - \pgfmathfloat@EOI always denotes 'END OF INPUT'. +% - in the second stage, we need to reverse \pgfmathfloat@tmptoks. +% This is -again- done with \pgfmathfloat@tmptoks. + +\def\pgfmathroundto@impl@discard@period#1.#2\pgfmathfloat@EOI{% + \pgfmathfloatroundhasperiodfalse + \aftergroup\pgfmathfloatroundhasperiodfalse + \def\pgfmathresult{#1}% +} + +\def\pgfmathroundto@impl@gobble@rest@and@start#1\pgfmathfloat@EOI{% + \pgfmathroundto@impl@start +} +\def\pgfmathroundto@impl@gobble@and@start\pgfmathfloat@EOI{% + \pgfmathroundto@impl@start +} +\def\pgfmathroundto@impl@gobble\pgfmathfloat@EOI{}% +\def\pgfmathroundto@impl@gobble@rest#1\pgfmathfloat@EOI{}% + +% This method will be invoked as soon as the first step, the reverse +% collection of up to PREC digits after the period, has finished. +\def\pgfmathroundto@impl@start{% + \ifx\pgfmathround@next\pgfutil@empty + \ifnum\c@pgfmathroundto@offsetbehindperiod<0 + % no period found. + \ifpgfmathfloat@fixed@digits@after@period + \ifnum\c@pgfmathroundto@prec=0\relax + \pgfmathfloatroundhasperiodfalse + \aftergroup\pgfmathfloatroundhasperiodfalse + \edef\pgfmathresult{\pgfmathround@input}% + \else + \pgfmathfloat@tmptoks=\expandafter{\pgfmathround@input.}% + \c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec + \pgfmathroundto@impl@append@zeros + \edef\pgfmathresult{\the\pgfmathfloat@tmptoks}% + \fi + \else + \pgfmathfloatroundhasperiodfalse + \aftergroup\pgfmathfloatroundhasperiodfalse + \edef\pgfmathresult{\pgfmathround@input}% + \fi + \else + %\ifnum\c@pgfmathroundto@offsetbehindperiod>\c@pgfmathroundto@prec + % \pgfmath@error{Internal logic error in pgfmathroundto at [I] - should not have happened!?}{}% + %\fi + \pgfmathroundto@impl@finish@with@truncation + \fi + \else + %\ifnum\c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec + %\else + % \pgfmath@error{Internal logic error in pgfmathroundto at [II] - should not have happened!? I have offsetbehindperiod=\the\c@pgfmathroundto@offsetbehindperiod and prec = \the\c@pgfmathroundto@prec}{}% + %\fi + \expandafter\ifnum\pgfmathround@next<5\relax + \pgfmathroundto@impl@finish@with@truncation + \else + \multiply\c@pgfmathroundto@offsetbehindperiod by-1 + \expandafter\pgfmathroundto@impl@ADD@ONE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI + \fi + \fi +} + +% takes the current input and decides whether trailing zeros shall be +% discarded or more zeros need to be filled in. +\def\pgfmathroundto@impl@finish@with@truncation{% + \ifpgfmathfloat@fixed@digits@after@period + \expandafter\pgfmathroundto@impl@REVERSE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI + \ifnum\c@pgfmathroundto@lastzeros=\c@pgfmathroundto@offsetbehindperiod + \ifpgfmathround@impl@PREPERIOD@is@negative@zero + % write '0.0000' instead of '-0.0000': + \expandafter\pgfmathroundto@impl@discard@minus\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI + \fi + \fi + \ifnum\c@pgfmathroundto@prec=0\relax + \expandafter\pgfmathroundto@impl@discard@period\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI + \else + \advance\c@pgfmathroundto@prec by-\c@pgfmathroundto@offsetbehindperiod + \c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec + \pgfmathroundto@impl@append@zeros + \edef\pgfmathresult{\the\pgfmathfloat@tmptoks}% + \fi + \else + \pgfmathroundto@impl@discard@suffix@zeros + \fi +} + +\def\pgfmathroundto@impl@discard@minus-#1\pgfmathfloat@EOI{\pgfmathfloat@tmptoks={#1}}% + +% appends \c@pgfmathroundto@offsetbehindperiod zeros at the end of \pgfmathfloat@tmptoks. +\def\pgfmathroundto@impl@append@zeros{% + \ifnum\c@pgfmathroundto@offsetbehindperiod>0 + \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}% + \advance\c@pgfmathroundto@offsetbehindperiod by-1 + \pgfmathroundto@impl@append@zeros + \fi +} + +\def\pgfmathroundto@impl@ADD@ONE{% + \pgfmathfloat@tmptoks={}% no longer needed because its old value will be read from input + \pgfmathroundto@impl@ADD@ONE@ITERATE +} +\def\pgfmathroundto@impl@ADD@ONE@ITERATE{% + \pgfutil@ifnextchar\pgfmathfloat@EOI{% + \global\pgfmathfloatroundmayneedrenormalizetrue + \edef\pgfmathresult{1\the\pgfmathfloat@tmptoks}% + \pgfmathroundto@impl@gobble + }{% + \pgfutil@ifnextchar.{% + \ifnum\c@pgfmathroundto@prec=0 + % silently discard period in special case precision=0 + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE@gobble@dot}% + \else + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@NEXT@COLLECT}% + \fi + \pgfmathround@nextcmd + }{% + \pgfutil@ifnextchar+{% + \global\pgfmathfloatroundmayneedrenormalizetrue + \edef\pgfmathresult{1\the\pgfmathfloat@tmptoks}% + \pgfmathroundto@impl@gobble@rest + }{% + \pgfutil@ifnextchar-{% + \global\pgfmathfloatroundmayneedrenormalizetrue + \edef\pgfmathresult{-1\the\pgfmathfloat@tmptoks}% + \pgfmathroundto@impl@gobble@rest + }{% + \pgfmathroundto@impl@ADD@ONE@NEXT + }% + }% + }% + }% +} + +\def\pgfmathroundto@impl@ADD@ONE@ITERATE@gobble@dot.{% + \pgfmathfloatroundhasperiodfalse + \aftergroup\pgfmathfloatroundhasperiodfalse + \pgfmathroundto@impl@ADD@ONE@ITERATE +} + +\def\pgfmathroundto@impl@ADD@ONE@NEXT@COLLECT#1{% + \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}% + \pgfmathroundto@impl@ADD@ONE@ITERATE +} +\def\pgfmathroundto@impl@ADD@ONE@NEXT#1{% + \ifnum#1=9 + \ifnum\c@pgfmathroundto@offsetbehindperiod<0 + \ifpgfmathfloat@fixed@digits@after@period + \pgfmathfloat@tmptoks=\expandafter{\expandafter0\the\pgfmathfloat@tmptoks}% + \else + % silently DROP digit + \fi + \else + \pgfmathfloat@tmptoks=\expandafter{\expandafter0\the\pgfmathfloat@tmptoks}% + \fi + \advance\c@pgfmathroundto@offsetbehindperiod by1 + \ifnum\c@pgfmathroundto@offsetbehindperiod=0 + \ifpgfmathfloat@fixed@digits@after@period + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE}% + \else + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE@gobble@dot}% + \fi + \else + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE}% + \fi + \else + % re-use this counter: + \c@pgfmathroundto@lastzeros=#1 + \advance\c@pgfmathroundto@lastzeros by1 + \edef\pgfmathresult{\the\c@pgfmathroundto@lastzeros\the\pgfmathfloat@tmptoks}% + \pgfmathfloat@tmptoks=\expandafter{\pgfmathresult}% + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@REVERSE@ITERATE}% + \fi + \pgfmathround@nextcmd +} + + +\def\pgfmathroundto@impl@discard@suffix@zeros{% + \ifnum\c@pgfmathroundto@lastzeros=\c@pgfmathroundto@offsetbehindperiod + \ifpgfmathround@impl@PREPERIOD@is@negative@zero + \pgfmathfloatroundhasperiodfalse + \aftergroup\pgfmathfloatroundhasperiodfalse + \def\pgfmathresult{0}% write '0' instead of '-0' + \else + \expandafter\pgfmathroundto@impl@discard@period\pgfmathround@input\pgfmathfloat@EOI + \fi + \else + \ifnum\c@pgfmathroundto@lastzeros=0 + \expandafter\pgfmathroundto@impl@REVERSE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI + \else + \expandafter\pgfmathroundto@impl@discard@suffix@zeros@ITERATE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI + \fi + \fi +} + +% PRECONDITION: +% \c@pgfmathroundto@lastzeros > 0 +\def\pgfmathroundto@impl@discard@suffix@zeros@ITERATE#1{% + \advance\c@pgfmathroundto@lastzeros by-1 + \ifnum\c@pgfmathroundto@lastzeros=0 + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@REVERSE}% + \else + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@discard@suffix@zeros@ITERATE}% + \fi + \pgfmathround@nextcmd +} + +% Usage: +% \pgfmathroundto@impl@REVERSE#1\pgfmathfloat@EOI +% -> writes #1 reversed into \pgfmathfloat@tmptoks +\def\pgfmathroundto@impl@REVERSE{% + \pgfmathfloat@tmptoks={}% + \pgfmathroundto@impl@REVERSE@ITERATE +} + +\def\pgfmathroundto@impl@REVERSE@ITERATE{% + \pgfutil@ifnextchar\pgfmathfloat@EOI{% + \edef\pgfmathresult{\the\pgfmathfloat@tmptoks}% + \pgfmathroundto@impl@gobble + }{% + \pgfmathroundto@impl@REVERSE@NEXT + }% +} + +\def\pgfmathroundto@impl@REVERSE@NEXT#1{% + \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}% + \pgfmathroundto@impl@REVERSE@ITERATE +} + +\def\pgfmathroundto@impl@BEGIN@DOT.{% + \pgfmathfloat@tmptoks=\expandafter{\expandafter.\the\pgfmathfloat@tmptoks}% + \c@pgfmathroundto@offsetbehindperiod=0 + \pgfmathroundto@impl@ITERATE@DOT +} +\def\pgfmathroundto@impl@ITERATE@DOT{% + \pgfutil@ifnextchar\pgfmathfloat@EOI{% + % finished. + \pgfmathroundto@impl@gobble@and@start + }{% + \pgfmathroundto@impl@NEXT@DOT + }% +} +\def\pgfmathroundto@impl@NEXT@DOT#1{% + \ifnum\c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec + \def\pgfmathround@next{#1}% + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@gobble@rest@and@start}% + \else + \advance\c@pgfmathroundto@offsetbehindperiod by1 + \ifnum#1=0 + \advance\c@pgfmathroundto@lastzeros by1 + \else + \c@pgfmathroundto@lastzeros=0 + \fi + \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}% + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ITERATE@DOT}% + \fi + \pgfmathround@nextcmd +}% + +% in contrast to pgfmathroundto@impl@ITERATE@NODOT, this method here +% checks also for signs +\def\pgfmathroundto@impl@ITERATE@NODOT@firstcall#1{% + \def\pgfmathround@cur{#1}% + \ifx\pgfmathround@cur\pgfmathfloat@EOI + \pgfmathround@impl@PREPERIOD@is@negative@zerofalse + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@start}% + \else + \ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@PERIOD + \pgfmathround@impl@PREPERIOD@is@negative@zerofalse + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@BEGIN@DOT.}% + \else + \ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@MINUS + \else + \pgfmathround@impl@PREPERIOD@is@negative@zerofalse + \fi + \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}% + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ITERATE@NODOT}% + \fi + \fi + \pgfmathround@nextcmd +} + +\def\pgfmathroundto@impl@ITERATE@NODOT#1{% + \def\pgfmathround@cur{#1}% + \ifx\pgfmathround@cur\pgfmathfloat@EOI + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@start}% + \else + \ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@PERIOD + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@BEGIN@DOT.}% + \else + \ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@ZERO + \else + \pgfmathround@impl@PREPERIOD@is@negative@zerofalse + \fi + \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}% + \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ITERATE@NODOT}% + \fi + \fi + \pgfmathround@nextcmd +} + +%-------------------------------------------- +% END of pgfmathroundto implementation. +%-------------------------------------------- + + +% flags, mantissa and exponent has already been stored into +% \pgfmathfloat@a@* [using ...@Mtok] +% +% PRECONDITION: +% \ifpgfmathfloatroundhasperiod = \iftrue outside of the current +% group +% +% POSTCONDITION: +% \ifpgfmathfloatroundhasperiod will be set after the current TeX +% group. +\def\pgfmathfloatround@impl{% + \expandafter\pgfmathroundto@impl\expandafter{\the\pgfmathfloat@a@Mtok}% + \ifpgfmathfloatroundmayneedrenormalize + \ifpgfmathfloatroundhasperiod + \expandafter\pgfmathfloatround@impl@renormalize\pgfmathresult\pgfmathfloat@EOI% + \else + \expandafter\pgfmathfloatround@impl@renormalize\pgfmathresult.\pgfmathfloat@EOI% + \fi + \advance\pgfmathfloat@a@E by1 + \fi + \pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\pgfmathresult}{\the\pgfmathfloat@a@E}% +} + +\def\pgfmathfloatround@impl@renormalize#1#2.#3\pgfmathfloat@EOI{% + \pgfmathroundto@impl{#1.#2#3}% +} + + + + + +% ATTENTION: this thing REQUIRES a period in the mantissa! +% collects everything into \pgfmathresult +\def\pgfmathfloattofixed@impl#1.#2\relax{% + \ifnum\pgfmathfloat@a@E<0 + \ifcase-\pgfmathfloat@a@E + \or%e-1 + \pgfmathfloat@a@Mtok={0.}% + \or%e-2 + \pgfmathfloat@a@Mtok={0.0}% + \or%e-3 + \pgfmathfloat@a@Mtok={0.00}% + \or%e-4 + \pgfmathfloat@a@Mtok={0.000}% + \or%e-5 + \pgfmathfloat@a@Mtok={0.0000}% + \or%e-6 + \pgfmathfloat@a@Mtok={0.00000}% + \or%e-7 + \pgfmathfloat@a@Mtok={0.000000}% + \or%e-8 + \pgfmathfloat@a@Mtok={0.0000000}% + \or%e-9 + \pgfmathfloat@a@Mtok={0.00000000}% + \or%e-10 + \pgfmathfloat@a@Mtok={0.000000000}% + \else%<= -11 + \pgfmathfloat@a@Mtok={0.0000000000}% + \advance\pgfmathfloat@a@E by10 + \pgfutil@loop + \ifnum\pgfmathfloat@a@E<-1 + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok 0}% + \advance\pgfmathfloat@a@E by1 + \pgfutil@repeat + \fi + \def\pgfmathfloat@loc@TMPb{#2}% + \def\pgfmathfloat@loc@TMPc{0}% + \ifx\pgfmathfloat@loc@TMPb\pgfmathfloat@loc@TMPc + \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok #1}% + \else + \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok #1#2}% + \fi + \else + %-------------------------------------------------- + % \ifnum\pgfmathfloat@a@E=0% + % \edef\pgfmathresult{#1.#2}% + % \else + % \pgfmathfloat@a@Mtok={#1}% + % \pgfmathfloattofixed@impl@collectmantissa#2\count\pgfmathfloat@a@E + % \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok}% + % \fi + %-------------------------------------------------- + \pgfmathfloat@a@Mtok{#1}% + \pgfmathfloattofixed@impl@pos#2000000000\pgfmathfloat@EOI + \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok}% + \fi +} + +% FIXME: this implementation here is very fast, but it introduces trailing zeros. Is that acceptable? +\def\pgfmathfloattofixed@impl@pos#1#2#3#4#5#6#7#8#9\pgfmathfloat@EOI{% + \ifcase\pgfmathfloat@a@E + % e+0 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok .#1#2#3#4#5#6#7#8#9}% + \or%e+1 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1.#2#3#4#5#6#7#8#9}% + \or%e+2 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2.#3#4#5#6#7#8#9}% + \or%e+3 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3.#4#5#6#7#8#9}% + \or%e+4 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4.#5#6#7#8#9}% + \or%e+5 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5.#6#7#8#9}% + \or%e+6 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6.#7#8#9}% + \or%e+7 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6#7.#8#9}% + \or%e+8 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6#7#8.#9}% + \else%>=9 + \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6#7#8}% + \advance\pgfmathfloat@a@E by-8 + \pgfmathfloattofixed@impl@collectmantissa#9\count\pgfmathfloat@a@E + \fi +}% + +\def\pgfmathfloattofixed@impl@collectmantissa#1#2\count#3{% + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok #1}% + \advance\pgfmathfloat@a@E by-1% + \def\pgfmathfloat@loc@TMPb{#2}% + \ifx\pgfmathfloat@loc@TMPb\pgfutil@empty + \pgfutil@loop + \ifnum\pgfmathfloat@a@E>0% + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok 0}% + \advance\pgfmathfloat@a@E by-1% + \pgfutil@repeat + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok .0}% + \else + \ifnum\pgfmathfloat@a@E=0 + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok .#2}% + \else + \pgfmathfloattofixed@impl@collectmantissa#2\count#3% + \fi + \fi +} + + +% ============================================ +% +% +% \pgfmathfloatparsenumber implementation +% +% +% ============================================ + +% accepted parser tokens: +\def\pgfmathfloatparsenumber@tok@ZERO{0} +\def\pgfmathfloatparsenumber@tok@PLUS{+} +\def\pgfmathfloatparsenumber@tok@MINUS{-} +\def\pgfmathfloatparsenumber@tok@PERIOD{.} + +\newif\ifpgfmathfloatparsenumberpendingperiod + +\def\pgfflt@EOI{p@EOI}% +\def\pgfflt@EOI@unexpanded{\pgfflt@EOI}% + +% Starts a finite-start-machine parser to read a number. +% +% The machine's state is represented by the macro which is currently +% processed; state transitions are realised using \csname...#1\endcsname +% constructions. +% +% It assigns \pgfmathfloat@a@S, \pgfmathfloat@a@Mtok, \pgfmathfloat@a@E. +\def\pgfflt@impl#1{% + \pgfmathfloatparsenumberpendingperiodfalse + \pgfmathfloat@tmptoks={}% this register is used to collect PENDING ZEROS + \pgfmathfloat@a@E=0 + % start parsing: check for sign: + \expandafter\ifx\csname pgfflt@#1\endcsname\relax + \pgfmathfloat@a@S=1 + \expandafter\pgfflt@init\expandafter#1% + \else + \expandafter\expandafter\csname pgfflt@#1\endcsname + \fi +} +% State transitions: +\expandafter\def\csname pgfflt@+\endcsname{% + \pgfmathfloat@a@S=1 % + \pgfflt@init}% +\expandafter\def\csname pgfflt@-\endcsname{% + \pgfmathfloat@a@S=2 % + \pgfflt@init}% +\expandafter\def\csname pgfflt@\pgfflt@EOI\endcsname{% + \pgfmathfloatparsenumber@handleerror{empty number}{}{}}% + +\pgfkeys{ + /pgf/fpu/handlers/empty number/.style 2 args={% + /pgf/fpu/handlers/invalid number={#1}{#2}% + }, + /pgf/fpu/empty number is zero/.style={% + /pgf/fpu/handlers/empty number/.code 2 args={% + \pgfmathfloatcreate{0}{0.0}{0}% + }% + },% + /pgf/fpu/handlers/invalid number/.code 2 args={% + \pgfmath@error{Could not parse input '#1' as a floating point number, sorry. The unreadable part was near '#2'.}{}% + }, + /pgf/fpu/handlers/wrong lowlevel format/.code 2 args={% + \pgfmath@error{Sorry, an internal routine of the floating point unit got an ill-formatted floating point number `#1'. The unreadable part was near '#2'.}{}% + \let\pgfmathresult=\pgfutil@empty + }, +} + +% #1 the error handler +% #2 the number which was invalid. +% #3 the part which produced the error +% +% POSTCONDITION: the three registers +% \pgfmathfloat@a@S +% \pgfmathfloat@a@Mtok +% \pgfmathfloat@a@E +% will contain the number which results from the error handler. +\def\pgfmathfloatparsenumber@handleerror#1#2#3{% + \let\pgfmathresult=\pgfutil@empty + \pgfmathfloatparsenumberpendingperiodfalse + \pgfkeys{/pgf/fpu/handlers/#1={#2}{#3}}% + \ifx\pgfmathresult\pgfutil@empty + \pgfmathfloat@a@S=3 + \pgfmathfloat@a@Mtok={0.0}% + \pgfmathfloat@a@E=0 + \else + \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E + \fi +} +\def\pgfflt@error#1\pgfflt@EOI{% + \begingroup + \pgfmathfloat@a@Mtok={#1}% + \xdef\pgfmathfloat@glob@TMP{% + \noexpand\pgfmathfloatparsenumber@handleerror + {invalid number}{\pgfmathresult}{\the\pgfmathfloat@a@Mtok}}% + \endgroup + \pgfmathfloat@glob@TMP +}% + + + +% FROM: checksign. +% +\def\pgfflt@init#1{% + \expandafter\ifx\csname pgffltA@#1\endcsname\relax + \expandafter\pgfflt@error\expandafter#1% + \else + \expandafter\expandafter\csname pgffltA@#1\endcsname + \fi} +% state transitions: +\expandafter\def\csname pgffltA@0\endcsname{\pgfflt@leadingzero}% FIXME: inline optimization! +\expandafter\def\csname pgffltA@1\endcsname{\pgfflt@nonzerodigit1}% +\expandafter\def\csname pgffltA@2\endcsname{\pgfflt@nonzerodigit2}% +\expandafter\def\csname pgffltA@3\endcsname{\pgfflt@nonzerodigit3}% +\expandafter\def\csname pgffltA@4\endcsname{\pgfflt@nonzerodigit4}% +\expandafter\def\csname pgffltA@5\endcsname{\pgfflt@nonzerodigit5}% +\expandafter\def\csname pgffltA@6\endcsname{\pgfflt@nonzerodigit6}% +\expandafter\def\csname pgffltA@7\endcsname{\pgfflt@nonzerodigit7}% +\expandafter\def\csname pgffltA@8\endcsname{\pgfflt@nonzerodigit8}% +\expandafter\def\csname pgffltA@9\endcsname{\pgfflt@nonzerodigit9}% +\def\pgfflt@nonzerodigit#1{% + \pgfmathfloat@a@Mtok={#1}% + \pgfmathfloatparsenumberpendingperiodtrue + \pgfflt@positiveexp}% +\expandafter\def\csname pgffltA@n\endcsname{\pgfflt@readnan}% FIXME: inlining? +\expandafter\def\csname pgffltA@N\endcsname{\pgfflt@readnan}% FIXME: inlining? +\expandafter\def\csname pgffltA@i\endcsname{\pgfflt@readinf}% FIXME: inlining? +\expandafter\def\csname pgffltA@I\endcsname{\pgfflt@readinf}% FIXME: inlining? +\expandafter\def\csname pgffltA@.\endcsname{% read '.9' like '0.9' + \pgfmathfloat@a@E=-1 + \pgfflt@leadingzero@foundperiod}% + +\def\pgfflt@finish#1\pgfflt@EOI{} + +\def\pgfflt@readnan #1#2{% + \def\pgfflt@readnan@ok{1}% + \if#1a\else\if#1A\else\def\pgfflt@readnan@ok{0}\fi\fi + \if#2n\else\if#2N\else\def\pgfflt@readnan@ok{0}\fi\fi + \if\pgfflt@readnan@ok1% + \pgfmathfloat@a@S=3\relax% + \pgfmathfloat@a@Mtok={0.0}% + \pgfmathfloat@a@E=0% + \expandafter\pgfflt@finish + \else + \def\pgfflt@readnan@{\pgfflt@error #1#2}% + \expandafter\pgfflt@readnan@ + \fi +} +\def\pgfflt@readinf #1#2{% + \def\pgfflt@readinf@ok{1}% + \if#1n\else\if#1N\else\def\pgfflt@readinf@ok{0}\fi\fi + \if#2f\else\if#2F\else\def\pgfflt@readinf@ok{0}\fi\fi + \if\pgfflt@readinf@ok1% + \ifnum\pgfmathfloat@a@S=1 % + \pgfmathfloat@a@S=4 % + \pgfmathfloat@a@Mtok={0.0}% + \else + \pgfmathfloat@a@S=5 % + \pgfmathfloat@a@Mtok={0.0}% + \fi + \pgfmathfloat@a@E=0 % + \expandafter\pgfflt@finish + \else + \def\pgfflt@readinf@{\pgfflt@error #1#2}% + \expandafter\pgfflt@readinf@ + \fi +} +\def\pgfflt@leadingzero#1{% + \expandafter\ifx\csname pgffltB@#1\endcsname\relax + \expandafter\pgfflt@error\expandafter#1% + \else + \expandafter\expandafter\csname pgffltB@#1\endcsname + \fi} +% State transitions: +\expandafter\def\csname pgffltB@0\endcsname{\pgfflt@leadingzero}% +\expandafter\def\csname pgffltB@1\endcsname{\pgfmathfloat@a@Mtok={1}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp} +\expandafter\def\csname pgffltB@2\endcsname{\pgfmathfloat@a@Mtok={2}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp} +\expandafter\def\csname pgffltB@3\endcsname{\pgfmathfloat@a@Mtok={3}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp} +\expandafter\def\csname pgffltB@4\endcsname{\pgfmathfloat@a@Mtok={4}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp} +\expandafter\def\csname pgffltB@5\endcsname{\pgfmathfloat@a@Mtok={5}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp} +\expandafter\def\csname pgffltB@6\endcsname{\pgfmathfloat@a@Mtok={6}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp} +\expandafter\def\csname pgffltB@7\endcsname{\pgfmathfloat@a@Mtok={7}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp} +\expandafter\def\csname pgffltB@8\endcsname{\pgfmathfloat@a@Mtok={8}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp} +\expandafter\def\csname pgffltB@9\endcsname{\pgfmathfloat@a@Mtok={9}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp} +\expandafter\def\csname pgffltB@\pgfmathfloat@POSTFLAGSCHAR\endcsname{\pgfmathfloat@a@Mtok={0}\pgfflt@readlowlevelfloat}% +\expandafter\def\csname pgffltB@.\endcsname{% + \pgfmathfloat@a@E=-1 + \pgfflt@leadingzero@foundperiod}% +\expandafter\def\csname pgffltB@e\endcsname{% + \pgfmathfloat@a@S=0\relax% + \pgfmathfloat@a@Mtok={0.0}% + \pgfmathfloat@a@E=0% + \pgfflt@readexponent}% +\let\pgffltB@E=\pgffltB@e +\expandafter\def\csname pgffltB@\pgfflt@EOI\endcsname{% + \pgfmathfloat@a@S=0\relax% + \pgfmathfloat@a@Mtok={0.0}% + \pgfmathfloat@a@E=0}% + +\def\pgfflt@leadingzero@foundperiod#1{% + \expandafter\ifx\csname pgffltC@#1\endcsname\relax + \expandafter\pgfflt@error\expandafter#1% + \else + \expandafter\expandafter\csname pgffltC@#1\endcsname + \fi} +% State transitions: +\expandafter\def\csname pgffltC@0\endcsname{% + \advance\pgfmathfloat@a@E by-1 + \pgfflt@leadingzero@foundperiod}% +\expandafter\def\csname pgffltC@1\endcsname{\pgfmathfloat@a@Mtok={1}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}% +\expandafter\def\csname pgffltC@2\endcsname{\pgfmathfloat@a@Mtok={2}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}% +\expandafter\def\csname pgffltC@3\endcsname{\pgfmathfloat@a@Mtok={3}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}% +\expandafter\def\csname pgffltC@4\endcsname{\pgfmathfloat@a@Mtok={4}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}% +\expandafter\def\csname pgffltC@5\endcsname{\pgfmathfloat@a@Mtok={5}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}% +\expandafter\def\csname pgffltC@6\endcsname{\pgfmathfloat@a@Mtok={6}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}% +\expandafter\def\csname pgffltC@7\endcsname{\pgfmathfloat@a@Mtok={7}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}% +\expandafter\def\csname pgffltC@8\endcsname{\pgfmathfloat@a@Mtok={8}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}% +\expandafter\def\csname pgffltC@9\endcsname{\pgfmathfloat@a@Mtok={9}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}% +\expandafter\def\csname pgffltC@e\endcsname{% + \pgfmathfloat@a@S=0\relax% + \pgfmathfloat@a@Mtok={0.0}% + \pgfmathfloat@a@E=0% + \pgfflt@readexponent}% +\let\pgffltC@E=\pgffltC@e +\expandafter\def\csname pgffltC@\pgfflt@EOI\endcsname{% + \pgfmathfloat@a@S=0\relax% + \pgfmathfloat@a@Mtok={0.0}% + \pgfmathfloat@a@E=0}% + + +\def\pgfflt@positiveexp#1{% + \expandafter\ifx\csname pgffltD@#1\endcsname\relax + \expandafter\pgfflt@error\expandafter#1% + \else + \expandafter\expandafter\csname pgffltD@#1\endcsname + \fi} +% State transitions: +\expandafter\def\csname pgffltD@0\endcsname{% + \advance\pgfmathfloat@a@E by1 + \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}% + \pgfflt@pendingzeros@positiveexp}% +\expandafter\def\csname pgffltD@1\endcsname{\pgffltD@nonzerodigit1}% +\expandafter\def\csname pgffltD@2\endcsname{\pgffltD@nonzerodigit2}% +\expandafter\def\csname pgffltD@3\endcsname{\pgffltD@nonzerodigit3}% +\expandafter\def\csname pgffltD@4\endcsname{\pgffltD@nonzerodigit4}% +\expandafter\def\csname pgffltD@5\endcsname{\pgffltD@nonzerodigit5}% +\expandafter\def\csname pgffltD@6\endcsname{\pgffltD@nonzerodigit6}% +\expandafter\def\csname pgffltD@7\endcsname{\pgffltD@nonzerodigit7}% +\expandafter\def\csname pgffltD@8\endcsname{\pgffltD@nonzerodigit8}% +\expandafter\def\csname pgffltD@9\endcsname{\pgffltD@nonzerodigit9}% +\expandafter\def\csname pgffltD@\pgfmathfloat@POSTFLAGSCHAR\endcsname{\pgfflt@readlowlevelfloat}% +\expandafter\def\csname pgffltD@.\endcsname{\pgfflt@finish@number@after@period}% FIXME : inlining? +\expandafter\def\csname pgffltD@e\endcsname{\pgfflt@readexponent}% FIXME : inlining? +\let\pgffltD@E=\pgffltD@e +\expandafter\def\csname pgffltD@\pgfflt@EOI\endcsname{}% NOP +\def\pgffltD@nonzerodigit#1{% + \advance\pgfmathfloat@a@E by1 + \ifpgfmathfloatparsenumberpendingperiod + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}% + \pgfmathfloatparsenumberpendingperiodfalse + \fi + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}% + \pgfflt@positiveexp}% + +% Read a low-level floating point. +% Since we are in the second state, \pgfmathfloat@a@Mtok contains the +% FLAGS. The post-flags-char has also been read. +\def\pgfflt@readlowlevelfloat#1e#2]\pgfflt@EOI{% + \pgfmathfloatparsenumberpendingperiodfalse + \pgfmathfloat@a@S=\the\pgfmathfloat@a@Mtok\relax + \pgfmathfloat@a@Mtok={#1}% + \pgfmathfloat@a@E=#2 +}% + +\def\pgfflt@readexponent#1\pgfflt@EOI{% + \afterassignment\pgfflt@readexponent@ + \pgfmathfloat@b@E=#1 \pgfflt@EOI% the white space is important, otherwise \pgfflt@EOI will be expanded. +} +\def\pgfflt@readexponent@#1{% + \advance\pgfmathfloat@a@E by\pgfmathfloat@b@E\relax + % + % sanity checking: + \def\pgfmathfloat@loc@TMPb{#1}% + \ifx\pgfmathfloat@loc@TMPb\pgfflt@EOI@unexpanded + \else + \def\pgfmathfloat@loc@TMPb{\pgfflt@error#1}% + \expandafter\pgfmathfloat@loc@TMPb + \fi +} + +\def\pgfflt@pendingzeros@positiveexp#1{% + \expandafter\ifx\csname pgffltE@#1\endcsname\relax + \expandafter\pgfflt@error\expandafter#1% + \else + \expandafter\expandafter\csname pgffltE@#1\endcsname + \fi} +% State transitions: +\expandafter\def\csname pgffltE@0\endcsname{% + \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}% + \advance\pgfmathfloat@a@E by1 + \pgfflt@pendingzeros@positiveexp}% +\expandafter\def\csname pgffltE@1\endcsname{\pgffltE@nonzerodigit1}% +\expandafter\def\csname pgffltE@2\endcsname{\pgffltE@nonzerodigit2}% +\expandafter\def\csname pgffltE@3\endcsname{\pgffltE@nonzerodigit3}% +\expandafter\def\csname pgffltE@4\endcsname{\pgffltE@nonzerodigit4}% +\expandafter\def\csname pgffltE@5\endcsname{\pgffltE@nonzerodigit5}% +\expandafter\def\csname pgffltE@6\endcsname{\pgffltE@nonzerodigit6}% +\expandafter\def\csname pgffltE@7\endcsname{\pgffltE@nonzerodigit7}% +\expandafter\def\csname pgffltE@8\endcsname{\pgffltE@nonzerodigit8}% +\expandafter\def\csname pgffltE@9\endcsname{\pgffltE@nonzerodigit9}% +\expandafter\def\csname pgffltE@.\endcsname{\pgfflt@finish@number@after@period}% FIXME : inlining? +\def\pgffltE@e{\pgfflt@readexponent}% FIXME : inlining? +\let\pgffltE@E=\pgffltE@e +\expandafter\def\csname pgffltE@\pgfflt@EOI\endcsname{}% NOP +\def\pgffltE@nonzerodigit#1{% + \advance\pgfmathfloat@a@E by1 + \ifpgfmathfloatparsenumberpendingperiod + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}% + \pgfmathfloatparsenumberpendingperiodfalse + \fi + \pgfmathfloat@a@Mtok=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfmathfloat@a@Mtok\the\pgfmathfloat@tmptoks}% + \pgfmathfloat@tmptoks={}% + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}% + \pgfflt@positiveexp}% + +\def\pgfflt@finish@number@after@period#1{% + \expandafter\ifx\csname pgffltF@#1\endcsname\relax + \expandafter\pgfflt@error\expandafter#1% + \else + \expandafter\expandafter\csname pgffltF@#1\endcsname + \fi} +% State transitions: +\expandafter\def\csname pgffltF@0\endcsname{% + \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}% + \pgfflt@pendingzeros}% +\expandafter\def\csname pgffltF@1\endcsname{\pgffltF@nonzerodigit1}% +\expandafter\def\csname pgffltF@2\endcsname{\pgffltF@nonzerodigit2}% +\expandafter\def\csname pgffltF@3\endcsname{\pgffltF@nonzerodigit3}% +\expandafter\def\csname pgffltF@4\endcsname{\pgffltF@nonzerodigit4}% +\expandafter\def\csname pgffltF@5\endcsname{\pgffltF@nonzerodigit5}% +\expandafter\def\csname pgffltF@6\endcsname{\pgffltF@nonzerodigit6}% +\expandafter\def\csname pgffltF@7\endcsname{\pgffltF@nonzerodigit7}% +\expandafter\def\csname pgffltF@8\endcsname{\pgffltF@nonzerodigit8}% +\expandafter\def\csname pgffltF@9\endcsname{\pgffltF@nonzerodigit9}% +\def\pgffltF@e{\pgfflt@readexponent}% +\let\pgffltF@E=\pgffltF@e +\expandafter\def\csname pgffltF@\pgfflt@EOI\endcsname{}% NOP +\def\pgffltF@nonzerodigit#1{% + \ifpgfmathfloatparsenumberpendingperiod + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}% + \pgfmathfloatparsenumberpendingperiodfalse + \fi + \pgfmathfloat@a@Mtok=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfmathfloat@a@Mtok\the\pgfmathfloat@tmptoks}% + \pgfmathfloat@tmptoks={}% + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}% + \pgfflt@finish@number@after@period}% + + +\def\pgfflt@pendingzeros#1{% + \expandafter\ifx\csname pgffltG@#1\endcsname\relax + \expandafter\pgfflt@error\expandafter#1% + \else + \expandafter\expandafter\csname pgffltG@#1\endcsname + \fi} +% State transitions: +\expandafter\def\csname pgffltG@0\endcsname{% + \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}% + \pgfflt@pendingzeros}% +\expandafter\def\csname pgffltG@1\endcsname{\pgffltG@nonzerodigit1}% +\expandafter\def\csname pgffltG@2\endcsname{\pgffltG@nonzerodigit2}% +\expandafter\def\csname pgffltG@3\endcsname{\pgffltG@nonzerodigit3}% +\expandafter\def\csname pgffltG@4\endcsname{\pgffltG@nonzerodigit4}% +\expandafter\def\csname pgffltG@5\endcsname{\pgffltG@nonzerodigit5}% +\expandafter\def\csname pgffltG@6\endcsname{\pgffltG@nonzerodigit6}% +\expandafter\def\csname pgffltG@7\endcsname{\pgffltG@nonzerodigit7}% +\expandafter\def\csname pgffltG@8\endcsname{\pgffltG@nonzerodigit8}% +\expandafter\def\csname pgffltG@9\endcsname{\pgffltG@nonzerodigit9}% +\def\pgffltG@e{\pgfflt@readexponent}% FIXME: inlining? +\let\pgffltG@E=\pgffltG@e +\expandafter\def\csname pgffltG@\pgfflt@EOI\endcsname{}% NOP +\def\pgffltG@nonzerodigit#1{% + \ifpgfmathfloatparsenumberpendingperiod + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}% + \pgfmathfloatparsenumberpendingperiodfalse + \fi + \pgfmathfloat@a@Mtok=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfmathfloat@a@Mtok\the\pgfmathfloat@tmptoks}% + \pgfmathfloat@tmptoks={}% + \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}% + \pgfflt@finish@number@after@period}% + +\endinput diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathbase.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.code.tex index cd34d3a8db0..a4e510d4dc8 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathbase.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.base.code.tex @@ -9,7 +9,46 @@ % % This file provides basic macros for converting between bases. % -% Version 1.414213 29/9/2007 +% Version 1.4142135 8/11/2008 + +% Base conversion operations for the parser. +% +\pgfmathdeclarefunction{bin}{1}{% + \begingroup% + \afterassignment\pgfmath@gobbletilpgfmath@% + \c@pgfmath@counta=#1\relax\pgfmath@% + \expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\the\c@pgfmath@counta}{10}{2}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} +\pgfmathdeclarefunction{hex}{1}{% + \begingroup% + \afterassignment\pgfmath@gobbletilpgfmath@% + \c@pgfmath@counta=#1\relax\pgfmath@% + \expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\the\c@pgfmath@counta}{10}{16}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +\pgfmathdeclarefunction{Hex}{1}{% + \begingroup% + \afterassignment\pgfmath@gobbletilpgfmath@% + \c@pgfmath@counta=#1\relax\pgfmath@% + \expandafter\pgfmathbasetoBase\expandafter\pgfmathresult\expandafter{\the\c@pgfmath@counta}{10}{16}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +\pgfmathdeclarefunction{oct}{1}{% + \begingroup% + \afterassignment\pgfmath@gobbletilpgfmath@% + \c@pgfmath@counta=#1\relax\pgfmath@% + \expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\the\c@pgfmath@counta}{10}{8}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% Additional macros: % \pgfmathbasetodec % @@ -30,14 +69,14 @@ \pgfmath@checknumber{#2}% \pgfmath@checkbase{#3}% \def\pgfmath@base{#3}% - \def\pgfmath@macro{#1}% - \c@pgfmath@counta1\relax% - \def\pgfmath@reversed{}% - \expandafter\pgfmathbasetodec@#2\pgfmathbasetodec} + \def\pgfmath@base@macro{#1}% + \c@pgfmath@counta=1\relax% + \let\pgfmath@reversed=\pgfmath@empty% + \expandafter\pgfmathbasetodec@#2\pgfmath@base@stop} \def\pgfmathbasetodec@#1{% - \ifx\pgfmathbasetodec#1% - \c@pgfmath@countb0% + \ifx#1\pgfmath@base@stop% + \c@pgfmath@countb=0% \divide\c@pgfmath@counta by\pgfmath@base\relax% \expandafter\pgfmathbasetodec@@% \else% @@ -50,32 +89,33 @@ \def\pgfmathbasetodec@@@#1{% \ifx\pgfmathbasetodec#1\relax% - \expandafter\edef\pgfmath@macro{\the\c@pgfmath@countb}% - \let\pgfmath@next\pgfmathbasetodec@@@@% + \expandafter\edef\pgfmath@base@macro{\the\c@pgfmath@countb}% + \let\pgfmath@next=\pgfmathbasetodec@@@@% \else% \chardef\pgfmath@charnum`#1\relax% - \c@pgfmath@countc\pgfmath@charnum% + \c@pgfmath@countc=\pgfmath@charnum\relax% \ifnum\c@pgfmath@countc>96\relax% - \advance\c@pgfmath@countc-87\relax% + \advance\c@pgfmath@countc by-87\relax% \else \ifnum\c@pgfmath@countc>64\relax% - \advance\c@pgfmath@countc-55\relax% + \advance\c@pgfmath@countc by-55\relax% \else - \advance\c@pgfmath@countc-48\relax% - \fi\fi% + \advance\c@pgfmath@countc by-48\relax% + \fi% + \fi% \ifnum\c@pgfmath@countc<\pgfmath@base\relax% - \multiply\c@pgfmath@countc\c@pgfmath@counta\relax% - \advance\c@pgfmath@countb\c@pgfmath@countc% + \multiply\c@pgfmath@countc by\c@pgfmath@counta% + \advance\c@pgfmath@countb by\c@pgfmath@countc% \divide\c@pgfmath@counta by\pgfmath@base\relax% \let\pgfmath@next\pgfmathbasetodec@@@% \else \pgfmath@error{Digit `#1' invalid for base \pgfmath@base}% - \let\pgfmath@next\relax% + \let\pgfmath@next=\relax% \fi% \fi% \pgfmath@next} \def\pgfmathbasetodec@@@@{% - \expandafter\pgfmath@ensurenumberlength\expandafter{\pgfmath@macro}% + \expandafter\pgfmath@ensurenumberlength\expandafter{\pgfmath@base@macro}% } % \pgfmathdectobase @@ -97,16 +137,16 @@ \def\pgfmathdectobase#1#2#3{% \pgfmath@checknumber{#2}% \pgfmath@checkbase{#3}% - \c@pgfmath@counta#2\relax% - \def#1{}% + \c@pgfmath@counta=#2\relax% + \let#1=\pgfmath@empty% \pgfmathloop \ifnum\c@pgfmath@counta>0\relax% - \c@pgfmath@countb\c@pgfmath@counta% - \divide\c@pgfmath@countb#3\relax% - \multiply\c@pgfmath@countb-#3\relax% - \advance\c@pgfmath@countb\c@pgfmath@counta% + \c@pgfmath@countb=\c@pgfmath@counta% + \divide\c@pgfmath@countb by#3\relax% + \multiply\c@pgfmath@countb by-#3\relax% + \advance\c@pgfmath@countb by\c@pgfmath@counta% \edef#1{\csname pgfmath@lowercase digit@\the\c@pgfmath@countb\endcsname#1}% - \divide\c@pgfmath@counta#3\relax% + \divide\c@pgfmath@counta by#3\relax% \repeatpgfmathloop% \pgfmath@ensurenumberlength{#1}} @@ -129,35 +169,35 @@ \def\pgfmathdectoBase#1#2#3{% \pgfmath@checkbase{#3}% \pgfmath@checknumber{#2}% - \c@pgfmath@counta#2\relax% - \def#1{}% + \c@pgfmath@counta=#2\relax% + \let#1=\pgfmath@empty% \pgfmathloop \ifnum\c@pgfmath@counta>0\relax% - \c@pgfmath@countb\c@pgfmath@counta% - \divide\c@pgfmath@countb#3\relax% - \multiply\c@pgfmath@countb-#3\relax% - \advance\c@pgfmath@countb\c@pgfmath@counta% + \c@pgfmath@countb=\c@pgfmath@counta% + \divide\c@pgfmath@countb by#3\relax% + \multiply\c@pgfmath@countb by-#3\relax% + \advance\c@pgfmath@countb by\c@pgfmath@counta% \edef#1{\csname pgfmath@uppercase digit@\the\c@pgfmath@countb\endcsname#1}% - \divide\c@pgfmath@counta#3\relax% + \divide\c@pgfmath@counta by#3\relax% \repeatpgfmathloop% \pgfmath@ensurenumberlength{#1}} -\def\pgfmath@createdigits{% - \def\pgfmath@digitstyle{lowercase digit}% - \c@pgfmath@counta0\relax% - \pgfmath@createdigits@0123456789abcdefghijklmnopqrstuvwxyz\pgfmath@createdigits% - \def\pgfmath@digitstyle{uppercase digit}% - \c@pgfmath@counta0\relax% - \pgfmath@createdigits@0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\pgfmath@createdigits} +\def\pgfmath@base@digits@create{% + \def\pgfmath@base@digit@style{lowercase digit}% + \c@pgfmath@counta=0\relax% + \pgfmath@base@digits@create@0123456789abcdefghijklmnopqrstuvwxyz\pgfmath@base@digits@create% + \def\pgfmath@base@digit@style{uppercase digit}% + \c@pgfmath@counta=0\relax% + \pgfmath@base@digits@create@0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ\pgfmath@base@digits@create} -\def\pgfmath@createdigits@#1{% - \ifx\pgfmath@createdigits#1\relax% +\def\pgfmath@base@digits@create@#1{% + \ifx\pgfmath@base@digits@create#1\relax% \else% - \expandafter\pgfmath@def\expandafter{\pgfmath@digitstyle}{\the\c@pgfmath@counta}{#1}% - \advance\c@pgfmath@counta1\relax% - \expandafter\pgfmath@createdigits@% + \expandafter\pgfmath@def\expandafter{\pgfmath@base@digit@style}{\the\c@pgfmath@counta}{#1}% + \advance\c@pgfmath@counta by1\relax% + \expandafter\pgfmath@base@digits@create@% \fi} -\pgfmath@createdigits +\pgfmath@base@digits@create % \pgfmathbasetobase % @@ -177,8 +217,8 @@ % \mynumber <- 721 % \def\pgfmathbasetobase#1#2#3#4{% - \pgfmathbasetodec{\pgfmath@temp}{#2}{#3}% - \pgfmathdectobase{#1}{\pgfmath@temp}{#4} + \pgfmathbasetodec{\pgfmath@base@temp}{#2}{#3}% + \pgfmathdectobase{#1}{\pgfmath@base@temp}{#4}% } % \pgfmathbasetobase @@ -199,8 +239,8 @@ % \mynumber <- 142 % \def\pgfmathbasetoBase#1#2#3#4{% - \pgfmathbasetodec{\pgfmath@temp}{#2}{#3}% - \pgfmathdectoBase{#1}{\pgfmath@temp}{#4} + \pgfmathbasetodec{\pgfmath@base@temp}{#2}{#3}% + \pgfmathdectoBase{#1}{\pgfmath@base@temp}{#4}% } \def\pgfmath@checkbase#1{% @@ -209,7 +249,8 @@ \else% \ifnum#1>36\relax% \pgfmath@error{Cannot process numbers in base `#1'.}% - \fi\fi} + \fi% + \fi} \def\pgfmath@checknumber#1{% \expandafter\pgfmath@checknumber@#1\pgfmath@} @@ -236,27 +277,27 @@ % \foo <- 000007FF % \def\pgfmath@ensurenumberlength#1{% - \def\pgfmath@tempa{#1}% + \def\pgfmath@base@tempa{#1}% \expandafter\c@pgfmath@counta\pgfmath@basenumberlength\relax% \expandafter\pgfmath@ensurenumberlength@#1\pgfmath@ensurenumberlength} \def\pgfmath@ensurenumberlength@#1{% \ifx\pgfmath@ensurenumberlength#1\relax% \expandafter\pgfmath@ensurenumberlength@@% \else% - \advance\c@pgfmath@counta-1\relax% + \advance\c@pgfmath@counta by-1\relax% \expandafter\pgfmath@ensurenumberlength@ \fi} \def\pgfmath@ensurenumberlength@@{% - \edef\pgfmath@tempb{\pgfmath@tempa}% + \edef\pgfmath@base@tempb{\pgfmath@base@tempa}% \pgfmath@ensurenumberlength@@@} \def\pgfmath@ensurenumberlength@@@{% \ifnum\c@pgfmath@counta>0\relax% - \advance\c@pgfmath@counta-1\relax% - \edef\pgfmath@tempb{0\pgfmath@tempb}% + \advance\c@pgfmath@counta by-1\relax% + \edef\pgfmath@base@tempb{0\pgfmath@base@tempb}% \expandafter\pgfmath@ensurenumberlength@@@% \fi% - \expandafter\edef\pgfmath@tempa{\pgfmath@tempb}} + \expandafter\edef\pgfmath@base@tempa{\pgfmath@base@tempb}} \def\pgfmathsetbasenumberlength#1{\def\pgfmath@basenumberlength{#1}} -\pgfmathsetbasenumberlength{1}%
\ No newline at end of file +\pgfmathsetbasenumberlength{1}% diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex new file mode 100644 index 00000000000..ca741fa7adc --- /dev/null +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex @@ -0,0 +1,713 @@ +% Copyright 2007 by Mark Wibrow +% +% This file may be distributed and/or modified +% +% 1. under the LaTeX Project Public License and/or +% 2. under the GNU Public License. +% +% See the file doc/generic/pgf/licenses/LICENSE for more details. + +% This file defines the mathematical functions and operators. +% +% Version 1.4142135 25/8/2008 + +% add function. +% +\pgfmathdeclarefunction{add}{2}{% + \begingroup% + \pgfmath@x=#1pt\relax% + \pgfmath@y=#2pt\relax% + \advance\pgfmath@x by\pgfmath@y% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + + +% subtract function. +% +\pgfmathdeclarefunction{subtract}{2}{% + \begingroup% + \pgfmath@x=#1pt\relax% + \pgfmath@y=#2pt\relax% + \advance\pgfmath@x by-\pgfmath@y% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% neg function. +% +\pgfmathdeclarefunction{neg}{1}{% + \begingroup% + \pgfmath@x=-#1pt\relax% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} +% change the precedence for neg. +% Otherwise, unary minus and exponentiation won't have the correct precedence +% (test '-2^2') +\def\pgfmath@operation@neg@precedence{500} + +% multiply function. +% +\pgfmathdeclarefunction{multiply}{2}{% + \begingroup% + \pgfmath@x=#1pt\relax% + \pgfmath@y=#2pt\relax% + \pgfmath@x=\pgfmath@tonumber{\pgfmath@y}\pgfmath@x% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% divide function. +% +\newif\ifpgfmath@divide@period + +\pgfmathdeclarefunction{divide}{2}{% + \begingroup% + \pgfmath@x=#1pt\relax% + \pgfmath@y=#2pt\relax% + \let\pgfmath@sign=\pgfmath@empty% + \ifdim0pt=\pgfmath@y% + \pgfmath@error{You've asked me to divide `#1' by `#2', % + but I cannot divide any number by `#2'}% + \fi% + \afterassignment\pgfmath@xa% + \c@pgfmath@counta\the\pgfmath@y\relax% + \ifdim0pt=\pgfmath@xa% + \divide\pgfmath@x by\c@pgfmath@counta% + \else% + \ifdim0pt>\pgfmath@x% + \def\pgfmath@sign{-}% + \pgfmath@x=-\pgfmath@x% + \fi% + \ifdim0pt>\pgfmath@y% + \expandafter\def\expandafter\pgfmath@sign\expandafter{\pgfmath@sign-}% + \pgfmath@y=-\pgfmath@y% + \fi% + \ifdim1pt>\pgfmath@y% + \pgfmathreciprocal@{\pgfmath@tonumber{\pgfmath@y}}% + \pgfmath@x=\pgfmath@sign\pgfmathresult\pgfmath@x% + \else% + \def\pgfmathresult{0}% + \pgfmath@divide@periodtrue% + \c@pgfmath@counta=0\relax% + \pgfmathdivide@@% + \pgfmath@x=\pgfmath@sign\pgfmathresult pt\relax% + \fi% + \fi% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +\def\pgfmath@small@number{0.00002} + +\def\pgfmathdivide@@{% + \let\pgfmath@next=\relax% + \ifdim\pgfmath@small@number pt<\pgfmath@x% + \ifdim\pgfmath@small@number pt<\pgfmath@y% + \ifdim\pgfmath@y>\pgfmath@x% + \ifpgfmath@divide@period% + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult.}% + \pgfmath@divide@periodfalse% + \fi% + \pgfmathdivide@dimenbyten\pgfmath@y% + \ifdim\pgfmath@y>\pgfmath@x% + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult0}% + \fi% + \else% + \c@pgfmath@counta=\pgfmath@x% + \c@pgfmath@countb=\pgfmath@y% + \divide\c@pgfmath@counta by\c@pgfmath@countb% + \pgfmath@ya=\c@pgfmath@counta\pgfmath@y% + \advance\pgfmath@x by-\pgfmath@ya% + \expandafter\expandafter\expandafter\def% + \expandafter\expandafter\expandafter\pgfmathresult + \expandafter\expandafter\expandafter{\expandafter\pgfmathresult\the\c@pgfmath@counta}% + \fi% + \let\pgfmath@next=\pgfmathdivide@@% + \fi% + \fi% + \pgfmath@next% +} + +\def\pgfmathdivide@dimenbyten#1{% + \edef\pgfmath@temp{\pgfmath@tonumber{#1}}% + \expandafter\pgfmathdivide@@dimenbyten\pgfmath@temp\@@#1\@@} +\def\pgfmathdivide@@dimenbyten#1.#2\@@#3\@@{% + \pgfmath@tempcnta=#1\relax% + \divide\pgfmath@tempcnta by10\relax% + \pgfmath@tempcntb=\pgfmath@tempcnta% + \multiply\pgfmath@tempcnta by-10\relax% + \advance\pgfmath@tempcnta by#1\relax% + #3=\the\pgfmath@tempcntb.\the\pgfmath@tempcnta#2pt\relax% +} + + +% reciprocal function. +% +\pgfmathdeclarefunction{reciprocal}{1}{% + \begingroup% + \expandafter\pgfmath@x#1pt\relax% + \ifdim\pgfmath@x=0pt\relax% + \pgfmath@error{You asked me to calculate `1/#1', but I cannot divide any number by zero}{}% + \fi% + \edef\pgfmath@reciprocaltemp{\pgfmath@tonumber{\pgfmath@x}}% + \expandafter\pgfmathreciprocal@@\pgfmath@reciprocaltemp0000000\pgfmath@} +\def\pgfmathreciprocal@@#1.#2#3#4#5#6#7\pgfmath@{% + \c@pgfmath@counta#2#3#4#5#6\relax% + % If the number is an integer, use TeX arithmatic. + \ifnum\c@pgfmath@counta=0\relax% + \pgfmath@x1pt\relax% + \divide\pgfmath@x#1\relax% + \else% + \ifnum#1>100\relax% + \c@pgfmath@counta#1#2#3#4\relax% + \c@pgfmath@countb1000000000\relax% + \divide\c@pgfmath@countb\c@pgfmath@counta% + \c@pgfmath@counta\c@pgfmath@countb% + \divide\c@pgfmath@counta10000\relax% + \pgfmath@x\c@pgfmath@counta pt\relax% + \multiply\c@pgfmath@counta-10000\relax% + \advance\c@pgfmath@countb\c@pgfmath@counta% + \pgfmath@y\c@pgfmath@countb pt\relax% + \divide\pgfmath@y1000000\relax% + \advance\pgfmath@x\pgfmath@y% + \else% + \c@pgfmath@counta#1#2#3#4#5#6\relax% + \c@pgfmath@countb1000000000\relax% + \divide\c@pgfmath@countb\c@pgfmath@counta% + \c@pgfmath@counta\c@pgfmath@countb% + \divide\c@pgfmath@counta10000\relax% + \pgfmath@x\c@pgfmath@counta pt\relax% + \multiply\c@pgfmath@counta-10000\relax% + \advance\c@pgfmath@countb\c@pgfmath@counta% + \pgfmath@y\c@pgfmath@countb pt\relax% + \pgfmath@y.1\pgfmath@y% Yes! This way is more accurate. Go figure... + \pgfmath@y.1\pgfmath@y% + \pgfmath@y.1\pgfmath@y% + \pgfmath@y.1\pgfmath@y% + \advance\pgfmath@x\pgfmath@y% + \fi% + \fi% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% div function. +% +\pgfmathdeclarefunction{div}{2}{% + \begingroup% + \pgfmathdivide@{#1}{#2}% + \ifdim\pgfmathresult pt<0pt\relax% + \pgfmathceil@{\pgfmathresult}% + \else% + \pgfmathfloor@{\pgfmathresult}% + \fi% + \afterassignment\pgfmath@gobbletilpgfmath@% + \c@pgfmath@counta=\pgfmathresult\relax\pgfmath@% + \edef\pgfmathresult{\the\c@pgfmath@counta}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% mod function. +% +\pgfmathdeclarefunction{mod}{2}{% + \begingroup% + \pgfmath@xa#1pt% + \pgfmath@xb#2pt% + \pgfmath@x\pgfmath@xa% + \c@pgfmath@counta\pgfmath@xa% + \c@pgfmath@countb\pgfmath@xb% + \divide\c@pgfmath@counta\c@pgfmath@countb% + \multiply\pgfmath@xb\c@pgfmath@counta% + \advance\pgfmath@x-\pgfmath@xb% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% Mod function (never negative). +% +\pgfmathdeclarefunction{Mod}{2}{% + \begingroup% + \pgfmathmod@{#1}{#2}% + \pgfmath@x=\pgfmathresult pt\relax% + \ifdim\pgfmath@x<0pt\relax% + \advance\pgfmath@x by#2pt\relax% + \fi% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% abs function. +% +\pgfmathdeclarefunction{abs}{1}{% + \begingroup% + \expandafter\pgfmath@x#1pt\relax% + \ifdim\pgfmath@x<0pt\relax% + \pgfmath@x-\pgfmath@x% + \fi% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% e constant. +% +\pgfmathdeclarefunction{e}{0}{\def\pgfmathresult{2.718281828}} + +% ln function. +% +% This is based on an algorithm due to Rouben Rostamian and +% uses coefficients contributed by Alain Matthes. +% +\pgfmathdeclarefunction{ln}{1}{% + \begingroup% + \expandafter\pgfmath@x#1pt\relax% + \ifdim\pgfmath@x>0pt\else% + \pgfmath@error{I cannot calculate the logarithm of `#1'}{}% + \fi% + \c@pgfmath@counta=0\relax% + \ifdim\pgfmath@x>2pt\relax% + \ifdim\pgfmath@x<128pt\relax% + \ifdim\pgfmath@x<8pt\relax% + \ifdim\pgfmath@x<4pt\relax% + \divide\pgfmath@x by2\relax% + \c@pgfmath@counta=1\relax% + \else% + \divide\pgfmath@x by4\relax% + \c@pgfmath@counta=2\relax% + \fi% + \else% + \ifdim\pgfmath@x<32pt\relax% + \ifdim\pgfmath@x<16pt\relax% + \divide\pgfmath@x by8\relax% + \c@pgfmath@counta=3\relax% + \else% + \divide\pgfmath@x by16\relax% + \c@pgfmath@counta=4\relax% + \fi% + \else% + \ifdim\pgfmath@x<64pt\relax% + \divide\pgfmath@x by32\relax% + \c@pgfmath@counta=5\relax% + \else% + \divide\pgfmath@x by64\relax% + \c@pgfmath@counta=6\relax% + \fi% + \fi% + \fi% + \else% + \ifdim\pgfmath@x<2048pt\relax% + \ifdim\pgfmath@x<512pt\relax% + \ifdim\pgfmath@x<256pt\relax% + \divide\pgfmath@x by128\relax% + \c@pgfmath@counta=7\relax% + \else% + \divide\pgfmath@x by256\relax% + \c@pgfmath@counta=8\relax% + \fi% + \else% + \ifdim\pgfmath@x<1024pt\relax% + \divide\pgfmath@x by512\relax% + \c@pgfmath@counta=9\relax% + \else% + \divide\pgfmath@x by1024\relax% + \c@pgfmath@counta=10\relax% + \fi% + \fi% + \else% + \ifdim\pgfmath@x<8192pt\relax% + \ifdim\pgfmath@x<4096pt\relax% + \divide\pgfmath@x by2048\relax% + \c@pgfmath@counta=11\relax% + \else% + \divide\pgfmath@x by4096\relax% + \c@pgfmath@counta =12\relax% + \fi% + \else% + \divide\pgfmath@x by8192\relax% + \c@pgfmath@counta=13\relax% + \fi% + \fi% + \fi% + \else% + \ifdim\pgfmath@x<1pt\relax% + \ifdim\pgfmath@x>0.0078125pt\relax% 2^-7 + \ifdim\pgfmath@x>0.125pt\relax% 2^-3 + \ifdim\pgfmath@x>0.5pt\relax% 2^-1 + \multiply\pgfmath@x by2\relax% + \c@pgfmath@counta=-1\relax% + \else% + \multiply\pgfmath@x by4\relax% + \c@pgfmath@counta=-2\relax% + \fi% + \else% + \ifdim\pgfmath@x>0.03125pt\relax% 2^-5 + \ifdim\pgfmath@x>0.0625pt\relax% + \multiply\pgfmath@x by8\relax% + \c@pgfmath@counta=-3\relax% + \else% + \multiply\pgfmath@x by16\relax% + \c@pgfmath@counta=-4\relax% + \fi% + \else% + \ifdim\pgfmath@x>0.015625pt\relax% 2^-6 + \multiply\pgfmath@x by32\relax% + \c@pgfmath@counta=-5\relax% + \else% + \multiply\pgfmath@x by64\relax% + \c@pgfmath@counta=-6\relax% + \fi% + \fi% + \fi% + \else% + \ifdim\pgfmath@x>0.000244140625pt\relax% 2^-11 + \ifdim\pgfmath@x>0.001953125pt\relax% 2^-9 + \ifdim\pgfmath@x>0.00390625pt\relax% 2^-8 + \multiply\pgfmath@x by128\relax% + \c@pgfmath@counta=-7\relax% + \else% + \multiply\pgfmath@x by256\relax% + \c@pgfmath@counta=-8\relax% + \fi% + \else% + \ifdim\pgfmath@x>0.0009765625pt\relax% 2^-10 + \multiply\pgfmath@x by512\relax% + \c@pgfmath@counta=-9\relax% + \else% + \multiply\pgfmath@x by1024\relax% + \c@pgfmath@counta=-10\relax% + \fi% + \fi% + \else% + \ifdim\pgfmath@x>0.0001220703125pt\relax% 2^13 + \ifdim\pgfmath@x>0.0002441406256pt\relax% 2^12 + \multiply\pgfmath@x by2048\relax% + \c@pgfmath@counta=-11\relax% + \else% + \multiply\pgfmath@x by4096\relax% + \c@pgfmath@counta=-12\relax% + \fi% + \else% + \multiply\pgfmath@x by8192\relax% + \c@pgfmath@counta=-13\relax% + \fi% + \fi% + \fi% + \fi% + \fi% + % + % Use A+(B+(C+(D+(E+F*x)*x)*x)*x)*x + % + % where: + % A = -2.787927935 + % B = 5.047861502 + % C = -3.489886985 + % D = 1.589480044 + % E = -.4025153233 + % F = 0.04300521312 + % + \edef\pgfmath@temp{\pgfmath@tonumber{\pgfmath@x}}% + \pgfmath@x=0.04300521312\pgfmath@x% + \advance\pgfmath@x by-.4025153233pt\relax% + \pgfmath@x=\pgfmath@temp\pgfmath@x% + \advance\pgfmath@x by1.589480044pt\relax% + \pgfmath@x=\pgfmath@temp\pgfmath@x% + \advance\pgfmath@x by-3.489886985pt\relax% + \pgfmath@x=\pgfmath@temp\pgfmath@x% + \advance\pgfmath@x by5.047861502pt\relax% + \pgfmath@x=\pgfmath@temp\pgfmath@x% + \advance\pgfmath@x by-2.787927935pt\relax% + \advance\pgfmath@x by\c@pgfmath@counta pt\relax% + \pgfmath@x=0.6931471806\pgfmath@x% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% log2 function. +% +\pgfmathdeclarefunction{log2}{1}{% + \begingroup% + \pgfmathln@{#1}% + \pgfmath@x=\pgfmathresult pt\relax% + \pgfmath@x=1.442695041\pgfmath@x% 1/ln(2). + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% log10 function +% +\pgfmathdeclarefunction{log10}{1}{% + \begingroup% + \pgfmathln@{#1}% + \pgfmath@x=\pgfmathresult pt\relax% + \pgfmath@x=0.43429441\pgfmath@x% 1/ln(10). + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% exp function. +% +\pgfmathdeclarefunction{exp}{1}{% + \begingroup% + \pgfmath@xc=#1pt\relax% + \ifdim\pgfmath@xc<-9pt% + \pgfmath@x=1sp\relax% + \else% + \ifdim\pgfmath@xc<0pt% + \pgfmath@xc=-\pgfmath@xc% + \fi% + \pgfmath@x=1pt\relax% + \pgfmath@xa=1pt\relax% + \pgfmath@xb=\pgfmath@x% + \pgfmathloop% + \divide\pgfmath@xa by\pgfmathcounter% + \pgfmath@xa=\pgfmath@tonumber\pgfmath@xc\pgfmath@xa% + \advance\pgfmath@x by\pgfmath@xa% + \ifdim\pgfmath@x=\pgfmath@xb% + \else% + \pgfmath@xb=\pgfmath@x% + \repeatpgfmathloop% + \ifdim#1pt<0pt% + \pgfmathreciprocal@{\pgfmath@tonumber\pgfmath@x}% + \pgfmath@x=\pgfmathresult pt\relax% + \fi% + \fi% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% sqrt function. +% +\pgfmathdeclarefunction{sqrt}{1}{% + \begingroup% + \expandafter\pgfmath@x#1pt\relax% + \ifdim\pgfmath@x<0pt\relax% + \pgfmath@error{I cannot calculate the square-root of the negative number `#1'}{}% + \else% + \ifdim\pgfmath@x<10pt\relax% + \def\pgfmath@zeros{0}% + \def\pgfmath@targetiterations{1}% + \else% + \ifdim\pgfmath@x<100pt\relax% + \def\pgfmath@zeros{}% + \def\pgfmath@targetiterations{1}% + \else% + \ifdim\pgfmath@x<1000pt\relax% + \def\pgfmath@zeros{0}% + \def\pgfmath@targetiterations{2}% + \else% + \ifdim\pgfmath@x<10000pt\relax% + \def\pgfmath@zeros{}% + \def\pgfmath@targetiterations{2}% + \else% + \def\pgfmath@zeros{0}% + \def\pgfmath@targetiterations{3}% + \fi\fi\fi\fi\fi% + \edef\pgfmath@temp{\pgfmath@zeros\pgfmath@tonumber{\pgfmath@x}}% + \expandafter\pgfmath@sqrt@\pgfmath@temp\pgfmath@% +} +\def\pgfmath@sqrt@#1.#2\pgfmath@{\pgfmath@@sqrt@#1#2\pgfmath@empty\pgfmath@empty\pgfmath@} + +\def\pgfmath@@sqrt@#1#2{% + \c@pgfmath@countb=#1#2\relax% + \ifnum\c@pgfmath@countb>35\relax% + \ifnum\c@pgfmath@countb>63\relax% + \ifnum\c@pgfmath@countb>80\relax% + \c@pgfmath@counta=9\relax% + \else% + \c@pgfmath@counta=8\relax% + \fi% + \else% + \ifnum\c@pgfmath@countb>48\relax% + \c@pgfmath@counta=7\relax% + \else% + \c@pgfmath@counta=6\relax% + \fi% + \fi% + \else% + \ifnum\c@pgfmath@countb>15\relax% + \ifnum\c@pgfmath@countb>24\relax% + \c@pgfmath@counta5\relax% + \else% + \c@pgfmath@counta=4\relax% + \fi% + \else% + \ifnum\c@pgfmath@countb>3\relax% + \ifnum\c@pgfmath@countb>8\relax% + \c@pgfmath@counta=3\relax% + \else% + \c@pgfmath@counta=2\relax% + \fi% + \else% + \ifnum\c@pgfmath@countb>0\relax% + \c@pgfmath@counta=1\relax% + \else% + \c@pgfmath@counta=0\relax% + \fi% + \fi% + \fi% + \fi% + \edef\pgfmath@root{\the\c@pgfmath@counta}% + \edef\pgfmath@rootspecial{\the\c@pgfmath@counta}% + \multiply\c@pgfmath@counta by-\c@pgfmath@counta\relax% + \advance\c@pgfmath@counta by#1#2\relax% + \edef\pgfmath@remainder{\the\c@pgfmath@counta}% + \pgfmath@@@sqrt@% +} + +\def\pgfmath@@@sqrt@#1#2{% + \ifx\pgfmath@empty#1% + \edef\pgfmath@remainder{\pgfmath@remainder00}% + \def\pgfmath@tokens{\pgfmath@empty\pgfmath@empty}% + \else% + \ifx\pgfmath@empty#2% + \edef\pgfmath@remainder{\pgfmath@remainder#10}% + \def\pgfmath@tokens{\pgfmath@empty\pgfmath@empty}% + \else% + \edef\pgfmath@remainder{\pgfmath@remainder#1#2}% + \def\pgfmath@tokens{}% + \fi\fi% + \c@pgfmath@counta=\pgfmath@rootspecial\relax% + \multiply\c@pgfmath@counta by20\relax% + \c@pgfmath@countb=\c@pgfmath@counta% + \multiply\c@pgfmath@countb by6\relax% + \advance\c@pgfmath@countb by36\relax% + \c@pgfmath@countc=\c@pgfmath@counta% + \multiply\c@pgfmath@countc by2\relax% + \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% + \advance\c@pgfmath@countb by-\c@pgfmath@countc% + \advance\c@pgfmath@countb by-20\relax% + \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% + \advance\c@pgfmath@countb by-\c@pgfmath@countc% + \advance\c@pgfmath@countb by-12\relax% + \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% + \advance\c@pgfmath@countb by-\c@pgfmath@counta% + \advance\c@pgfmath@countb by-3\relax% + \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% + \def\pgfmath@digit{0}% + \else% + \def\pgfmath@digit{1}% + \fi% + \else% + \advance\c@pgfmath@countb by\c@pgfmath@counta% + \advance\c@pgfmath@countb by5\relax% + \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% + \def\pgfmath@digit{2}% + \else% + \def\pgfmath@digit{3}% + \fi% + \fi% + \else% + \advance\c@pgfmath@countb by\c@pgfmath@counta% + \advance\c@pgfmath@countb by9\relax% + \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% + \def\pgfmath@digit{4}% + \else% + \def\pgfmath@digit{5}% + \fi% + \fi% + \else% + \advance\c@pgfmath@countb by\c@pgfmath@countc% + \advance\c@pgfmath@countb by28\relax% + \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% + \advance\c@pgfmath@countb by-\c@pgfmath@counta% + \advance\c@pgfmath@countb by-15\relax% + \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% + \def\pgfmath@digit{6}% + \else% + \def\pgfmath@digit{7}% + \fi% + \else% + \advance\c@pgfmath@countb by\c@pgfmath@counta% + \advance\c@pgfmath@countb by17\relax% + \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% + \def\pgfmath@digit{8}% + \else% + \def\pgfmath@digit{9}% + \fi% + \fi% + \fi% + \edef\pgfmath@rootspecial{\pgfmath@rootspecial\pgfmath@digit}% + \advance\c@pgfmath@counta by\pgfmath@digit\relax% + \multiply\c@pgfmath@counta by-\pgfmath@digit\relax% + \advance\c@pgfmath@counta by\pgfmath@remainder\relax% + \edef\pgfmath@remainder{\the\c@pgfmath@counta}% + \c@pgfmath@counta=\pgfmath@targetiterations\relax% + \advance\c@pgfmath@counta by-1\relax% + \edef\pgfmath@targetiterations{\the\c@pgfmath@counta}% + \ifnum\c@pgfmath@counta=0\relax% + \edef\pgfmath@root{\pgfmath@root.\pgfmath@digit}% + \else% + \edef\pgfmath@root{\pgfmath@root\pgfmath@digit}% + \fi% + \ifnum\c@pgfmath@counta=-4\relax% -n+1 digits of precision. + \let\pgfmath@next\pgfmath@sqrt@end% + \else% + \let\pgfmath@next\pgfmath@@@sqrt@% + \fi% + \expandafter\pgfmath@next\pgfmath@tokens% +} + +\def\pgfmath@sqrt@end#1\pgfmath@{% + \edef\pgfmathresult{\pgfmath@root}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup} + +% \pgfmathpow +% +% Calculates #1 ^ #2 +% +\pgfmathdeclarefunction{pow}{2}{% + \begingroup% + \pgfmath@xa=#1pt% + \pgfmath@xb=#2pt% + \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% + \pgfmath@returnone\pgf@x% + \endgroup% +} + +% factorial function. +% +\pgfmathdeclarefunction{factorial}{1}{% + \begingroup% + \afterassignment\pgfmath@gobbletilpgfmath@% + \c@pgfmath@counta=#1\relax\pgfmath@% + \pgfmath@x=1pt\relax% + \pgfmathloop% + \ifnum\c@pgfmath@counta<2\relax% + \else% + \multiply\pgfmath@x by\c@pgfmath@counta% + \advance\c@pgfmath@counta by-1\relax% + \repeatpgfmathloop% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex new file mode 100644 index 00000000000..a493b6c6b62 --- /dev/null +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex @@ -0,0 +1,240 @@ +% Copyright 2007 by Mark Wibrow +% +% This file may be distributed and/or modified +% +% 1. under the LaTeX Project Public License and/or +% 2. under the GNU Public License. +% +% See the file doc/generic/pgf/licenses/LICENSE for more details. + +% Declare a function for the parser. +% +% #1 - the name of the function. +% #2 - arity (or ... for variable arguments). +% #3 - the code for the function. +% +% Use \pgfmathdeclarefunction* to force a redefinition if the function exists already. +\def\pgfmathdeclarefunction{\pgfmath@ifnextchar*\pgfmathdeclarefunction@force\pgfmathdeclarefunction@check} +\def\pgfmathdeclarefunction@check#1#2#3{% + \expandafter\ifx\csname pgfmath@function@#1\endcsname\relax% + \pgfmath@declarefunction{#1}{#2}{#3}% + \else% + \pgfmath@error{The function `#1' already exists}{}% + \fi% +} +\def\pgfmathdeclarefunction@force*{\pgfmath@declarefunction}% + +\def\pgfmathredeclarefunction#1#2{% + \expandafter\ifx\csname pgfmath@function@#1\endcsname\relax% + \pgfmath@error{The function `#1' does not exist}{}% + \else% + \pgfmath@namedef{pgfmath#1@}{#2}% + \fi% +} + +\def\pgfmath@declarefunction#1#2{% + \pgfmath@namedef{pgfmath@function@#1}{#1}% + \pgfmath@namedef{pgfmath@operation@#1@type}{function}% + \pgfmath@namedef{pgfmath@operation@#1@arity}{#2}% + \pgfmath@namedef{pgfmath@operation@#1@infix}{#1}% + \pgfmath@namedef{pgfmath@operation@#1@precedence}{1000}% + \expandafter\ifx\csname pgfmath@operation@#1@arity\endcsname\pgfmath@dots% + \pgfmath@namedef{pgfmath@operation@#1@arity}{1}% + \else% + \ifnum\csname pgfmath@operation@#1@arity\endcsname>9\relax% + \pgfmath@namedef{pgfmath@operation@#1@arity}{1}% + \fi% + \fi% + \edef\pgfmath@marshal{% + \noexpand\pgfmath@@declarefunction% + {\expandafter\noexpand\csname pgfmath#1\endcsname}% + {\expandafter\noexpand\csname pgfmath#1@\endcsname}% + {\csname pgfmath@operation@#1@arity\endcsname}% + }% + \pgfmath@marshal% +} + +% #1 - \pgfmath<name>. +% #2 - \pgfmath<name>@. +% #3 - arity. +% #4 - code for function <name>. +% +\def\pgfmath@@declarefunction#1#2#3#4{% Function of arity 0 - 9. + \ifcase#3\relax% + \def#1{#2}% + \def#2{#4}% + \or + \def#1##1{\pgfmathparse{##1}\expandafter#2\expandafter{\pgfmathresult}}% + \def#2##1{#4}% + \else% + \pgfmath@toks={}% + \pgfmathloop% + \ifnum\pgfmathcounter>#3\relax% + \else% + \expandafter\pgfmath@addto@toks\expandafter{\pgfmath@char@hash}% + \expandafter\pgfmath@addto@toks\expandafter{\pgfmathcounter}% + \repeatpgfmathloop% + \edef\pgfmath@head{\noexpand\def\noexpand#1\the\pgfmath@toks}% + \edef\pgfmath@@head{\noexpand\def\noexpand#2\the\pgfmath@toks}% + \pgfmath@toks={}% + \def\pgfmath@arguments{}% + \pgfmathloop% + \ifnum\pgfmathcounter>#3\relax% + \else% + \pgfmath@addto@toks{\pgfmathparse}% + \expandafter\expandafter\expandafter\pgfmath@addto@toks% + \expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter% + {\expandafter\pgfmath@char@hash\pgfmathcounter}}% + \pgfmath@addto@toks{\let}% + \expandafter\pgfmath@addto@toks\expandafter{% + \csname pgfmath@argument@\pgfmathcounter\endcsname=\pgfmathresult}% + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter% + \pgfmath@arguments\expandafter\expandafter\expandafter{\expandafter% + \pgfmath@arguments\expandafter{\csname pgfmath@argument@\pgfmathcounter\endcsname}}% + \repeatpgfmathloop% + \expandafter\pgfmath@addto@toks\expandafter{\expandafter#2\pgfmath@arguments}% + \edef\pgfmath@body{{\the\pgfmath@toks}}% + \expandafter\pgfmath@head\pgfmath@body% + \pgfmath@@head{#4}% + \fi% +} + +\def\pgfmath@addto@toks#1{% + \edef\pgfmath@toks@expanded{\the\pgfmath@toks}% + \expandafter\pgfmath@toks\expandafter{\pgfmath@toks@expanded#1}} + +% Key for declaring local functions. +% +\pgfkeys{% + /pgf/declare function/.code={% + \pgfmath@local@functions#1@=@;% + } +} + +\def\pgfmath@local@gobbleone#1{} +\def\pgfmath@local@at{@}% + +\def\pgfmath@local@functions{% + \pgfutil@ifnextchar x{\pgfmath@local@@functions}{\pgfmath@local@@functions}% +} + +\def\pgfmath@local@@functions#1=#2;{% + \def\pgfmath@local@temp{#1}% + \ifx\pgfmath@local@temp\pgfmath@local@at% + \let\pgfmath@local@next=\relax% + \else% + \pgfmath@local@function#1=#2;% + \let\pgfmath@local@next=\pgfmath@local@functions% + \fi% + \pgfmath@local@next% +} + +\def\pgfmath@local@function{% + \let\pgfmath@local@name=\pgfutil@empty% + \let\pgfmath@local@args=\pgfutil@empty% + \let\pgfmath@local@body=\pgfutil@empty% + \pgfmath@local@@function} + +\def\pgfmath@local@@function#1{% + \if#1=% + \let\pgfmath@local@next=\pgfmath@local@function@body% + \else% + \if#1(% + \let\pgfmath@local@next=\pgfmath@local@function@args% + \else% + \expandafter\def\expandafter\pgfmath@local@name\expandafter{\pgfmath@local@name#1}% + \let\pgfmath@local@next=\pgfmath@local@@function% + \fi% + \fi% + \pgfmath@local@next% +} + +\def\pgfmath@local@function@args#1){% + \def\pgfmath@local@args{#1}% + \pgfmath@local@@function} + +\def\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\pgfmathdeclarefunction{\pgfmath@local@name}{\the\c@pgf@counta}% + {\noexpand\pgfmathparse{\the\pgfmath@toks}}% + }% + \endgroup% + \pgfmath@local@temp% +} + +\def\pgfmath@local@function@@body#1,{% + \def\pgfmath@local@test{#1}% + \ifx\pgfmath@local@test\pgfutil@empty% + \let\pgfmath@local@next=\relax% + \else% + \edef\pgfmath@local@var@string{@\expandafter\pgfmath@local@gobbleone\string#1}% + \advance\c@pgf@counta by1\relax% + \expandafter\expandafter\expandafter\pgfmath@toks\expandafter\expandafter\expandafter=% + \expandafter\expandafter\expandafter{\expandafter\pgfmath@char@hash\the\c@pgf@counta}% + \edef#1{\the\pgfmath@toks}% + \pgfmath@toks={}% + \expandafter\pgfmath@local@function@@@body\pgfmath@local@body @% + \edef\pgfmath@local@body{\the\pgfmath@toks}% + \let\pgfmath@local@next=\pgfmath@local@function@@body% + \fi% + \pgfmath@local@next% +} + +\def\pgfmath@local@function@@@body{% + \pgfutil@ifnextchar\bgroup{\pgfmath@local@function@@@body@bgroup}% + {\pgfmath@local@function@@@body@nobgroup}}% + +\def\pgfmath@local@function@@@body@bgroup#1{% + \begingroup% + \pgfmath@toks={}% + \pgfmath@local@function@@@body#1 @% + \xdef\pgfmath@local@temp{{\the\pgfmath@toks}}% + \endgroup% + \expandafter\pgfmath@addto@toks\expandafter{\pgfmath@local@temp}% + \pgfmath@local@function@@@body% +} + +\def\pgfmath@local@function@@@body@nobgroup#1{% + \ifx#1@% + \let\pgfmath@local@next=\relax% + \else% + \let\pgfmath@local@next=\pgfmath@local@function@@@body% + \edef\pgfmath@local@var@@string{@\expandafter\pgfmath@local@gobbleone\string#1}% + \ifx\pgfmath@local@var@@string\pgfmath@local@var@string% + \expandafter\pgfmath@addto@toks\expandafter{#1}% + \else% + \edef\pgfmath@local@temp{\the\pgfmath@toks}% + \pgfmath@toks={#1}% + \edef\pgfmath@local@@temp{\the\pgfmath@toks}% + \expandafter\pgfmath@toks\expandafter=\expandafter{\pgfmath@local@temp}% + \expandafter\pgfmath@addto@toks\expandafter{\pgfmath@local@@temp}% + \fi% + \fi% + \pgfmath@local@next% +} + +% Allows to define 'x' as some \TeX command '#2'. +\def\pgfmathdeclarepseudoconstant#1#2{% + \pgfmathdeclarefunction*{#1}{0}{#2}% +}% +% Redefines a pseudo constant '#1'. +\def\pgfmathredeclarepseudoconstant#1#2{% + \pgfmathredeclarefunction{#1}{#2}% +}% + +\input pgfmathfunctions.basic.code.tex +\input pgfmathfunctions.trigonometric.code.tex +\input pgfmathfunctions.random.code.tex +\input pgfmathfunctions.comparison.code.tex +\input pgfmathfunctions.base.code.tex +\input pgfmathfunctions.round.code.tex +\input pgfmathfunctions.misc.code.tex diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.comparison.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.comparison.code.tex new file mode 100644 index 00000000000..54a8d64220e --- /dev/null +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.comparison.code.tex @@ -0,0 +1,179 @@ +% Copyright 2007 by Mark Wibrow +% +% This file may be distributed and/or modified +% +% 1. under the LaTeX Project Public License and/or +% 2. under the GNU Public License. +% +% See the file doc/generic/pgf/licenses/LICENSE for more details. + +% This file defines the mathematical functions and operators. +% +% Version 1.4142135 11/8/2008 + +\pgfmathdeclarefunction{greater}{2}{% + \begingroup% + \ifdim#1pt>#2pt\relax% + \def\pgfmathresult{1}% + \else% + \def\pgfmathresult{0}% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} +\let\pgfmathgreaterthan=\pgfmathgreater + +\pgfmathdeclarefunction{less}{2}{% + \begingroup% + \ifdim#1pt<#2pt\relax% + \def\pgfmathresult{1}% + \else% + \def\pgfmathresult{0}% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} +\let\pgfmathlessthan=\pgfmathless + +\pgfmathdeclarefunction{equal}{2}{% + \begingroup% + \ifdim#1pt=#2pt\relax% + \def\pgfmathresult{1}% + \else% + \def\pgfmathresult{0}% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} +\let\pgfmathequalto=\pgfmathequal + + +% approxequalto function from Christian Feuersanger. +% +\newif\ifpgfmathcomparison +\pgfmathdeclarefunction{approxequalto}{2}{% + \begingroup% + \pgfmath@x=#1pt\relax% + \pgfmath@y=#2pt\relax% + \advance\pgfmath@x by-\pgfmath@y% + \ifdim\pgfmath@x<0pt\relax% + \multiply\pgfmath@x by-1\relax% + \fi + \ifdim\pgfmath@x<0.0001pt\relax% + \def\pgfmathresult{1.0}% + \global\pgfmathcomparisontrue% + \else% + \def\pgfmathresult{0.0}% + \global\pgfmathcomparisonfalse% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + + + +% ifthenelse function. +% +\pgfmathdeclarefunction{ifthenelse}{3}{% + \begingroup% + \ifdim#1pt=0.0pt\relax% + \expandafter\def\expandafter\pgfmathresult\expandafter{#3}% + \else% + \expandafter\def\expandafter\pgfmathresult\expandafter{#2}% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% notequal function. +% +\pgfmathdeclarefunction{notequal}{2}{% + \begingroup% + \ifdim#1pt=#2pt\relax% + \def\pgfmathresult{0}% + \else% + \def\pgfmathresult{1}% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% notless function. +% +\pgfmathdeclarefunction{notless}{2}{% + \begingroup% + \ifdim#1pt<#2pt\relax% + \def\pgfmathresult{0}% + \else% + \def\pgfmathresult{1}% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% notgreater function. +% +\pgfmathdeclarefunction{notgreater}{2}{% + \begingroup% + \ifdim#1pt>#2pt\relax% + \def\pgfmathresult{0}% + \else% + \def\pgfmathresult{1}% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% and function. +% +\pgfmathdeclarefunction{and}{2}{% + \begingroup% + \def\pgfmathresult{1}% + \ifdim#1pt=0pt\relax% + \def\pgfmathresult{0}% + \else% + \ifdim#2pt=0pt\relax% + \def\pgfmathresult{0}% + \fi% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% or function. +% +\pgfmathdeclarefunction{or}{2}{% + \begingroup% + \def\pgfmathresult{0}% + \ifdim#1pt=0pt\relax% + \ifdim#2pt=0pt\relax% + \else% + \def\pgfmathresult{1}% + \fi% + \else% + \def\pgfmathresult{1}% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% not function. +% +\pgfmathdeclarefunction{not}{1}{% + \begingroup% + \ifdim#1pt=0pt\relax% + \def\pgfmathresult{1}% + \else% + \def\pgfmathresult{0}% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% true function. +% +\pgfmathdeclarefunction{true}{0}{\def\pgfmathresult{1}} + +% false function. +% +\pgfmathdeclarefunction{false}{0}{\def\pgfmathresult{0}} diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex new file mode 100644 index 00000000000..65460e4b3cc --- /dev/null +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex @@ -0,0 +1,320 @@ +% Copyright 2007 by Mark Wibrow +% +% This file may be distributed and/or modified +% +% 1. under the LaTeX Project Public License and/or +% 2. under the GNU Public License. +% +% See the file doc/generic/pgf/licenses/LICENSE for more details. + +% This file defines the mathematical functions and operators. +% +% Version 1.414213 29/9/2007 + +% veclen function adpated from ideas due to Rouben Rostamian. +% +% Calcluate the Eulidean length of a 2D vector. +% +% +\pgfmathdeclarefunction{veclen}{2}{% + \begingroup% + \pgfmath@x#1pt\relax% + \pgfmath@y#2pt\relax% + \ifdim\pgfmath@x<0pt\relax% + \pgfmath@x-\pgfmath@x% + \fi% + \ifdim\pgfmath@y<0pt\relax% + \pgfmath@y-\pgfmath@y% + \fi% + \ifdim\pgfmath@x=0pt\relax% + \pgfmath@x\pgfmath@y% + \else% + \ifdim\pgfmath@y=0pt\relax% + \else% + \ifdim\pgfmath@x>\pgfmath@y% + \pgfmath@xa\pgfmath@x% + \pgfmath@x\pgfmath@y% + \pgfmath@y\pgfmath@xa% + \fi% + % We use a scaling factor to reduce errors. + \ifdim\pgfmath@y>10000pt\relax% + \c@pgfmath@counta1500\relax% + \else% + \ifdim\pgfmath@y>1000pt\relax% + \c@pgfmath@counta150\relax% + \else% + \ifdim\pgfmath@y>100pt\relax% + \c@pgfmath@counta50\relax% + \else% + \c@pgfmath@counta1\relax% + \fi% + \fi% + \fi% + \divide\pgfmath@x\c@pgfmath@counta\relax% + \divide\pgfmath@y\c@pgfmath@counta\relax% + \pgfmathreciprocal@{\pgfmath@tonumber{\pgfmath@y}}% + \pgfmath@x\pgfmathresult\pgfmath@x% + \pgfmath@xa\pgfmath@tonumber{\pgfmath@x}\pgfmath@x% + \edef\pgfmath@temp{\pgfmath@tonumber{\pgfmath@xa}}% + % + % Use A+x^2*(B+x^2*(C+x^2*(D+E*x^2))) + % where + % A = +1.000012594 + % B = +0.4993615349 + % C = -0.1195159052 + % D = +0.04453994279 + % E = -0.01019210944 + % + \pgfmath@x-0.01019210944\pgfmath@xa% + \advance\pgfmath@x0.04453994279pt\relax% + \pgfmath@x\pgfmath@temp\pgfmath@x% + \advance\pgfmath@x-0.1195159052pt\relax% + \pgfmath@x\pgfmath@temp\pgfmath@x% + \advance\pgfmath@x0.4993615349pt\relax% + \pgfmath@x\pgfmath@temp\pgfmath@x% + \advance\pgfmath@x1.000012594pt\relax% + \ifdim\pgfmath@y<0pt\relax% + \pgfmath@y-\pgfmath@y% + \fi% + \pgfmath@x\pgfmath@tonumber{\pgfmath@y}\pgfmath@x% + % Invert the scaling factor. + \multiply\pgfmath@x\c@pgfmath@counta\relax% + \fi% + \fi% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + +% Hyperbolic functions contributed by Martin Heller. +% +\pgfmathdeclarefunction{cosh}{1}{% + \begingroup + \edef\pgfmath@arg{#1}% + \pgfmathexp@{\pgfmath@arg}% + \pgfmath@x=\pgfmathresult pt\relax% + \pgfmathexp@{-\pgfmath@arg}% + \advance\pgfmath@x by\pgfmathresult pt\relax% + \divide\pgfmath@x by2\relax% + \pgfmath@returnone\pgfmath@x% + \endgroup} + +\pgfmathdeclarefunction{sinh}{1}{% + \begingroup + \edef\pgfmath@arg{#1}% + \pgfmathexp@{\pgfmath@arg}% + \pgfmath@x=\pgfmathresult pt\relax% + \pgfmathexp@{-\pgfmath@arg}% + \advance\pgfmath@x by-\pgfmathresult pt\relax% + \divide\pgfmath@x by2\relax% + \pgfmath@returnone\pgfmath@x% + \endgroup +}% + +\pgfmathdeclarefunction{tanh}{1}{% + \begingroup + \edef\pgfmath@arg{#1}% + \pgfmathsinh@{\pgfmath@arg}% + \pgfmath@x=\pgfmathresult pt\relax% + \pgfmathcosh@{\pgfmath@arg}% + \pgfmath@y=\pgfmathresult pt\relax% + \pgfmathdivide@{\pgfmath@tonumber{\pgfmath@x}}{\pgfmath@tonumber{\pgfmath@y}}% + \pgfmath@x=\pgfmathresult pt\relax% + \pgfmath@returnone\pgfmath@x% + \endgroup +}% + +% \pgfmathscientific +% +% Return the value of #1e#2 +% +% e.g. \pgfmathscientific{1.23456789123}{4} +% +% defines \pgfmathresult as 12345.67891 +% +% NB These arguments *are not parsed*, as the long mantissa would be lost. +% +\def\pgfmathscientific#1#2{% + \begingroup% + \edef\pgfmath@sci@exponent{#2}% + \pgfmath@x#1pt\relax% + \ifdim\pgfmath@x<0pt\relax% + \pgfmath@x-\pgfmath@x% + \edef\pgfmath@sci@sign{-}% + \expandafter\edef\expandafter\pgfmath@temp\expandafter{\expandafter\pgfmath@gobbleone#1}% + \else% + \edef\pgfmath@sci@sign{+}% + \edef\pgfmath@temp{#1}% + \fi% + \expandafter\pgfmath@in@\expandafter.\expandafter{#1}% + \ifpgfmath@in@% + \else% + \edef\pgfmath@temp{\pgfmath@temp.0}% + \fi% + \expandafter\pgfmath@scientific@@\pgfmath@temp00000000000\pgfmath@} + +\def\pgfmath@scientific@@#1.#2#3#4#5#6{% + \edef\pgfmath@sci@int{#1}% + \edef\pgfmath@sci@mantissaA{#2#3#4#5#6}% + \pgfmath@scientific@@@} + +\def\pgfmath@scientific@@@#1#2#3#4#5#6\pgfmath@{% + \edef\pgfmath@sci@mantissaB{#1#2#3#4#5}% + \c@pgfmath@counta\pgfmath@sci@exponent\relax% + \c@pgfmath@countb\c@pgfmath@counta% + \ifnum\c@pgfmath@counta<0\relax% + \c@pgfmath@counta-\c@pgfmath@counta% + \fi% + \pgfmathpow@{10}{\the\c@pgfmath@counta}% + \afterassignment\pgfmath@gobbletilpgfmath@ + \c@pgfmath@countc\pgfmathresult\relax\pgfmath@ + \edef\pgfmath@sci@factor{\the\c@pgfmath@countc}% + \ifnum\c@pgfmath@countb<0\relax% + % xE-y: easy... + \pgfmath@x\pgfmath@sci@int.\pgfmath@sci@mantissaA pt\relax% + \divide\pgfmath@x\pgfmath@sci@factor\relax% + \else% + % xE+y: + % Must do this way so as not lose digits in a long mantissa. Sigh... + \c@pgfmath@counta\pgfmath@sci@int% + \c@pgfmath@countb\pgfmath@sci@mantissaA% + \multiply\c@pgfmath@counta\pgfmath@sci@factor\relax% + \multiply\c@pgfmath@countb\pgfmath@sci@factor\relax% + \c@pgfmath@countc\c@pgfmath@countb% + \divide\c@pgfmath@countb100000\relax% + \advance\c@pgfmath@counta\c@pgfmath@countb% + \multiply\c@pgfmath@countb100000\relax% + \advance\c@pgfmath@countc-\c@pgfmath@countb% + \c@pgfmath@countb\pgfmath@sci@mantissaB\relax% + \multiply\c@pgfmath@countb\pgfmath@sci@factor\relax% + \divide\c@pgfmath@countb100000\relax% + \advance\c@pgfmath@countc\c@pgfmath@countb% + \advance\c@pgfmath@countc100000\relax% + \edef\pgfmath@sci@result{\pgfmath@sci@sign\the\c@pgfmath@counta.\expandafter\pgfmath@gobbleone\the\c@pgfmath@countc pt}% + \pgfmath@x\pgfmath@sci@result\relax% + \fi% + \pgfmath@returnone\pgfmath@x% + \endgroup} + + + +% width function. +% +\pgfmathdeclarefunction{width}{1}{% + \begingroup% + \setbox\pgfmath@box=\hbox{{\pgfmath@selectfont{#1}}}% + \pgfmath@x=\wd\pgfmath@box% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + + +% height function. +% +\pgfmathdeclarefunction{height}{1}{% + \begingroup% + \setbox\pgfmath@box=\hbox{{\pgfmath@selectfont{#1}}}% + \pgfmath@x=\ht\pgfmath@box% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + +% depth function. +% +\pgfmathdeclarefunction{depth}{1}{% + \begingroup% + \setbox\pgfmath@box=\hbox{{\pgfmath@selectfont{#1}}}% + \pgfmath@x=\dp\pgfmath@box% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} + + +% array function. +% +\pgfmathdeclarefunction{array}{2}{% + \begingroup% + \afterassignment\pgfmath@gobbletilpgfmath@\pgfmath@count=#2\relax\pgfmath@% + \expandafter\pgfmatharray@@#1\pgfmath@stop% +} + +\def\pgfmath@token@stop{\pgfmath@stop}% +\def\pgfmatharray@@#1{% + \def\pgfmath@temp{#1}% + \advance\pgfmath@count by-1\relax% + \ifx\pgfmath@temp\pgfmath@token@stop% + \pgfmath@error{Array index out of bounds.}{}% + \def\pgfmathresult{0}% + \pgfmath@smuggleone\pgfmathresult\endgroup% + \let\pgfmath@next=\relax% + \else% + \ifnum\pgfmath@count=-1\relax% + \def\pgfmathresult{#1}% + \let\pgfmath@next=\pgfmatharray@@@% + \else% + \let\pgfmath@next=\pgfmatharray@@% + \fi% + \fi% + \pgfmath@next} + +\def\pgfmatharray@@@#1\pgfmath@stop{% + \pgfmath@smuggleone\pgfmathresult\endgroup% +} + + +% max function. +% +\pgfmathdeclarefunction{max}{...}{% + \begingroup% + \pgfmath@x=-16383pt\relax% + \pgfmathmax@@#1{}} + +\def\pgfmathmax@@#1{% + \def\pgfmath@temp{#1}% + \ifx\pgfmath@temp\pgfmath@empty% + \let\pgfmath@next=\pgfmathmax@@@% + \else% + \ifdim#1pt>\pgfmath@x% + \pgfmath@x=#1pt\relax% + \fi% + \let\pgfmath@next=\pgfmathmax@@% + \fi% + \pgfmath@next} + +\def\pgfmathmax@@@{\pgfmath@returnone\pgfmath@x\endgroup}% + +% For compatability with old code. +\def\pgfmathmax#1#2{% + \pgfmathparse{getargs(#1,#2)}% + \expandafter\pgfmathmax@\expandafter{\pgfmathresult}% +} + +% min function. +% +\pgfmathdeclarefunction{min}{...}{% + \begingroup% + \pgfmath@x=16383pt\relax% + \pgfmathmin@@#1{}} + +\def\pgfmathmin@@#1{% + \def\pgfmath@temp{#1}% + \ifx\pgfmath@temp\pgfmath@empty% + \let\pgfmath@next=\pgfmathmin@@@% + \else% + \ifdim#1pt<\pgfmath@x% + \pgfmath@x=#1pt\relax% + \fi% + \let\pgfmath@next=\pgfmathmin@@% + \fi% + \pgfmath@next} + +\def\pgfmathmin@@@{\pgfmath@returnone\pgfmath@x\endgroup}% + +% For compatability with old code. +\def\pgfmathmin#1#2{% + \pgfmathparse{getargs(#1,#2)}% + \expandafter\pgfmathmin@\expandafter{\pgfmathresult}% +} + diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathrnd.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex index ea8d5bb3092..2811d67c101 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathrnd.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex @@ -39,8 +39,8 @@ % % #1 -> the new seed. % -\def\pgfmathsetseed#1{\pgfmathparse{#1}\expandafter\pgfmath@setseed\pgfmathresult\relax}% -\def\pgfmath@setseed#1.#2\relax{\def\pgfmath@rnd@z{#1}}% +\def\pgfmathsetseed#1{\pgfmathparse{#1}\expandafter\pgfmath@setseed\pgfmathresult.0\pgfmath@stop}% +\def\pgfmath@setseed#1.#2\pgfmath@stop{\def\pgfmath@rnd@z{#1}}% % Alternative paramaters - see Press et al (1992) p278-279, % for discussion. @@ -86,7 +86,7 @@ % % Generates a pseudo-random number between 0 and 1. % -\def\pgfmathrnd{% +\pgfmathdeclarefunction{rnd}{0}{% \begingroup% \pgfmathgeneratepseudorandomnumber% \c@pgfmath@counta\pgfmathresult% @@ -95,12 +95,12 @@ \multiply\c@pgfmath@countb-100001\relax% \advance\c@pgfmath@countb\c@pgfmath@counta% \advance\c@pgfmath@countb1000000\relax% - \expandafter\pgfmathrnd@\the\c@pgfmath@countb\pgfmath@% + \expandafter\pgfmathrnd@@\the\c@pgfmath@countb\pgfmath@% \pgfmath@returnone\pgfmath@x% \endgroup% }% -\def\pgfmathrnd@#1#2#3\pgfmath@{% +\def\pgfmathrnd@@#1#2#3\pgfmath@{% \edef\pgfmath@temp{#2.#3}% \pgfmath@x=\pgfmath@temp pt\relax% }% @@ -109,7 +109,7 @@ % % Generates a pseudo-random number between -1 and 1. % -\def\pgfmathrand{% +\pgfmathdeclarefunction{rand}{0}{% \begingroup% \pgfmathgeneratepseudorandomnumber% \c@pgfmath@counta\pgfmathresult% @@ -123,12 +123,12 @@ \else% \advance\c@pgfmath@countb1000000\relax% \fi% - \expandafter\pgfmathrand@\the\c@pgfmath@countb\pgfmath@% + \expandafter\pgfmathrand@@\the\c@pgfmath@countb\pgfmath@% \pgfmath@returnone\pgfmath@x% \endgroup% }% -\def\pgfmathrand@#1#2#3#4\pgfmath@{% +\def\pgfmathrand@@#1#2#3#4\pgfmath@{% \ifx#1-% \edef\pgfmath@temp{-#3.#4}% \else% @@ -137,6 +137,32 @@ \pgfmath@x=\pgfmath@temp pt\relax% }% +\pgfmathdeclarefunction{random}{...}{% + \begingroup% + \def\pgfmath@temp{#1}% + \ifx\pgfmath@temp\pgfmath@empty% + \pgfmathrnd@% + \else% + \expandafter\pgfmathrandom@@#1\pgfmath@stop% + \fi% + \pgfmath@smuggleone\pgfmathresult% + \endgroup} + +\def\pgfmathrandom@@{\futurelet\pgfmath@token\pgfmathrandom@@@} +\def\pgfmathrandom@@@{% + \ifx\pgfmath@token\bgroup% + \expandafter\pgfmath@random@@@@% + \else% + \expandafter\pgfmath@random@@@@@% + \fi% +} +\def\pgfmath@random@@@@@#1\pgfmath@stop{% + \pgfmathrandominteger\pgfmathresult{1}{#1}% +} +\def\pgfmath@random@@@@#1#2\pgfmath@stop{% + \pgfmathrandominteger\pgfmathresult{#1}{#2}% +} + % \pgfmathrandominteger % % Return a 'randomly' selected integer in the range #2 - #3 (inclusive). @@ -209,4 +235,5 @@ \pgfmath@ifundefined{pgfmath@randomlist@#2}{\pgfmath@error{Unknown random list `#2'}}{% \edef\pgfmath@randomlistlength{\csname pgfmath@randomlist@#2\endcsname}% \pgfmathrandominteger{\pgfmath@randomtemp}{1}{\pgfmath@randomlistlength}% - \def#1{\csname pgfmath@randomlist@#2@\pgfmath@randomtemp\endcsname}}}
\ No newline at end of file + \def#1{\csname pgfmath@randomlist@#2@\pgfmath@randomtemp\endcsname}}} +
\ No newline at end of file diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round.code.tex new file mode 100644 index 00000000000..03f9ca270ae --- /dev/null +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.round.code.tex @@ -0,0 +1,112 @@ +% Copyright 2007 by Mark Wibrow +% +% This file may be distributed and/or modified +% +% 1. under the LaTeX Project Public License and/or +% 2. under the GNU Public License. +% +% See the file doc/generic/pgf/licenses/LICENSE for more details. + +% This file defines the mathematical functions and operators. +% +% Version 1.414213 29/9/2007 + +% round function. Uses asymmetric half-up rounding. +% +\pgfmathdeclarefunction{round}{1}{% + \begingroup% + \expandafter\pgfmath@x#1pt\relax% + \afterassignment\pgfmath@xa% + \expandafter\c@pgfmath@counta\the\pgfmath@x\relax% + \pgfmath@xb\pgfmath@x% + \ifdim\pgfmath@xb<0pt\relax% + \ifdim\pgfmath@xa<0.5pt\relax% + \else% + \advance\c@pgfmath@counta-1\relax% + \fi% + \else% + \ifdim\pgfmath@xa<0.5pt\relax% + \else% + \advance\c@pgfmath@counta1\relax% + \fi% + \fi% + \pgfmath@returnone\the\c@pgfmath@counta pt% + \endgroup% +}% + +% floor function. +% +\pgfmathdeclarefunction{floor}{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% +}% + +% ceil function. +% +\pgfmathdeclarefunction{ceil}{1}{% + \begingroup% + \expandafter\pgfmath@x#1pt\relax% + \afterassignment\pgfmath@gobbletilpgfmath@% + \expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@% + \pgfmath@y\pgfmath@x% + \advance\pgfmath@y-\c@pgfmath@counta pt\relax% + \pgfmath@x\c@pgfmath@counta pt\relax% + \ifdim\pgfmath@y>0pt\relax% + \advance\pgfmath@x1pt\relax% + \fi% + \pgfmath@returnone\pgfmath@x% + \endgroup% +}% + +% int function +% +\pgfmathdeclarefunction{int}{1}{% + \begingroup% + \expandafter\pgfmathint@@#1.\pgfmath@stop + \pgfmath@smuggleone\pgfmathresult% + \endgroup} + +\def\pgfmathint@@#1.#2\pgfmath@stop{% + \def\pgfmath@temp{#1}% + \ifx\pgfmath@temp\pgfmath@empty% + \def\pgfmathresult{0}% + \else% + \pgfmath@in@{#1}{+-+0-0}% + \ifpgfmath@in@ + \def\pgfmathresult{0}% + \else% + \def\pgfmathresult{#1}% + \fi% + \fi} + +% frac function. +% +\pgfmathdeclarefunction{frac}{1}{% + \begingroup% + \expandafter\pgfmathfrac@@#1.\pgfmath@stop% + \pgfmath@smuggleone\pgfmathresult% + \endgroup} + +\def\pgfmathfrac@@#1.{% + \pgfmath@ifnextchar\pgfmath@stop{\def\pgfmathresult{0.0}\pgfmath@gobbleone}{\pgfmathfrac@@@}% +} +\def\pgfmathfrac@@@#1.\pgfmath@stop{\def\pgfmathresult{0.#1}} + +% real function. +% +\pgfmathdeclarefunction{real}{1}{% + \begingroup% + \pgfmath@x=#1pt\relax% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% +} diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathtrig.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code.tex index 20d86dd8bdf..6b60eb7ec16 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathtrig.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code.tex @@ -7,7 +7,7 @@ % % See the file doc/generic/pgf/licenses/LICENSE for more details. -% This file defines the trigonometric functions/operations. +% This file defines the trigonometric functions/functions. % % Much of this file is based on ideas and code (particularly % the old \pgfcoremath.code.tex) due to Till Tantau. @@ -16,18 +16,14 @@ % \pgfmathpi % -\def\pgfmathpi{\edef\pgfmathresult{\pgfmath@pi}} -\def\pgfmath@pi{3.14159} +\pgfmathdeclarefunction{pi}{0}{\def\pgfmathresult{3.141592654}} % \pgfmathradians % (for comptability with 1.18 beta, will be deprecated) % % Convert #1 from radians to degrees (accurate to 1 deg). % -\def\pgfmathradians#1{% - \pgfmathparse{#1}% - \pgfmathradians@{\pgfmathresult}} -\def\pgfmathradians@#1{% +\pgfmathdeclarefunction{radians}{1}{% \begingroup% \expandafter\pgfmath@x#1pt\relax% \pgfmath@x57.29577\pgfmath@x\relax% 57.29577 = 360/(2*pi) @@ -39,10 +35,7 @@ % % Convert #1 from radians to degrees. % -\def\pgfmathdeg#1{% - \pgfmathparse{#1}% - \pgfmathdeg@{\pgfmathresult}} -\def\pgfmathdeg@#1{% +\pgfmathdeclarefunction{deg}{1}{% \begingroup% \expandafter\pgfmath@x#1pt\relax% \pgfmath@x57.29577\pgfmath@x\relax% 57.29577 = 360/(2*pi) @@ -54,10 +47,7 @@ % % Convert #1 from degrees to radians. % -\def\pgfmathrad#1{% - \pgfmathparse{#1}% - \pgfmathrad@{\pgfmathresult}} -\def\pgfmathrad@#1{% +\pgfmathdeclarefunction{rad}{1}{% \begingroup% \expandafter\pgfmath@x#1pt\relax% \pgfmath@x3.14159\pgfmath@x% @@ -70,10 +60,7 @@ % % Calculate the sine of #1 (in degrees). % -\def\pgfmathsin#1{% - \pgfmathparse{#1}% - \pgfmathsin@{\pgfmathresult}} -\def\pgfmathsin@#1{% +\pgfmathdeclarefunction{sin}{1}{% % Let #1 = a.b % Then sin(#1) \approx (1-b)*sin(a) + b*sin(a+1) % @@ -114,10 +101,7 @@ % % Calculate the cosine of #1 (in degrees). % -\def\pgfmathcos#1{% - \pgfmathparse{#1}% - \expandafter\pgfmathcos@\expandafter{\pgfmathresult}} -\def\pgfmathcos@#1{% +\pgfmathdeclarefunction{cos}{1}{% % Let x = a.b % Then cos(x) \approx (1-b)*cos(a) + b*cos(a+1) % @@ -171,10 +155,7 @@ % % Calculate the tangent of #1 (in degrees). % -\def\pgfmathtan#1{% - \pgfmathparse{#1}% - \pgfmathtan@{\pgfmathresult}} -\def\pgfmathtan@#1{% +\pgfmathdeclarefunction{tan}{1}{% \begingroup% \edef\pgfmath@temparg{#1}% \pgfmathcos@{\pgfmath@temparg}% @@ -183,19 +164,6 @@ \pgfmathsin@{\pgfmath@temparg}% \pgfmath@x\pgfmathresult pt\relax% \pgfmath@x\pgfmath@tantemp\pgfmath@x% - \ifdim\pgfmath@x<0pt\relax% - \c@pgfmath@countb-1\relax% - \else% - \c@pgfmath@countb1\relax% - \fi% - % Adjust to 4 decimal places. This gets rid of some annoyingly tiny errors. - \afterassignment\pgfmath@x% - \expandafter\c@pgfmath@counta\the\pgfmath@x\relax% - \ifdim\pgfmath@x<.0001pt\relax% - \pgfmath@x0pt\relax% - \fi% - \advance\pgfmath@x\c@pgfmath@counta pt% - \multiply\pgfmath@x\c@pgfmath@countb% \pgfmath@returnone\pgfmath@x% \endgroup% } @@ -204,10 +172,7 @@ % % Calculate the cosec of #1 (in degrees). % -\def\pgfmathcosec#1{% - \pgfmathparse{#1}% - \pgfmathcosec@{\pgfmathresult}} -\def\pgfmathcosec@#1{% +\pgfmathdeclarefunction{cosec}{1}{% \expandafter\pgfmathsin@\expandafter{#1}% \pgfmathreciprocal@{\pgfmathresult}% } @@ -216,10 +181,7 @@ % % Calculate the sec of #1 (in degrees). % -\def\pgfmathsec#1{% - \pgfmathparse{#1}% - \pgfmathsec@{\pgfmathresult}} -\def\pgfmathsec@#1{% +\pgfmathdeclarefunction{sec}{1}{% \expandafter\pgfmathcos@\expandafter{#1}% \pgfmathreciprocal@{\pgfmathresult}% } @@ -228,10 +190,7 @@ % % Calculate the cotangent of #1 (in degrees). % -\def\pgfmathcot#1{% - \pgfmathparse{#1}% - \pgfmathcot@{\pgfmathresult}} -\def\pgfmathcot@#1{% +\pgfmathdeclarefunction{cot}{1}{% \begingroup% \edef\pgfmath@temparg{#1}% \pgfmathsin@{\pgfmath@temparg}% @@ -240,19 +199,6 @@ \pgfmathcos@{\pgfmath@temparg}% \pgfmath@x\pgfmathresult pt\relax% \pgfmath@x\pgfmath@tantemp\pgfmath@x% - \ifdim\pgfmath@x<0pt\relax% - \c@pgfmath@countb-1\relax% - \else% - \c@pgfmath@countb1\relax% - \fi% - % Adjust to 4 decimal places. This gets rid of some annoyingly tiny errors. - \afterassignment\pgfmath@x% - \expandafter\c@pgfmath@counta\the\pgfmath@x\relax% - \ifdim\pgfmath@x<.0001pt\relax% - \pgfmath@x0pt\relax% - \fi% - \advance\pgfmath@x\c@pgfmath@counta pt% - \multiply\pgfmath@x\c@pgfmath@countb% \pgfmath@returnone\pgfmath@x% \endgroup% } @@ -261,10 +207,7 @@ % % The asin of #1 % -\def\pgfmathasin#1{% - \pgfmathparse{#1}% - \expandafter\pgfmathasin@\expandafter{\pgfmathresult}} -\def\pgfmathasin@#1{% +\pgfmathdeclarefunction{asin}{1}{% \begingroup% \expandafter\pgfmath@x#1pt\relax% \pgfmath@xa\pgfmath@x% @@ -287,10 +230,7 @@ % % The acos of #1 % -\def\pgfmathacos#1{% - \pgfmathparse{#1}% - \expandafter\pgfmathacos@\expandafter{\pgfmathresult}} -\def\pgfmathacos@#1{% +\pgfmathdeclarefunction{acos}{1}{% \begingroup% \expandafter\pgfmath@x#1pt\relax% \pgfmath@xa\pgfmath@x% @@ -303,19 +243,13 @@ \expandafter\pgfmath@x\csname pgfmath@acos@\the\c@pgfmath@counta\endcsname pt\relax% \ifdim\pgfmath@xa<0pt\relax% \pgfmath@x-\pgfmath@x% + \advance\pgfmath@x by180pt\relax% \fi% \pgfmath@returnone\pgfmath@x% \endgroup% } -% \pgfmathasin -% -% The atan of #1 -% -\def\pgfmathatan#1{% - \pgfmathparse{#1}% - \expandafter\pgfmathatan@\expandafter{\pgfmathresult}} -\def\pgfmathatan@#1{% +\pgfmathdeclarefunction{atan}{1}{% \begingroup% \expandafter\pgfmath@x#1pt\relax% \pgfmath@xa\pgfmath@x% @@ -344,7 +278,40 @@ \endgroup% } - +\pgfmathdeclarefunction{atan2}{2}{% + \begingroup% + \pgfmath@x=#1pt\relax% + \ifdim\pgfmath@x<0pt\relax% + \pgfmath@x=-\pgfmath@x% + \fi% + \ifdim\pgfmath@x<0.001pt\relax% + \ifdim#2pt<0pt\relax% + \pgfmath@x=-90pt\relax% + \else% + \ifdim#2pt>0pt\relax% + \pgfmath@x=90pt\relax% + \else% + \pgfmath@x=0pt\relax% + \fi% + \fi% + \else% + \pgfmathdivide@{#2}{#1}% + \expandafter\pgfmathatan@\expandafter{\pgfmathresult}% + \pgfmath@x=\pgfmathresult pt\relax% + \ifdim#2pt<0pt\relax% + \ifdim#1pt<0pt\relax% + \advance\pgfmath@x by-180pt\relax% + \fi% + \else% + \ifdim#1pt<0pt\relax% + \advance\pgfmath@x by180pt\relax% + \fi% + \fi% + \fi% + \pgfmath@returnone\pgfmath@x% + \endgroup% +} + \def\pgfmath@def#1#2#3{\expandafter\def\csname pgfmath@#1@#2\endcsname{#3}} \pgfmath@def{cos}{0}{1.00000} \pgfmath@def{cos}{1}{0.99985} \pgfmath@def{cos}{2}{0.99939} \pgfmath@def{cos}{3}{0.99863} diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathoperations.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathoperations.code.tex deleted file mode 100644 index 452b9fa0b2c..00000000000 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathoperations.code.tex +++ /dev/null @@ -1,1488 +0,0 @@ -% Copyright 2007 by Mark Wibrow -% -% This file may be distributed and/or modified -% -% 1. under the LaTeX Project Public License and/or -% 2. under the GNU Public License. -% -% See the file doc/generic/pgf/licenses/LICENSE for more details. - -% This file defines the mathematical functions and operators. -% -% Version 1.414213 29/9/2007 - -% This file defines the mathematical functions and operators. -% -% Adding/redefining extra operators/functions: -% -% Each operator/function XXX has two forms: -% -% -% \pgfmathXXX#1... a public version which evaluates any -% arguments passed to it and passes the -% results on to... -% -% \pgfmathXXX@#1... a non-public version which performs -% required calculation on arguments which -% must have already been evaluated (i.e. -% *without* dimensions). -% -% If a function XXX is to be included in the parser, it is -% recommended, for consistency, that where possible, the -% pgfmathparser file should define the macro \pgfmath@parseXXX. -% The parser should (ideally) then call \pgfmathXXX@. -% -% It is also recommened that all calculations (where necessary) -% take place within a TeX group. \pgfmath@returnone#1 makes and -% expanded version of #1 global and stores this in \pgfmathresult -% after the group is ended. -% - -\input pgfmathtrig.code.tex% Load the trig. stuff. -\input pgfmathrnd.code.tex% Load the random stuff. - - -% \pgfmathadd -% -% Add #1 and #2. -% -\def\pgfmathadd#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathadd@{\pgfmathresult}{\pgfmath@arg}} -\def\pgfmathadd@#1#2{% - \begingroup% - \pgfmath@x#1pt% - \pgfmath@y#2pt% - \advance\pgfmath@x by\pgfmath@y% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathsubtract -% -% Subtract #2 from #1. -% -\def\pgfmathsubtract#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathsubtract@{\pgfmathresult}{\pgfmath@arg}} -\def\pgfmathsubtract@#1#2{% - \begingroup% - \pgfmath@x#1pt% - \pgfmath@y#2pt% - \advance\pgfmath@x-\pgfmath@y% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathmultiply -% -% Multiply #1 by #2. -% -\def\pgfmathmultiply#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathmultiply@{\pgfmathresult}{\pgfmath@arg}} -\def\pgfmathmultiply@#1#2{% - \begingroup% - \pgfmath@x#1pt% - \pgfmath@y#2pt% - \pgfmath@x\pgfmath@tonumber{\pgfmath@y}\pgfmath@x% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathdivide -% -% Divide #1 by #2. -% -\def\pgfmathdivide#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathdivide@{\pgfmathresult}{\pgfmath@arg}} -\def\pgfmathdivide@#1#2{% - \begingroup% - \pgfmath@x#1pt% - \pgfmath@y#2pt% - \def\pgfmath@sign{}% - \ifdim\pgfmath@y=0pt\relax% - \pgfmath@error{You've asked me to divide `#1' by `#2', % - but I cannot divide any number by `#2'}% - \fi% - \afterassignment\pgfmath@xa% - \expandafter\c@pgfmath@counta\the\pgfmath@y\relax% - % - % If y is an integer, use TeX arithmatic. - % - \ifdim\pgfmath@xa=0pt\relax% - \divide\pgfmath@x\c@pgfmath@counta\relax% - \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% - \let\pgfmath@next\pgfmathdivide@@@% - \else% - % - % Simple long division. - % - \ifdim\pgfmath@x<0pt\relax% - \def\pgfmath@sign{-}% - \pgfmath@x-\pgfmath@x% - \fi% - \ifdim\pgfmath@y<0pt\relax% - \edef\pgfmath@sign{\pgfmath@sign-}% - \pgfmath@y-\pgfmath@y% - \fi% - \pgfmath@ya\pgfmath@y% - \c@pgfmath@counta0\relax% - \ifdim\pgfmath@x>\pgfmath@ya% - \ifdim\pgfmath@ya<1638.4pt\relax% - \pgfmathmultiply@dimenbyten\pgfmath@ya% - \ifdim\pgfmath@ya>\pgfmath@x% - \pgfmathdivide@dimenbyten\pgfmath@ya% - \c@pgfmath@counta0\relax% - \else% - \ifdim\pgfmath@ya<1638.4pt\relax% - \pgfmathmultiply@dimenbyten\pgfmath@ya% - \ifdim\pgfmath@ya>\pgfmath@x% - \pgfmathdivide@dimenbyten\pgfmath@ya% - \c@pgfmath@counta1\relax% - \else% - \ifdim\pgfmath@ya<1638.4pt\relax% - \pgfmathmultiply@dimenbyten\pgfmath@ya% - \ifdim\pgfmath@ya>\pgfmath@x% - \pgfmathdivide@dimenbyten\pgfmath@ya% - \c@pgfmath@counta2\relax% - \else% - \ifdim\pgfmath@ya<1638.4pt\relax% - \pgfmathmultiply@dimenbyten\pgfmath@ya% - \ifdim\pgfmath@ya>\pgfmath@x% - \pgfmathdivide@dimenbyten\pgfmath@ya% - \c@pgfmath@counta3\relax% - \else% - \pgfmath@error{The result of `#1/#2' is too big for me}{}% - \fi% - \fi% - \fi% - \fi% - \fi% - \fi% - \fi% - \fi% - \fi% - % - % If y < 1pt use reciprocal operation. - % - \ifdim\pgfmath@y<1pt\relax% - \ifdim\pgfmath@y<.00007pt\relax% - \pgfmath@error{The result of `#1/#2' is too big for me}{}% - \fi% - \pgfmathreciprocal@{\pgfmath@tonumber{\pgfmath@y}}% - \pgfmath@x\pgfmathresult\pgfmath@x% - \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% - \let\pgfmath@next\pgfmathdivide@@@% - \else% - \pgfmath@y\pgfmath@ya% - \def\pgfmathresult{}% - \let\pgfmath@next\pgfmathdivide@@% - \fi% - \fi% - \pgfmath@next% -} - -\def\pgfmathdivide@dimenbyten#1{% - \edef\pgfmath@temp{\pgfmath@tonumber{#1}}% - \expandafter\pgfmathdivide@@dimenbyten\pgfmath@temp\@@#1\@@} -\def\pgfmathdivide@@dimenbyten#1.#2\@@#3\@@{% - \pgfmath@tempcnta#1\relax% - \divide\pgfmath@tempcnta10\relax% - \pgfmath@tempcntb\pgfmath@tempcnta% - \multiply\pgfmath@tempcnta-10\relax% - \advance\pgfmath@tempcnta#1\relax% - #3\the\pgfmath@tempcntb.\the\pgfmath@tempcnta#2pt\relax% -} - -\def\pgfmathmultiply@dimenbyten#1{% - \edef\pgfmath@temp{\pgfmath@tonumber{#1}}% - \expandafter\pgfmathmultiply@@dimenbyten\pgfmath@temp\@@#1\@@} -\def\pgfmathmultiply@@dimenbyten#1.#2#3\@@#4\@@{#4#1#2.#3pt\relax} - -\def\pgfmathdivide@@{% - \ifdim\pgfmath@x>\pgfmath@y% - \pgfmath@yb6.0\pgfmath@y% - \ifdim\pgfmath@yb>\pgfmath@x% 6*y - \advance\pgfmath@yb-\pgfmath@y% - \advance\pgfmath@yb-\pgfmath@y% - \ifdim\pgfmath@yb>\pgfmath@x% 4*y - \advance\pgfmath@yb-\pgfmath@y% - \advance\pgfmath@yb-\pgfmath@y% - \ifdim\pgfmath@yb>\pgfmath@x% 2*y - \advance\pgfmath@yb-\pgfmath@y% - \ifdim\pgfmath@yb>\pgfmath@x% 1*y - \c@pgfmath@countb0\relax% - \else% - \c@pgfmath@countb1\relax% - \fi% - \else% - \advance\pgfmath@yb\pgfmath@y% 3*y - \ifdim\pgfmath@yb>\pgfmath@x% - \c@pgfmath@countb2\relax% - \else% - \c@pgfmath@countb3\relax% - \fi% - \fi% - \else% - \advance\pgfmath@yb\pgfmath@y% 5*y - \ifdim\pgfmath@yb>\pgfmath@x% - \c@pgfmath@countb4\relax% - \else% - \c@pgfmath@countb5\relax% - \fi% - \fi% - \else% - \advance\pgfmath@yb\pgfmath@y% - \advance\pgfmath@yb\pgfmath@y% - \ifdim\pgfmath@yb>\pgfmath@x% 8*y - \advance\pgfmath@yb-\pgfmath@y% - \ifdim\pgfmath@yb>\pgfmath@x% 7*y - \c@pgfmath@countb6\relax% - \else% - \c@pgfmath@countb7\relax% - \fi% - \else% - \advance\pgfmath@yb\pgfmath@y% - \ifdim\pgfmath@yb>\pgfmath@x% 9*y - \c@pgfmath@countb8\relax% - \else% - \c@pgfmath@countb9\relax% - \fi% - \fi% - \fi% - \else% - \c@pgfmath@countb=0\relax% - \fi% - \ifnum\c@pgfmath@countb=0\relax% - \edef\pgfmathresult{\pgfmathresult0}% - \else% - \pgfmath@yb\c@pgfmath@countb\pgfmath@y% - \advance\pgfmath@x-\pgfmath@yb% - \edef\pgfmathresult{\pgfmathresult\the\c@pgfmath@countb}% - \fi% - \pgfmathdivide@dimenbyten\pgfmath@y% - \ifnum\c@pgfmath@counta=0\relax% - \edef\pgfmathresult{\pgfmathresult.}% - \fi% - \advance\c@pgfmath@counta-1\relax% - \ifdim\pgfmath@y=0pt\relax% - \let\pgfmath@next\pgfmathdivide@@@% - \else% - \let\pgfmath@next\pgfmathdivide@@% - \fi% - \pgfmath@next% -} - -\def\pgfmathdivide@@@{% - \pgfmath@x\pgfmath@sign\pgfmathresult pt\relax% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - - -% \pgfmathgreaterthan -% -% 1.0 if #1 > #2. Otherwise 0.0 -% -\def\pgfmathgreaterthan#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathgreaterthan@{\pgfmathresult}{\pgfmath@arg}} -\def\pgfmathgreaterthan@#1#2{% - \begingroup% - \pgfmath@x#1pt% - \pgfmath@y#2pt% - \advance\pgfmath@x-\pgfmath@y% - \ifdim\pgfmath@x>0pt\relax% - \pgfmath@x1pt\relax% - \else% - \pgfmath@x0pt\relax% - \fi% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathlessthan -% -% 1.0 if #1< #2. Otherwise 0.0 -% -\def\pgfmathlessthan#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathlessthan@{\pgfmathresult}{\pgfmath@arg}} -\def\pgfmathlessthan@#1#2{% - \begingroup% - \pgfmath@x#1pt% - \pgfmath@y#2pt% - \advance\pgfmath@x-\pgfmath@y\relax% - \ifdim\pgfmath@x<0pt\relax% - \pgfmath@x1pt\relax% - \else% - \pgfmath@x0pt\relax% - \fi% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathequalto -% -% 1.0 if #1 = #2. Otherwise 0.0 -% -\def\pgfmathequalto#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathequalto@{\pgfmathresult}{\pgfmath@arg}} -\def\pgfmathequalto@#1#2{% - \begingroup% - \pgfmath@x#1pt% - \pgfmath@y#2pt% - \advance\pgfmath@x-\pgfmath@y% - \ifdim\pgfmath@x=0pt\relax% - \pgfmath@x1pt\relax% - \else% - \pgfmath@x0pt\relax% - \fi% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathreciprocal -% -% 1 / #1 -% -\def\pgfmathreciprocal#1{% - \pgfmathparse{#1}% - \pgfmathreciprocal@{\pgfmathresult}} -\def\pgfmathreciprocal@#1{% - \begingroup% - \expandafter\pgfmath@x#1pt\relax% - \ifdim\pgfmath@x=0pt\relax% - \pgfmath@error{You asked me to calculate `1/#1', but I cannot divide any number by zero}{}% - \fi% - \edef\pgfmath@reciprocaltemp{\pgfmath@tonumber{\pgfmath@x}}% - \expandafter\pgfmathreciprocal@@\pgfmath@reciprocaltemp0000000\pgfmath@} -\def\pgfmathreciprocal@@#1.#2#3#4#5#6#7\pgfmath@{% - \c@pgfmath@counta#2#3#4#5#6\relax% - % If the number is an integer, use TeX arithmatic. - \ifnum\c@pgfmath@counta=0\relax% - \pgfmath@x1pt\relax% - \divide\pgfmath@x#1\relax% - \else% - \ifnum#1>100\relax% - \c@pgfmath@counta#1#2#3#4\relax% - \c@pgfmath@countb1000000000\relax% - \divide\c@pgfmath@countb\c@pgfmath@counta% - \c@pgfmath@counta\c@pgfmath@countb% - \divide\c@pgfmath@counta10000\relax% - \pgfmath@x\c@pgfmath@counta pt\relax% - \multiply\c@pgfmath@counta-10000\relax% - \advance\c@pgfmath@countb\c@pgfmath@counta% - \pgfmath@y\c@pgfmath@countb pt\relax% - \divide\pgfmath@y1000000\relax% - \advance\pgfmath@x\pgfmath@y% - \else% - \c@pgfmath@counta#1#2#3#4#5#6\relax% - \c@pgfmath@countb1000000000\relax% - \divide\c@pgfmath@countb\c@pgfmath@counta% - \c@pgfmath@counta\c@pgfmath@countb% - \divide\c@pgfmath@counta10000\relax% - \pgfmath@x\c@pgfmath@counta pt\relax% - \multiply\c@pgfmath@counta-10000\relax% - \advance\c@pgfmath@countb\c@pgfmath@counta% - \pgfmath@y\c@pgfmath@countb pt\relax% - \pgfmath@y.1\pgfmath@y% Yes! This way is more accurate. Go figure... - \pgfmath@y.1\pgfmath@y% - \pgfmath@y.1\pgfmath@y% - \pgfmath@y.1\pgfmath@y% - \advance\pgfmath@x\pgfmath@y% - \fi% - \fi% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathln -% -% Calculate ln(#1} -% -% This is based on an algorithm due to Rouben Rostamian and -% uses coefficients contributed by Alain Matthes. -% -\def\pgfmathln#1{\pgfmathparse{#1}\pgfmathln@{\pgfmathresult}} -\def\pgfmathln@#1{% - \begingroup% - \expandafter\pgfmath@x#1pt\relax% - \ifdim\pgfmath@x>0pt\else% - \pgfmath@error{I cannot calculate the logarithm of `#1'}{}% - \fi% - \c@pgfmath@counta0\relax% - \ifdim\pgfmath@x>2pt\relax% - \ifdim\pgfmath@x<128pt\relax% - \ifdim\pgfmath@x<8pt\relax% - \ifdim\pgfmath@x<4pt\relax% - \divide\pgfmath@x2\relax% - \c@pgfmath@counta1\relax% - \else% - \divide\pgfmath@x4\relax% - \c@pgfmath@counta2\relax% - \fi% - \else% - \ifdim\pgfmath@x<32pt\relax% - \ifdim\pgfmath@x<16pt\relax% - \divide\pgfmath@x8\relax% - \c@pgfmath@counta3\relax% - \else% - \divide\pgfmath@x16\relax% - \c@pgfmath@counta4\relax% - \fi% - \else% - \ifdim\pgfmath@x<64pt\relax% - \divide\pgfmath@x32\relax% - \c@pgfmath@counta5\relax% - \else% - \divide\pgfmath@x64\relax% - \c@pgfmath@counta6\relax% - \fi% - \fi% - \fi% - \else% - \ifdim\pgfmath@x<2048pt\relax% - \ifdim\pgfmath@x<512pt\relax% - \ifdim\pgfmath@x<256pt\relax% - \divide\pgfmath@x128\relax% - \c@pgfmath@counta7\relax% - \else% - \divide\pgfmath@x256\relax% - \c@pgfmath@counta8\relax% - \fi% - \else% - \ifdim\pgfmath@x<1024pt\relax% - \divide\pgfmath@x512\relax% - \c@pgfmath@counta9\relax% - \else% - \divide\pgfmath@x1024\relax% - \c@pgfmath@counta10\relax% - \fi% - \fi% - \else% - \ifdim\pgfmath@x<8192pt\relax% - \ifdim\pgfmath@x<4096pt\relax% - \divide\pgfmath@x2048\relax% - \c@pgfmath@counta11\relax% - \else% - \divide\pgfmath@x4096\relax% - \c@pgfmath@counta12\relax% - \fi% - \else% - \divide\pgfmath@x8192\relax% - \c@pgfmath@counta13\relax% - \fi% - \fi% - \fi% - \else% - \ifdim\pgfmath@x<1pt\relax% - \ifdim\pgfmath@x>0.0078125pt\relax% 2^-7 - \ifdim\pgfmath@x>0.125pt\relax% 2^-3 - \ifdim\pgfmath@x>0.5pt\relax% 2^-1 - \multiply\pgfmath@x2\relax% - \c@pgfmath@counta-1\relax% - \else% - \multiply\pgfmath@x4\relax% - \c@pgfmath@counta-2\relax% - \fi% - \else% - \ifdim\pgfmath@x>0.03125pt\relax% 2^-5 - \ifdim\pgfmath@x>0.0625pt\relax% - \multiply\pgfmath@x8\relax% - \c@pgfmath@counta-3\relax% - \else% - \multiply\pgfmath@x16\relax% - \c@pgfmath@counta-4\relax% - \fi% - \else% - \ifdim\pgfmath@x>0.015625pt\relax% 2^-6 - \multiply\pgfmath@x32\relax% - \c@pgfmath@counta-5\relax% - \else% - \multiply\pgfmath@x64\relax% - \c@pgfmath@counta-6\relax% - \fi% - \fi% - \fi% - \else% - \ifdim\pgfmath@x>0.000244140625pt\relax% 2^-11 - \ifdim\pgfmath@x>0.001953125pt\relax% 2^-9 - \ifdim\pgfmath@x>0.00390625pt\relax% 2^-8 - \multiply\pgfmath@x128\relax% - \c@pgfmath@counta-7\relax% - \else% - \multiply\pgfmath@x256\relax% - \c@pgfmath@counta-8\relax% - \fi% - \else% - \ifdim\pgfmath@x>0.0009765625pt\relax% 2^-10 - \multiply\pgfmath@x512\relax% - \c@pgfmath@counta-9\relax% - \else% - \multiply\pgfmath@x1024\relax% - \c@pgfmath@counta-10\relax% - \fi% - \fi% - \else% - \ifdim\pgfmath@x>0.0001220703125pt\relax% 2^13 - \ifdim\pgfmath@x>0.0002441406256pt\relax% 2^12 - \multiply\pgfmath@x2048\relax% - \c@pgfmath@counta-11\relax% - \else% - \multiply\pgfmath@x4096\relax% - \c@pgfmath@counta-12\relax% - \fi% - \else% - \multiply\pgfmath@x8192\relax% - \c@pgfmath@counta-13\relax% - \fi% - \fi% - \fi% - \fi% - \fi% - % - % Use A+(B+(C+(D+(E+F*x)*x)*x)*x)*x - % - % where: - % A = -2.787927935 - % B = 5.047861502 - % C = -3.489886985 - % D = 1.589480044 - % E = -.4025153233 - % F = 0.04300521312 - % - \edef\pgfmath@temp{\pgfmath@tonumber{\pgfmath@x}}% - \pgfmath@x0.04300521312\pgfmath@x% - \advance\pgfmath@x-.4025153233pt\relax% - \pgfmath@x\pgfmath@temp\pgfmath@x% - \advance\pgfmath@x1.589480044pt\relax% - \pgfmath@x\pgfmath@temp\pgfmath@x% - \advance\pgfmath@x-3.489886985pt\relax% - \pgfmath@x\pgfmath@temp\pgfmath@x% - \advance\pgfmath@x5.047861502pt\relax% - \pgfmath@x\pgfmath@temp\pgfmath@x% - \advance\pgfmath@x-2.787927935pt\relax% - \advance\pgfmath@x\c@pgfmath@counta pt\relax% - \pgfmath@x0.6931471806\pgfmath@x% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathabs -% -% Calculate |#1| -% -\def\pgfmathabs#1{% - \pgfmathparse{#1}% - \pgfmathabsolute@{\pgfmathresult}} -\def\pgfmathabs@#1{% - \begingroup% - \expandafter\pgfmath@x#1pt\relax% - \ifdim\pgfmath@x<0pt\relax% - \pgfmath@x-\pgfmath@x% - \fi% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathmod -% -% Calculate #1 mod #2. -% -\def\pgfmathmod#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathmod@{\pgfmathresult}{\pgfmath@arg}% -} -\def\pgfmathmod@#1#2{% - \begingroup% - \pgfmath@xa#1pt% - \pgfmath@xb#2pt% - \pgfmath@x\pgfmath@xa% - \c@pgfmath@counta\pgfmath@xa% - \c@pgfmath@countb\pgfmath@xb% - \divide\c@pgfmath@counta\c@pgfmath@countb% - \multiply\pgfmath@xb\c@pgfmath@counta% - \advance\pgfmath@x-\pgfmath@xb% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathsqrt -% -% Square-root of #1. -% -% -\def\pgfmathsqrt#1{\pgfmathparse{#1}\pgfmathsqrt@{\pgfmathresult}} -\def\pgfmathsqrt@#1{% - \begingroup% - \expandafter\pgfmath@x#1pt\relax% - \ifdim\pgfmath@x<0pt\relax% - \pgfmath@error{I cannot calculate the square-root of the negative number `#1'}{}% - \else% - \ifdim\pgfmath@x<10pt\relax% - \def\pgfmath@zeros{0}% - \def\pgfmath@targetiterations{1}% - \else% - \ifdim\pgfmath@x<100pt\relax% - \def\pgfmath@zeros{}% - \def\pgfmath@targetiterations{1}% - \else% - \ifdim\pgfmath@x<1000pt\relax% - \def\pgfmath@zeros{0}% - \def\pgfmath@targetiterations{2}% - \else% - \ifdim\pgfmath@x<10000pt\relax% - \def\pgfmath@zeros{}% - \def\pgfmath@targetiterations{2}% - \else% - \def\pgfmath@zeros{0}% - \def\pgfmath@targetiterations{3}% - \fi\fi\fi\fi\fi% - \edef\pgfmath@temp{\pgfmath@zeros\pgfmath@tonumber{\pgfmath@x}}% - \expandafter\pgfmath@sqrt@\pgfmath@temp\pgfmath@% -} -\def\pgfmath@sqrt@#1.#2\pgfmath@{\pgfmath@@sqrt@#1#2\pgfmath@empty\pgfmath@empty\pgfmath@} - -\def\pgfmath@@sqrt@#1#2{% - \c@pgfmath@countb#1#2\relax% - \ifnum\c@pgfmath@countb>35\relax% - \ifnum\c@pgfmath@countb>63\relax% - \ifnum\c@pgfmath@countb>80\relax% - \c@pgfmath@counta9\relax% - \else% - \c@pgfmath@counta8\relax% - \fi% - \else% - \ifnum\c@pgfmath@countb>48\relax% - \c@pgfmath@counta7\relax% - \else% - \c@pgfmath@counta6\relax% - \fi% - \fi% - \else% - \ifnum\c@pgfmath@countb>15\relax% - \ifnum\c@pgfmath@countb>24\relax% - \c@pgfmath@counta5\relax% - \else% - \c@pgfmath@counta4\relax% - \fi% - \else% - \ifnum\c@pgfmath@countb>3\relax% - \ifnum\c@pgfmath@countb>8\relax% - \c@pgfmath@counta3\relax% - \else% - \c@pgfmath@counta2\relax% - \fi% - \else% - \ifnum\c@pgfmath@countb>0\relax% - \c@pgfmath@counta1\relax% - \else% - \c@pgfmath@counta0\relax% - \fi% - \fi% - \fi% - \fi% - \edef\pgfmath@root{\the\c@pgfmath@counta}% - \edef\pgfmath@rootspecial{\the\c@pgfmath@counta}% - \multiply\c@pgfmath@counta-\c@pgfmath@counta\relax% - \advance\c@pgfmath@counta#1#2\relax% - \edef\pgfmath@remainder{\the\c@pgfmath@counta}% - \pgfmath@@@sqrt@% -} - -\def\pgfmath@@@sqrt@#1#2{% - \ifx\pgfmath@empty#1% - \edef\pgfmath@remainder{\pgfmath@remainder00}% - \def\pgfmath@tokens{\pgfmath@empty\pgfmath@empty}% - \else% - \ifx\pgfmath@empty#2% - \edef\pgfmath@remainder{\pgfmath@remainder#10}% - \def\pgfmath@tokens{\pgfmath@empty\pgfmath@empty}% - \else% - \edef\pgfmath@remainder{\pgfmath@remainder#1#2}% - \def\pgfmath@tokens{}% - \fi\fi% - \c@pgfmath@counta\pgfmath@rootspecial\relax% - \multiply\c@pgfmath@counta20\relax% - \c@pgfmath@countb\c@pgfmath@counta% - \multiply\c@pgfmath@countb6\relax% - \advance\c@pgfmath@countb36\relax% - \c@pgfmath@countc\c@pgfmath@counta\relax% - \multiply\c@pgfmath@countc2\relax% - \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% - \advance\c@pgfmath@countb-\c@pgfmath@countc% - \advance\c@pgfmath@countb-20\relax% - \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% - \advance\c@pgfmath@countb-\c@pgfmath@countc% - \advance\c@pgfmath@countb-12\relax% - \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% - \advance\c@pgfmath@countb-\c@pgfmath@counta% - \advance\c@pgfmath@countb-3\relax% - \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% - \def\pgfmath@digit{0}% - \else% - \def\pgfmath@digit{1}% - \fi% - \else% - \advance\c@pgfmath@countb\c@pgfmath@counta% - \advance\c@pgfmath@countb5\relax% - \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% - \def\pgfmath@digit{2}% - \else% - \def\pgfmath@digit{3}% - \fi% - \fi% - \else% - \advance\c@pgfmath@countb\c@pgfmath@counta% - \advance\c@pgfmath@countb9\relax% - \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% - \def\pgfmath@digit{4}% - \else% - \def\pgfmath@digit{5}% - \fi% - \fi% - \else% - \advance\c@pgfmath@countb\c@pgfmath@countc% - \advance\c@pgfmath@countb28\relax% - \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% - \advance\c@pgfmath@countb-\c@pgfmath@counta% - \advance\c@pgfmath@countb-15\relax% - \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% - \def\pgfmath@digit{6}% - \else% - \def\pgfmath@digit{7}% - \fi% - \else% - \advance\c@pgfmath@countb\c@pgfmath@counta% - \advance\c@pgfmath@countb17\relax% - \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax% - \def\pgfmath@digit{8}% - \else% - \def\pgfmath@digit{9}% - \fi% - \fi% - \fi% - \edef\pgfmath@rootspecial{\pgfmath@rootspecial\pgfmath@digit}% - \advance\c@pgfmath@counta\pgfmath@digit\relax% - \multiply\c@pgfmath@counta-\pgfmath@digit\relax% - \advance\c@pgfmath@counta\pgfmath@remainder\relax% - \edef\pgfmath@remainder{\the\c@pgfmath@counta}% - \c@pgfmath@counta\pgfmath@targetiterations\relax% - \advance\c@pgfmath@counta-1\relax% - \edef\pgfmath@targetiterations{\the\c@pgfmath@counta}% - \ifnum\c@pgfmath@counta=0\relax% - \edef\pgfmath@root{\pgfmath@root.\pgfmath@digit}% - \else% - \edef\pgfmath@root{\pgfmath@root\pgfmath@digit}% - \fi% - \ifnum\c@pgfmath@counta=-4\relax% -n+1 digits of precision. - \let\pgfmath@next\pgfmath@sqrt@end% - \else% - \let\pgfmath@next\pgfmath@@@sqrt@% - \fi% - \expandafter\pgfmath@next\pgfmath@tokens% -} - -\def\pgfmath@sqrt@end#1\pgfmath@{% - \edef\pgfmathresult{\pgfmath@root}% - \pgfmath@smuggleone\pgfmathresult% - \endgroup} - -% \pgfmathpow -% -% Calculates #1 ^ #2 -% -\def\pgfmathpow#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathpow@{\pgfmathresult}{\pgfmath@arg}} -\def\pgfmathpow@#1#2{% - \begingroup% - \pgfmath@xa#1pt% - \pgfmath@xb#2pt% - \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@x1pt\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@counta2\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% - \pgfmath@returnone\pgf@x% - \endgroup% -} - -% \pgfmathround -% -% Asymmetric Half-up rounding. -% -\def\pgfmathround#1{\pgfmathparse{#1}\pgfmathround@{\pgfmathresult}} -\def\pgfmathround@#1{% - \begingroup% - \expandafter\pgfmath@x#1pt\relax% - \afterassignment\pgfmath@xa% - \expandafter\c@pgfmath@counta\the\pgfmath@x\relax% - \pgfmath@xb\pgfmath@x% - \ifdim\pgfmath@xb<0pt\relax% - \ifdim\pgfmath@xa<0.5pt\relax% - \else% - \advance\c@pgfmath@counta-1\relax% - \fi% - \else% - \ifdim\pgfmath@xa<0.5pt\relax% - \else% - \advance\c@pgfmath@counta1\relax% - \fi% - \fi% - \pgfmath@returnone\the\c@pgfmath@counta pt% - \endgroup% -}% - -% \pgfmathfloor -% -% Floor function. -% -\def\pgfmathfloor#1{\pgfmathparse{#1}\pgfmathfloor@{\pgfmathresult}} -\def\pgfmathfloor@#1{% - \begingroup% - \expandafter\pgfmath@x#1pt\relax% - \afterassignment\pgfmath@gobbletilpgfmath@% - \expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@% - \pgfmath@x\c@pgfmath@counta pt\relax% - \pgfmath@returnone\pgfmath@x% - \endgroup% -}% - -% \pgfmathceil -% -% Ceiling function. -% -\def\pgfmathceil#1{\pgfmathparse{#1}\pgfmathceil@{\pgfmathresult}} -\def\pgfmathceil@#1{% - \begingroup% - \expandafter\pgfmath@x#1pt\relax% - \afterassignment\pgfmath@gobbletilpgfmath@% - \expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@% - \pgfmath@y\pgfmath@x% - \advance\pgfmath@y-\c@pgfmath@counta pt\relax% - \pgfmath@x\c@pgfmath@counta pt\relax% - \ifdim\pgfmath@y>0pt\relax% - \advance\pgfmath@x1pt\relax% - \fi% - \pgfmath@returnone\pgfmath@x% - \endgroup% -}% - -% \pgfmathexp -% -% A Maclaurens expansion for e^#1. -% 0 <= #1 < ln(16384). -% -\def\pgfmathexp#1{\pgfmathparse{#1}\pgfmathexp@{\pgfmathresult}} -\def\pgfmathexp@#1{% - \begingroup% - \edef\pgfmath@arg{#1}% - \pgfmath@x1pt\relax% - \pgfmath@xa1pt\relax% - \pgfmath@xb\pgfmath@x% - \pgfmathloop% - \pgfmath@xc\pgfmathcounter pt\relax% - \c@pgfmath@counta\pgfmath@xc% - \divide\c@pgfmath@counta65536\relax% - \pgfmath@xc1pt\relax% - \divide\pgfmath@xc\c@pgfmath@counta% - \pgfmath@xa\pgfmath@tonumber{\pgfmath@xc}\pgfmath@xa% - \expandafter\pgfmath@xa\pgfmath@arg\pgfmath@xa% - \advance\pgfmath@x\pgfmath@xa% - \ifdim\pgfmath@x=\pgfmath@xb% - \else% - \pgfmath@xb\pgfmath@x% - \repeatpgfmathloop% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - - - -% \pgfmathvectorlength -% -% Calcluate the Eulidean length of a 2D vector. -% -% This based on polynomial approximation co-efficents -% contributed by Rouben Rostamian. -% -% #1 - the x component of the vector. -% #2 - the y component of the vector. -% -\def\pgfmathveclen#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathveclen@{\pgfmathresult}{\pgfmath@arg}% -} -\def\pgfmathveclen@#1#2{% - \begingroup% - \pgfmath@x#1pt\relax% - \pgfmath@y#2pt\relax% - \ifdim\pgfmath@x<0pt\relax% - \pgfmath@x-\pgfmath@x% - \fi% - \ifdim\pgfmath@y<0pt\relax% - \pgfmath@y-\pgfmath@y% - \fi% - \ifdim\pgfmath@x=0pt\relax% - \pgfmath@x\pgfmath@y% - \else% - \ifdim\pgfmath@y=0pt\relax% - \else% - \ifdim\pgfmath@x>\pgfmath@y% - \pgfmath@xa\pgfmath@x% - \pgfmath@x\pgfmath@y% - \pgfmath@y\pgfmath@xa% - \fi% - % We use a scaling factor to reduce errors. - \ifdim\pgfmath@y>10000pt\relax% - \c@pgfmath@counta1500\relax% - \else% - \ifdim\pgfmath@y>1000pt\relax% - \c@pgfmath@counta150\relax% - \else% - \ifdim\pgfmath@y>100pt\relax% - \c@pgfmath@counta50\relax% - \else% - \c@pgfmath@counta1\relax% - \fi% - \fi% - \fi% - \divide\pgfmath@x\c@pgfmath@counta\relax% - \divide\pgfmath@y\c@pgfmath@counta\relax% - \pgfmathreciprocal@{\pgfmath@tonumber{\pgfmath@y}}% - \pgfmath@x\pgfmathresult\pgfmath@x% - \pgfmath@xa\pgfmath@tonumber{\pgfmath@x}\pgfmath@x% - \edef\pgfmath@temp{\pgfmath@tonumber{\pgfmath@xa}}% - % - % Use A+x^2*(B+x^2*(C+x^2*(D+E*x^2))) - % where - % A = +1.000012594 - % B = +0.4993615349 - % C = -0.1195159052 - % D = +0.04453994279 - % E = -0.01019210944 - % - \pgfmath@x-0.01019210944\pgfmath@xa% - \advance\pgfmath@x0.04453994279pt\relax% - \pgfmath@x\pgfmath@temp\pgfmath@x% - \advance\pgfmath@x-0.1195159052pt\relax% - \pgfmath@x\pgfmath@temp\pgfmath@x% - \advance\pgfmath@x0.4993615349pt\relax% - \pgfmath@x\pgfmath@temp\pgfmath@x% - \advance\pgfmath@x1.000012594pt\relax% - \ifdim\pgfmath@y<0pt\relax% - \pgfmath@y-\pgfmath@y% - \fi% - \pgfmath@x\pgfmath@tonumber{\pgfmath@y}\pgfmath@x% - % Invert the scaling factor. - \multiply\pgfmath@x\c@pgfmath@counta\relax% - \fi% - \fi% - \pgfmath@returnone\pgfmath@x% - \endgroup% -} - -% \pgfmathmax -% -% Return the maximum of #1 or #2 -% -\def\pgfmathmax#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathmax@{\pgfmathresult}{\pgfmath@arg}}% -\def\pgfmathmax@#1#2{% - \begingroup - \pgfmath@x#1pt% - \pgfmath@y#2pt\relax% - \ifdim\pgfmath@x>\pgfmath@y% - \pgfmath@returnone\pgfmath@x% - \else% - \pgfmath@returnone\pgfmath@y% - \fi% - \endgroup -} - -% \pgfmathmax -% -% Return the minimim of #1 or #2 -% -\def\pgfmathmin#1#2{% - \edef\pgfmath@marshal{% - \noexpand\pgfmathparse{#2} - \noexpand\let\noexpand\pgfmath@arg\noexpand\pgfmathresult% - \noexpand\pgfmathparse{#1}% - }% - \pgfmath@marshal% - \pgfmathmin@{\pgfmathresult}{\pgfmath@arg}}% -\def\pgfmathmin@#1#2{% - \begingroup - \pgfmath@x#1pt% - \pgfmath@y#2pt% - \relax% - \ifdim\pgfmath@x<\pgfmath@y% - \pgfmath@returnone\pgfmath@x% - \else% - \pgfmath@returnone\pgfmath@y% - \fi% - \endgroup% -} - -% \pgfmathscientific -% -% Return the value of #1e#2 -% -% e.g. \pgfmathscientific{1.23456789123}{4} -% -% defines \pgfmathresult as 12345.67891 -% -% NB These arguments *are not parsed*, as the long mantissa would be lost. -% -\def\pgfmathscientific#1#2{% - \begingroup% - \edef\pgfmath@sci@exponent{#2}% - \pgfmath@x#1pt\relax% - \ifdim\pgfmath@x<0pt\relax% - \pgfmath@x-\pgfmath@x% - \edef\pgfmath@sci@sign{-}% - \edef\pgfmath@temp{\pgfmath@gobbleone#1}% - \else% - \edef\pgfmath@sci@sign{+}% - \edef\pgfmath@temp{#1}% - \fi% - \expandafter\pgfmath@scientific@@\pgfmath@temp00000000000\pgfmath@} - -\def\pgfmath@scientific@@#1.#2#3#4#5#6{% - \edef\pgfmath@sci@int{#1}% - \edef\pgfmath@sci@mantissaA{#2#3#4#5#6}% - \pgfmath@scientific@@@} - -\def\pgfmath@scientific@@@#1#2#3#4#5#6\pgfmath@{% - \edef\pgfmath@sci@mantissaB{#1#2#3#4#5}% - \c@pgfmath@counta\pgfmath@sci@exponent\relax% - \c@pgfmath@countb\c@pgfmath@counta% - \ifnum\c@pgfmath@counta<0\relax% - \c@pgfmath@counta-\c@pgfmath@counta% - \fi% - \pgfmathpow@{10}{\the\c@pgfmath@counta}% - \afterassignment\pgfmath@gobbletilpgfmath@ - \c@pgfmath@countc\pgfmathresult\relax\pgfmath@ - \edef\pgfmath@sci@factor{\the\c@pgfmath@countc}% - \ifnum\c@pgfmath@countb<0\relax% - % xE-y: easy... - \pgfmath@x\pgfmath@sci@int.\pgfmath@sci@mantissaA pt\relax% - \divide\pgfmath@x\pgfmath@sci@factor\relax% - \else% - % xE+y: - % Must do this way so as not lose digits in a long mantissa. Sigh... - \c@pgfmath@counta\pgfmath@sci@int% - \c@pgfmath@countb\pgfmath@sci@mantissaA% - \multiply\c@pgfmath@counta\pgfmath@sci@factor\relax% - \multiply\c@pgfmath@countb\pgfmath@sci@factor\relax% - \c@pgfmath@countc\c@pgfmath@countb% - \divide\c@pgfmath@countb100000\relax% - \advance\c@pgfmath@counta\c@pgfmath@countb% - \multiply\c@pgfmath@countb100000\relax% - \advance\c@pgfmath@countc-\c@pgfmath@countb% - \c@pgfmath@countb\pgfmath@sci@mantissaB\relax% - \multiply\c@pgfmath@countb\pgfmath@sci@factor\relax% - \divide\c@pgfmath@countb100000\relax% - \advance\c@pgfmath@countc\c@pgfmath@countb% - \advance\c@pgfmath@countc100000\relax% - \edef\pgfmath@sci@result{\pgfmath@sci@sign\the\c@pgfmath@counta.\expandafter\pgfmath@gobbleone\the\c@pgfmath@countc pt}% - \pgfmath@x\pgfmath@sci@result\relax% - \fi% - \pgfmath@returnone\pgfmath@x% - \endgroup} - - - - - -% *** The following commands DO NOT WORK without the rest of PGF *** -% -% (a dumping ground for stuff that doesn't really belong anywhere else) - -% \pgfmathanglebetweenpoints -% -% Define \pgfmathresult as the angle between points #1 and #2 -% Should get the quadrants right as well. -% -\def\pgfmathanglebetweenpoints#1#2{% - \begingroup% - \pgf@process{\pgfpointdiff{#1}{#2}}% - % - % First approximate the angle of the external point... - % - \pgf@xa\pgf@x% - \pgf@ya\pgf@y% - \pgf@xb\pgf@x% - \pgf@yb\pgf@y% - \ifdim\pgf@xa<0pt\relax% - \pgf@xa-\pgf@xa% - \fi% - \ifdim\pgf@ya<0pt\relax% - \pgf@ya-\pgf@ya% - \fi% - \ifdim\pgf@ya>\pgf@xa% - \pgf@x\pgf@xa% - \pgf@y\pgf@ya% - \else% - \pgf@x\pgf@ya% - \pgf@y\pgf@xa% - \fi% - \ifdim\pgf@y=0pt\relax% - \pgf@x0pt% - \else% - \pgfmathreciprocal@{\pgfmath@tonumber{\pgf@y}}% - \pgf@x\pgfmathresult\pgf@x% - \fi% - \multiply\pgf@x1000\relax% - \afterassignment\pgfmath@gobbletilpgfmath@% - \expandafter\c@pgf@counta\the\pgf@x\relax\pgfmath@% - \expandafter\pgf@x\csname pgfmath@atan@\the\c@pgf@counta\endcsname pt\relax% - \ifdim\pgfmath@ya>\pgfmath@xa\relax% - \pgf@x-\pgf@x% - \advance\pgf@x90pt% - \fi% - \ifdim\pgf@xb<0pt% - \ifdim\pgf@yb>0pt% - \pgf@x-\pgf@x% - \fi% - \advance\pgf@x180pt\relax% - \else% - \ifdim\pgf@yb<0pt% - \pgf@x-\pgf@x% - \advance\pgf@x360pt\relax% - \fi\fi% - \pgfmath@returnone\pgf@x% - \endgroup% -} - -% -% \pgfmathrotatepointaround -% -% Rotate point #1 about point #2 by #3 degrees. -% -\def\pgfmathrotatepointaround#1#2#3{% - \pgf@process{% - \pgf@process{#2}% - \pgf@xa\pgf@x% - \pgf@ya\pgf@y% - \pgf@xb\pgf@x% - \pgf@yb\pgf@y% - \pgf@process{#1}% - \advance\pgf@x-\pgf@xa% - \advance\pgf@y-\pgf@ya% - \pgfmathsetmacro\angle{#3}% - \pgfmathsin@{\angle}% - \let\sineangle\pgfmathresult% - \pgfmathcos@{\angle}% - \let\cosineangle\pgfmathresult% - \pgf@xa\cosineangle\pgf@x% - \advance\pgf@xa-\sineangle\pgf@y% - \pgf@ya\sineangle\pgf@x% - \advance\pgf@ya\cosineangle\pgf@y% - \pgf@x\pgf@xb% - \pgf@y\pgf@yb% - \advance\pgf@x\pgf@xa% - \advance\pgf@y\pgf@ya% - }% -} - -% \pgfmathanglebetweenlines -% -% Calculate the clockwise angle between a line from point #1 -% to point #2 and a line from #3 to point #4. -% -\def\pgfmathanglebetweenlines#1#2#3#4{% - \begingroup% - \pgfmathanglebetweenpoints{#1}{#2}% - \let\firstangle\pgfmathresult% - \pgfmathanglebetweenpoints{#3}{#4}% - \let\secondangle\pgfmathresult% - \ifdim\firstangle pt>\secondangle pt\relax% - \pgfmathadd@{\secondangle}{360}% - \let\secondangle\pgfmathresult% - \fi% - \pgfmathsubtract@{\secondangle}{\firstangle}% - \pgfmath@smuggleone\pgfmathresult% - \endgroup% -} - -% \pgfmathpointreflectalongaxis -% -% Reflects point #2 around an axis centered on #2 at an angle #3. -% -\def\pgfmathreflectpointalongaxis#1#2#3{% - \pgf@process{% - \pgfmathanglebetweenpoints{#2}{#1}% - \pgfmath@tempdima\pgfmathresult pt\relax% - \pgfmathparse{#3}% - \advance\pgfmath@tempdima-\pgfmathresult pt\relax% - \pgfmath@tempdima-2.0\pgfmath@tempdima% - \pgfmathrotatepointaround{#1}{#2}{\pgfmath@tonumber{\pgfmath@tempdima}}% - }% -} - - -% \pgfmathpointintersectionoflineandarc -% -% A bit experimental at the moment: -% -% Locates the point where a line crosses an eliptical arc. If the line -% does not cross the arc, a meaningless point will result. -% -% #1 the point of the line on the "convex" side of the arc. -% #2 the point of the line on the "concave" side of the arc. -% #3 the center of the eliptical arc. -% #4 start angle of the arc. -% #5 end angle of the arc. -% #6 radii of the arc. -% -\def\pgfmathpointintersectionoflineandarc#1#2#3#4#5#6{% - \pgf@process{% - % - % Get the required angle. - % - \pgfmathanglebetweenpoints{#2}{#1}% - \let\x\pgfmathresult% - % - % Get the radii of the arc. - % - \pgfmath@in@{and }{#6}% - \ifpgfmath@in@% - \pgf@polar@#6\@@% - \else% - \pgf@polar@#6 and #6\@@% - \fi% - \edef\xarcradius{\the\pgf@x}% - \edef\yarcradius{\the\pgf@y}% - % - % Get the start and end angles of the arc... - % - \pgfmathsetmacro\s{#4}% - \pgfmathsetmacro\e{#5}% - % - % ...and also with rounding. - % - \pgfmathmod@{\s}{360}% - \ifdim\pgfmathresult pt<0pt\relax% - \pgfmathadd@{\pgfmathresult}{360}% - \fi% - \let\ss\pgfmathresult% - \pgfmathmod@{\e}{360}% - \ifdim\pgfmathresult pt<0pt\relax% - \pgfmathadd@{\pgfmathresult}{360}% - \fi% - \let\ee\pgfmathresult% - % - % Hackery for when arc straddles zero. - % - \ifdim\ee pt<\ss pt\relax% - \pgfmathadd@{\x}{180}% - \pgfmathmod@{\pgfmathresult}{360}% - \let\x\pgfmathresult% - \fi% - \def\m{360}% Measure of nearness. - \pgfmathadd@{\s}{\e}% - \pgfmathdivide@{\pgfmathresult}{2}% - \let\n\pgfmathresult% The best estimate (default to middle of arc). - \pgfmathloop% - \pgfmathadd@{\s}{\e}% - \pgfmathdivide@{\pgfmathresult}{2}% - \let\p\pgfmathresult% - \ifdim\p pt=\s pt\relax% - \else% - \pgfmathanglebetweenpoints{#2}{% - \pgfpointadd{#3}{% - \pgf@x\xarcradius\relax% - \pgfmathcos@{\p}% - \pgf@x\pgfmathresult\pgf@x% - \pgf@y\yarcradius\relax% - \pgfmathsin@{\p}% - \pgf@y\pgfmathresult\pgf@y% - }% - }% - % - % Hackery for when arc straddles zero. - % - \ifdim\ee pt<\ss pt\relax% - \pgfmathadd@{\pgfmathresult}{180}% - \pgfmathmod@{\pgfmathresult}{360}% - \fi% - \let\q\pgfmathresult% - % - % More hackery... - % - \ifdim\x pt>335pt\relax% - \ifdim\q pt<45pt\relax% - \pgfmathadd@{\q}{360}% - \let\q\pgfmathresult% - \fi% - \fi% - \ifdim\x pt=\q pt% Found it! - \pgfmathbreakloop% Breaks after current iteration is complete. - \else - \ifdim\x pt<\q pt\relax% - \let\e\p% - \else% - \let\s\p% - \fi% - \fi% - \pgfmathsubtract@{\x}{\q}% - \pgfmathabs@{\pgfmathresult}% - % - % Save the estimate if it is better than any previous estimate. - % - \ifdim\pgfmathresult pt<\m pt\relax% - \let\m\pgfmathresult% - \let\n\p% - \fi% - \repeatpgfmathloop% - \pgfpointadd{#3}{\pgfpointpolar{\n}{\xarcradius and \yarcradius}}% - }% -} - -% \pgfmathangleonellipse -% -% Find the angle corresponding to a point on the border of an ellispe. -% -% #1 - the point on the border. -% #2 - the radii of the ellipse. -% -\def\pgfmathangleonellipse#1#2{% - \begingroup% - \pgfmath@in@{and }{#2}% - \ifpgfmath@in@% - \pgf@polar@#2\@@% - \else% - \pgf@polar@#2 and #2\@@% - \fi% - \pgf@xa\pgf@x% - \pgf@ya\pgf@y% - \pgf@process{#1}% - \ifdim\pgf@x=0pt\relax% - \pgfutil@tempdima1pt\relax% - \else% - \pgfutil@tempdima\pgf@x% - \pgfmathdivide@{\pgfmath@tonumber{\pgf@xa}}{\pgfmath@tonumber{\pgfutil@tempdima}}% - \pgfutil@tempdima\pgfmathresult pt\relax% - \fi% - \ifdim\pgf@y=0pt\relax% - \pgfutil@tempdima1pt\relax% - \else% - \pgfmathdivide@{\pgfmath@tonumber{\pgf@y}}{\pgfmath@tonumber{\pgf@ya}}% - \pgfutil@tempdima\pgfmathresult\pgfutil@tempdima% - \pgfmathatan@{\pgfmath@tonumber{\pgfutil@tempdima}}% - \fi% - % - \pgfutil@tempdima\pgfmathresult pt\relax% - \ifdim\pgfutil@tempdima<0pt\relax% - \advance\pgfutil@tempdima360pt\relax% - \fi% - \ifdim\pgf@x<0pt\relax% - \ifdim\pgf@y=0pt\relax% - \pgfutil@tempdima180pt\relax% - \else% - \ifdim\pgf@y<0pt\relax% - \advance\pgfutil@tempdima180pt\relax% - \else% - \advance\pgfutil@tempdima-180pt\relax% - \fi% - \fi% - \else% - \ifdim\pgf@x=0pt\relax% - \ifdim\pgf@y<0pt\relax% - \pgfutil@tempdima270pt\relax% - \else% - \pgfutil@tempdima90pt\relax% - \fi% - \else% - \ifdim\pgf@y=0pt\relax% - \pgfutil@tempdima0pt\relax% - \fi% - \fi% - \fi% - \pgfmath@returnone\pgfutil@tempdima% - \endgroup% -}
\ No newline at end of file diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex index 3d69d34b73c..81f6545897e 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex @@ -1,970 +1,772 @@ -% Copyright 2007 Mark Wibrow -% -% This file may be distributed and/or modified -% -% 1. under the LaTeX Project Public License and/or -% 2. under the GNU Public License. -% -% See the file doc/generic/pgf/licenses/LICENSE for more details. -% This file parses/evaluates a decimal expression. -% -% Version 1.414213 29/9/2007 +\newdimen\pgfmath@dimen +\newcount\pgfmath@count +\newbox\pgfmath@box +\newtoks\pgfmath@toks -% \pgfmathparse, \pgfmathqparse -% -% Evaluates a decimal expression. -% -% #1 - the expression. -% -% returns -% -% x = the result as a dimension. -% -% E.g. -% \pgfmathparse{3pt*2cm+1.5} -% \pgfmathqparse{3pt*2cm+1.5pt} -% -% Every number in \pgfmathqparse *must* -% specify a unit. -% \newif\ifpgfmath@quickparse +\newif\ifpgfmathfloat +\newif\ifpgfmathunitsdeclared +\newif\ifpgfmathignoreunitscale + +\def\pgfmathprint#1{\pgfmathparse{#1}\pgfmathresult} \def\pgfmathparse{% - \pgfmath@quickparsefalse% - \pgfmathparse@} + \begingroup% + \pgfmath@catcodes% + \pgfmath@quickparsefalse% + \ifpgfmathfloat% + \let\pgfmath@parse@next=\pgfmathfloatparsenumber% + \else% + \let\pgfmath@parse@next=\pgfmathparse@% + \fi% + \pgfmath@parse@next} -\def\pgfmathqparse{% - \pgfmath@quickparsetrue% - \pgfmathparse@} - -\def\pgfmath@calcreal#1{#1}% -\def\pgfmath@calcminof#1#2{min(#1,#2)}% -\def\pgfmath@calcmaxof#1#2{max(#1,#2)}% -\def\pgfmath@calcratio#1#2{#1/#2}% +\def\pgfmath@catcodes{% Maybe unecessary. + \catcode`\==12% + \catcode`\,=12% + \catcode`\|=12% + \catcode`\&=12% +} +\def\pgfmathqparse{% + \begingroup% + \pgfmath@catcodes% + \pgfmath@quickparsetrue% + \pgfmathparse@} + \def\pgfmathparse@#1{% - \begingroup% - % Reinstall correct font, so that dimensions like 1em are correct + % Stuff for calc compatiability. + \let\real=\pgfmath@calc@real% + \let\minof=\pgfmath@calc@minof% + \let\maxof=\pgfmath@calc@maxof% + \let\ratio=\pgfmath@calc@ratio% + \let\widthof=\pgfmath@calc@widthof% + \let\heightof=\pgfmath@calc@heightof% + \let\depthof=\pgfmath@calc@depthof% + % Restore font. \pgfmath@selectfont% - \let\real\pgfmath@calcreal% - \let\minof\pgfmath@calcminof% - \let\maxof\pgfmath@calcmaxof% - \let\ratio\pgfmath@calcratio% - \edef\pgfmath@temp{#1}% - \pgfmath@resetparsingparameters% + % Expand expression so any reamining CSs are registers + % or box dimensions (i.e., \wd, \ht, \dp). + \edef\pgfmath@expression{#1}% + % No units yet. \global\pgfmathunitsdeclaredfalse% - \ifpgfmath@quickparse% - \let\pgfmath@parseoperand\pgfmath@quickparseoperand% - \else% - \let\pgfmath@parseoperand\pgfmath@parseoperand% - \fi% - \let\pgfmath@parsepostgroup\pgfmath@parseoperator% - \expandafter\pgfmath@parse@\pgfmath@temp @@@@@@@@@@@\pgfmath@empty} + % Set up stack. + \pgfmath@stack@operation={{}{}{}}% + \pgfmath@stack@operand={{}{}{}}% + \let\pgfmath@stack@operation@top=\pgfmath@stack@empty% + \let\pgfmath@stack@operand@top=\pgfmath@stack@empty% + % An expression always begins with an operand. + \expandafter\pgfmath@bgroup@strip\expandafter{\pgfmath@expression}% + \expandafter\pgfmath@parse@@operand\pgfmath@bgroup@stripped @@@@\pgfmath@parse@stop% +}% +\def\pgfmath@parse@end#1\pgfmath@parse@stop{% + \pgfmathpostparse% + \pgfmath@smuggleone\pgfmathresult% + \endgroup% + \ignorespaces}% -% \pgfmath@resetparsingparameters -% -% Reset the stack at the begining of the parse/group. -% -\def\pgfmath@resetparsingparameters{% - \pgfmath@stack{\pgfmath@empty\pgfmath@empty\pgfmath@empty\pgfmath@empty}% - \def\pgfmath@stacknextoperator{\pgfmath@empty}% Will not work with \let -} -% \pgfmath@parse@ -% -% Start parsing. Expect one of -% 1) the end of the parse -% 2) the start of a group -% 3) a (possible) operand. +\let\pgfmathpostparse=\relax% + +% For compatiability with older version. % -\def\pgfmath@parse@#1{% - \def\pgfmath@token{}% - \ifx#1@% - \let\pgfmath@parsenext\pgfmath@endparse% - \else% - \ifx#1(% - \let\pgfmath@parsenext\pgfmath@startparsegroup% - \else% - \edef\pgfmath@token{#1}% - \let\pgfmath@parsenext\pgfmath@parseoperand% - \fi\fi% - \pgfmath@parsenext% +\def\pgfmathscaleresult{% + \ifpgfmathunitsdeclared% + \else% + \ifpgfmathignoreunitscale% + \else% + \afterassignment\pgfmath@gobbletilpgfmath@% + \pgfmath@x\pgfmathresultunitscale pt\relax\pgfmath@% + \expandafter\pgfmath@x\pgfmathresult\pgfmath@x% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}% + \fi% + \fi% } - -% If no TeX units are declared *at any point* in the parse -% the result is scaled by \pgfmathresultunitscale. -\newif\ifpgfmathunitsdeclared \def\pgfmathsetresultunitscale#1{\def\pgfmathresultunitscale{#1}} \def\pgfmathresultunitscale{1} -% \pgfmath@endparse -% -% Everything stops here. -% -\def\pgfmath@endparse#1\pgfmath@empty{% - \pgfmath@processalloperations% - \pgfmath@stackpop{\pgfmathresult}% - \begingroup% - \ifpgfmathunitsdeclared% - \pgfmath@x1pt\relax% - \else% - \afterassignment\pgfmath@gobbletilpgfmath@% - \pgfmath@x\pgfmathresultunitscale pt\relax\pgfmath@% - \fi% - \expandafter\pgfmath@x\pgfmathresult\pgfmath@x% - \pgfmath@returnone\pgfmath@x% - \endgroup% - \pgfmath@smuggleone{\pgfmathresult}% - \endgroup% - \ignorespaces% -} +% Stuff for compatability with the calc package. +% +\def\pgfmath@calc@real#1{#1} +\def\pgfmath@calc@minof#1#2{min(#1,#2)} +\def\pgfmath@calc@maxof#1#2{max(#1,#2)} +\def\pgfmath@calc@ratio#1#2{#1/#2} +\def\pgfmath@calc@widthof#1{width("#1")} +\def\pgfmath@calc@heightof#1{height("#1")} +\def\pgfmath@calc@depthof#1{depth("#1")} + +\def\pgfmath@bgroup{\string\pgfmath@bgroup} +\def\pgfmath@egroup{\string\pgfmath@egroup} +\def\pgfmath@egroup@token{\pgfmath@egroup} + +\def\pgfmath@text@@{@} +\def\pgfmath@text@operator{operator} +\def\pgfmath@text@function{function} +\def\pgfmath@dots{...} +\def\pgfmath@char@zero{0} +\def\pgfmath@char@quote{"} +\def\pgfmath@char@exclamation{!} +\def\pgfmath@char@plus{+} +\def\pgfmath@char@minus{-} +\def\pgfmath@char@period{.} +\def\pgfmath@char@leftangle{<} +\def\pgfmath@char@leftbracket{[} +\pgfmath@toks={#} +\edef\pgfmath@char@hash{\the\pgfmath@toks} + +\def\pgfmath@tokens@make#1#2{% + \def\pgfmath@prefix{#1}% + \expandafter\pgfmath@tokens@@make#2{}} + +\def\pgfmath@tokens@@make#1{% + \def\pgfmath@token{#1}% + \ifx\pgfmath@token\pgfmath@empty% + \else% + \pgfmath@namedef{pgfmath@token@\pgfmath@prefix @\string#1}{#1}% + \expandafter\pgfmath@tokens@@make% + \fi} -% \pgfmath@startparsegroup -% -% When opening ( is scanned start a new group. +\pgfmath@tokens@make{box}{\wd\ht\dp} +\pgfmath@tokens@make{unit}{{bp}{cc}{cm}{dd}{em}{ex}{in}{mm}{pc}{pt}{sp}} +\pgfmath@tokens@make{numeric}{.0123456789} +\pgfmath@tokens@make{number}{0123456789} +\pgfmath@tokens@make{functional}{_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ} +\pgfmath@tokens@make{exponent}{eE} +\pgfmath@tokens@make{group}{{()}{[]}{\pgfmath@bgroup\pgfmath@egroup}} +\pgfmath@tokens@make{specials}{@)]\pgfmath@egroup} +\pgfmath@tokens@make{hexadecimal}{0123456789ABCDEFabcdef} +\pgfmath@tokens@make{octal}{01234567} +\pgfmath@tokens@make{binary}{01} + +\pgfmath@namedef{pgfmath@base@0x}{16} +\pgfmath@namedef{pgfmath@base@0X}{16} +\pgfmath@namedef{pgfmath@base@0b}{2} +\pgfmath@namedef{pgfmath@base@0B}{2} + +% Determine if a register is a count or a dimension/skip register. % -\def\pgfmath@startparsegroup{% +\newif\ifpgfmath@dimen@ +\def\pgfmath@dimen@#1{% \begingroup% - \let\pgfmath@parsepostgroup\pgfmath@parseoperator% - \pgfmath@resetparsingparameters% - \pgfmath@parse@} - -% \pgfmath@endparsegroup -% -% When closing ) is scanned, processes all waiting -% operations (within the group) and close the group. -% -\def\pgfmath@endparsegroup{% - \pgfmath@processalloperations% - \pgfmath@stackpop{\pgfmathresult}% - \expandafter\pgfmath@x\pgfmathresult pt\relax% - \pgfmath@returnone\pgfmath@x% + \afterassignment\pgfmath@dimen@@% + #1=0.0pt\relax\pgfmath@} +\def\pgfmath@dimen@@#1#2\pgfmath@{% \endgroup% - \pgfmath@parsepostgroup% -} + \ifx#1.% + \pgfmath@dimen@false% + \else% + \pgfmath@dimen@true% + \fi} -% \pgfmath@parseoperator -% -% An operator is expected here. -% Or the end of the parse or parse group. -% -\def\pgfmath@parseoperator#1{% - \def\pgfmath@token{}% - % Push the operand in \pgfmathresult on to the stack. - \expandafter\pgfmath@stackpushoperand\expandafter{\pgfmathresult}% - \ifx#1@% - \let\pgfmath@parsenext\pgfmath@endparse% +\def\pgfmath@parse@ifbgroup#1#2{% + \let\pgfmath@parse@bgroup@after=#1% + \let\pgfmath@parse@nobgroup@after=#2% + \futurelet\pgfmath@token@let% + \pgfmath@parse@@ifbgroup} + +\def\pgfmath@parse@@ifbgroup{% + \ifx\pgfmath@token@let\bgroup% + \let\pgfmath@parse@next=\pgfmath@parse@@@ifbgroup% \else% - \ifx#1+% - \let\pgfmath@parsenext\pgfmath@parseadd% + \ifx\pgfmath@token@let\pgfmath@sptoken% + \let\pgfmath@parse@next=\pgfmath@parse@@@@ifbgroup% \else% - \ifx#1-% - \let\pgfmath@parsenext\pgfmath@parsesubtract% - \else% - \ifx#1*% - \let\pgfmath@parsenext\pgfmath@parsemultiply% - \else% - \ifx#1/% - \let\pgfmath@parsenext\pgfmath@parsedivide% - \else - \ifx#1)% - \let\pgfmath@parsenext\pgfmath@endparsegroup% - \else% - \ifx#1r% - \let\pgfmath@parsenext\pgfmath@parseradians% - \else% - \ifx#1>% - \let\pgfmath@parsenext\pgfmath@parsegreaterthan% - \else% - \ifx#1<% - \let\pgfmath@parsenext\pgfmath@parselessthan% - \else% - \if#1=% - \let\pgfmath@parsenext\pgfmath@parseequalto% - \else% - \if#1^% - \let\pgfmath@parsenext\pgfmath@parsepower% - \else% - \pgfmath@error{Unknown operator `#1'}% - \let\pgfmath@parsenext\relax% - \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi% - \pgfmath@parsenext% -} - -% Use a \toks register as a stack. -\newtoks\pgfmath@stack + \let\pgfmath@parse@next=\pgfmath@parse@nobgroup@after% + \fi% + \fi% + \pgfmath@parse@next} -% \pgfmath@stackpushoperator -% -% Push an operator (actually its macro e.g., \pgfmathadd@) -% on to the stack. And keep track of it using the macro -% \pgfmath@stacknextoperator. -% -\def\pgfmath@stackpushoperator#1{% - \edef\pgfmath@temp{\noexpand#1\the\pgfmath@stack}% - \expandafter\pgfmath@stack\expandafter{\pgfmath@temp}% - \def\pgfmath@stacknextoperator{#1}}% <- Must \def. Cannot \let. +\def\pgfmath@parse@@@ifbgroup#1{\pgfmath@parse@bgroup@after\pgfmath@bgroup#1\pgfmath@egroup} -% \pgfmath@stackpushoperand -% -% Push an operand (i.e. a number) on the stack. It is -% put within a TeX group to make popping a lot simpler. -% -\def\pgfmath@stackpushoperand#1{% - \edef\pgfmath@temp{{#1}\the\pgfmath@stack}% - \expandafter\pgfmath@stack\expandafter{\pgfmath@temp}% +{ +\def\:{\pgfmath@parse@@@@ifbgroup} +\expandafter\gdef\: {\futurelet\pgfmath@token@let\pgfmath@parse@@ifbgroup} } -% \pgfmath@stackpeek -% -% Peek (i.e. without removal) at the top of the stack. -% -\def\pgfmath@stackpeek{\expandafter\pgfmath@stackpeek@\the\pgfmath@stack\pgfmath@} -\def\pgfmath@stackpeek@#1#2\pgfmath@{#1}% +% Parse an operand. +% +\def\pgfmath@parse@operand{\expandafter\pgfmath@parse@@operand\pgfmath@token@next}% -% \pgfmath@stackpop -% -% Pop (i.e. remove) the top of the stack into #1. -% -\def\pgfmath@stackpop#1{\expandafter\pgfmath@stackpop@\expandafter#1\the\pgfmath@stack\pgfmath@} -\def\pgfmath@stackpop@#1#2#3\pgfmath@{\edef#1{#2}\pgfmath@stack{#3}}% +\def\pgfmath@parse@@operand{\pgfmath@parse@ifbgroup{\pgfmath@parse@@operand}{\pgfmath@parse@@operand@}} -% \pgfmath@stackpopoperation -% -% Remove and perform an operation from the stack. -% -\def\pgfmath@stackpopoperation{% - \expandafter\pgfmath@stackpopoperation@\the\pgfmath@stack\pgfmath@% -} -\def\pgfmath@stackpopoperation@#1#2#3#4#5\pgfmath@{% - \ifx\pgfmath@empty#1\relax% - \pgfmath@stack{\pgfmath@empty\pgfmath@empty\pgfmath@empty\pgfmath@empty}% +\def\pgfmath@parse@@operand@#1{% + \def\pgfmath@token{#1}% + \ifx\pgfmath@token\pgfmath@char@plus% Ignore. + \let\pgfmath@parse@next=\pgfmath@parse@@operand% \else% - \ifx\pgfmath@empty#2\relax% - \pgfmath@stack{{#1}\pgfmath@empty\pgfmath@empty\pgfmath@empty\pgfmath@empty}% + \ifx\pgfmath@token\pgfmath@char@minus% + \pgfmath@stack@push@operation{neg}% Unary minus. + \let\pgfmath@parse@next=\pgfmath@parse@@operand% \else% - #2{#3}{#1}% - \pgfmath@stack{#4#5}% - \expandafter\pgfmath@stackpushoperand\expandafter{\pgfmathresult}% - \fi\fi% - \def\pgfmath@stacknextoperator{#4}} + \expandafter\ifx\csname pgfmath@operation@\expandafter\string\pgfmath@token @prefix\endcsname\pgfmath@token% + \let\pgfmath@parse@next=\pgfmath@parse@prefix@operator% + \else% + \ifpgfmath@quickparse% + \let\pgfmath@parse@next=\pgfmath@qparse@operand% + \else% + \let\pgfmath@number=\pgfmath@empty% + \expandafter\ifx\csname pgfmath@token@functional@\string#1\endcsname\relax% + \let\pgfmath@base=\pgfmath@empty% + \let\pgfmath@token@next=\pgfmath@token% + \if#10% Check for octal prefix. + \def\pgfmath@base{8}% + \fi% + \let\pgfmath@parse@next=\pgfmath@parse@number% + \else% + \let\pgfmath@function=\pgfmath@token% + \let\pgfmath@parse@next=\pgfmath@parse@function% + \fi% + \fi% + \fi% + \fi% + \fi% + \pgfmath@parse@next% +} -% \pgfmath@processalloperations -% -% Process all operation in the stack. The -% overall result is at the top of the stack. +% Parse prefix operators. % -\def\pgfmath@processalloperations{% - \expandafter\pgfmath@in@\pgfmath@stacknextoperator{\pgfmath@empty}% - \ifpgfmath@in@% - \let\pgfmath@processnext\relax% +\def\pgfmath@parse@prefix@operator{% + \ifx\pgfmath@token\pgfmath@char@quote% Quote character. + \let\pgfmath@parse@next=\pgfmath@parse@operand@quote% \else% - \pgfmath@stackpopoperation% - \let\pgfmath@processnext\pgfmath@processalloperations% + \ifx\pgfmath@token\pgfmath@char@exclamation% Prefix !. + \pgfmath@stack@push@operation{not}% + \let\pgfmath@parse@next=\pgfmath@parse@@operand% + \else% Anything else, just push and hope. + \expandafter\pgfmath@stack@push@operation\expandafter{\pgfmath@token}% + \let\pgfmath@parse@next=\pgfmath@parse@@operand% + \fi% \fi% - \pgfmath@processnext} + \pgfmath@parse@next% +}% -% \pgfmath@processoperationsuntil -% -% Process operations in the stack, until the specified -% operation/s is/are encountered. The overall result is -% at the top of the stack. -% -\def\pgfmath@processoperationsuntil#1{% - \expandafter\pgfmath@in@\pgfmath@stacknextoperator{#1\pgfmath@empty}% - \ifpgfmath@in@% - \let\pgfmath@processnext\pgfmath@processoperationsuntil@end% + +% Quote part of an expression. +% +\def\pgfmath@parse@operand@quote#1"{% + \def\pgfmathresult{#1}% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \pgfmath@parse@@operator% +} + +% Quick operand parsing. Should always have units. +% No functions, base conversion, quoting or scientific notation +% are permitted. +\def\pgfmath@qparse@operand{% + \afterassignment\pgfmath@qparse@@operand% + \pgfmath@dimen\pgfmath@token} +\def\pgfmath@qparse@@operand{% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \pgfmath@parse@@operator% +} + +% Parse a number, which can take the form: +% +% 1. An integer, or a decimal, with or without units. +% 2. A dimension/skip or a count register. +% 3. A dimension register preceded by a number or count register. +% 4. A box dimension (e.g., \wd\mybox). +% 5. A box dimension preceded by a number or a count register. +% 6. Scientific notation (e.g., 1.234567e-10). +% 7. A binary, hexadeciaml, or octal number. +% +\def\pgfmath@parse@number{\pgfmath@parse@ifbgroup{\pgfmath@parse@number}{\pgfmath@parse@number@}} +\def\pgfmath@parse@number@#1{% + \let\pgfmath@token=\pgfmath@token@next% + \def\pgfmath@token@next{#1}% + \pgfmath@parse@@number} + +\def\pgfmath@parse@@number{% + \ifx\pgfmath@token\pgfmath@egroup@token% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmath@number}% + \let\pgfmath@parse@next=\pgfmath@parse@@@operator% \else% - \pgfmath@stackpopoperation% - \let\pgfmath@processnext\pgfmath@processoperationsuntil% + \expandafter\ifcat\pgfmath@token\relax% A CS? + \expandafter\ifx\csname pgfmath@token@box@\expandafter\string\pgfmath@token\endcsname\relax% + % So, is the CS is a dimension or a count register? + \expandafter\pgfmath@dimen@\pgfmath@token% + \ifpgfmath@dimen@% A dimension register. + \global\pgfmathunitsdeclaredtrue% + \pgfmath@dimen=\pgfmath@number\pgfmath@token% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \let\pgfmath@parse@next=\pgfmath@parse@operator% + \else% A count register. + \pgfmath@count=\pgfmath@token% + \expandafter\def\expandafter\pgfmath@number\expandafter{\the\pgfmath@count}% + \expandafter\ifcat\pgfmath@token@next\relax% + % A CS following a count register should be \wd, \ht or \dp. + \let\pgfmath@parse@next=\pgfmath@parse@number% + \else% + \let\pgfmathresult=\pgfmath@number% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \let\pgfmath@parse@next=\pgfmath@parse@operator% + \fi% + \fi% + \else% + % This should be a box specification, for example, 0.5\wd\mybox. + \global\pgfmathunitsdeclaredtrue% + \pgfmath@dimen=\pgfmath@number\pgfmath@token\pgfmath@token@next% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \let\pgfmath@parse@next=\pgfmath@parse@@operator% + \fi% + \else% + \expandafter\ifx\csname pgfmath@token@numeric@\expandafter\string\pgfmath@token\endcsname\relax% + % It isn't numeric (i.e., 012345679.), so it might be units... + \expandafter\ifx\csname pgfmath@token@unit@\pgfmath@token\expandafter\string\pgfmath@token@next\endcsname\relax% + % ...or the exponent characters... + \expandafter\ifx\csname pgfmath@token@exponent@\pgfmath@token\endcsname\relax% + % ...or a base prefix... + \expandafter\ifx\csname pgfmath@base@\pgfmath@number\pgfmath@token\endcsname\relax% + % ...none of the above... + \ifx\pgfmath@base\pgfmath@empty% + \let\pgfmathresult=\pgfmath@number% + \else% + \ifx\pgfmath@number\pgfmath@char@zero% + \let\pgfmathresult=\pgfmath@number% + \else% + % Convert from octal. + \expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\pgfmath@number}{8}{10}% + \fi% + \fi% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \let\pgfmath@parse@next=\pgfmath@parse@@@operator% + \else% + % ...here, it is a base prefix 0x, 0X, 0b or 0B + \expandafter\let\expandafter\pgfmath@base\expandafter=% + \csname pgfmath@base@\pgfmath@number\pgfmath@token\endcsname% + \let\pgfmath@parse@next=\pgfmath@parse@base% + \fi% + \else% ... and here, it is the exponent characters. + \let\pgfmath@parse@next=\pgfmath@parse@exponent% + \fi% + \else% ...but here it is units. + \global\pgfmathunitsdeclaredtrue% + \pgfmath@dimen=\pgfmath@number\pgfmath@token\pgfmath@token@next\relax% + \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@dimen}}% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \let\pgfmath@parse@next=\pgfmath@parse@@operator% + \fi% + \else% It is numeric. + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\pgfmath@number% + \expandafter\expandafter\expandafter{\expandafter\pgfmath@number\pgfmath@token}% + \ifx\pgfmath@token\pgfmath@char@period% + \let\pgfmath@base=\pgfmath@empty% + \fi% + \let\pgfmath@parse@next=\pgfmath@parse@number% + \fi% + \fi% \fi% - \pgfmath@processnext{#1}} -\def\pgfmath@processoperationsuntil@end#1{} + \pgfmath@parse@next% +} +% Parse the exponent of a number. +% +% REMARK: this method will be overwritten by the FPU library. Please +% keep changes consistent... +\def\pgfmath@parse@exponent{% + \afterassignment\pgfmath@parse@@exponent% + \pgfmath@count\pgfmath@token@next} +\def\pgfmath@parse@@exponent{% + \pgfmathscientific{\pgfmath@number}{\the\pgfmath@count}% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \pgfmath@parse@@operator% +} -% OK. Now the operators are parsed. -% These correspond to the + - / * ^ < > = operators and r (postfix) function. +% Parse binary or hexadecimal numbers (octal numbers done elsehwere). % -\def\pgfmath@parseadd{% - % If no operator has been assigned (i.e. + is the first operator scanned), - % do nothing, except add addition to the stack. - \ifx\pgfmath@stacknextoperator\pgfmath@empty% +\def\pgfmath@parse@base{% + \ifnum\pgfmath@base=2\relax% + \let\pgfmath@parse@next=\pgfmath@parse@binary% \else% - % Empty the process stack up to any inequalities. - \pgfmath@processoperationsuntil{\pgfmathequalto@\pgfmathlessthan@\pgfmathgreaterthan@}% + \ifnum\pgfmath@base=16\relax% + \let\pgfmath@parse@next=\pgfmath@parse@hexadecimal% + \else% + \pgfmath@error{Unexpected numerical base `\pgfmath@base'}{}% + \def\pgfmathresult{0}% + \let\pgfmath@parse@next=\pgfmath@parse@end% + \fi% \fi% - \pgfmath@stackpushoperator{\pgfmathadd@}% - \pgfmath@parse@} + \let\pgfmath@number=\pgfmath@empty% + \expandafter\pgfmath@parse@next\pgfmath@token@next% +} -\def\pgfmath@parsesubtract{% - % If no operator has been assigned (i.e. - is the first operator scanned), - % do nothing, except add subtract to the stack. - \ifx\pgfmath@stacknextoperator\pgfmath@empty% +\def\pgfmath@parse@binary#1{% + \expandafter\ifx\csname pgfmath@token@binary@#1\endcsname\relax% + \expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\pgfmath@number}{2}{10}% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \def\pgfmath@token@next{#1}% + \let\pgfmath@parse@next=\pgfmath@parse@operator% \else% - % Empty the process stack up to any inequalities. - \pgfmath@processoperationsuntil{\pgfmathequalto@\pgfmathlessthan@\pgfmathgreaterthan@}% + \expandafter\def\expandafter\pgfmath@number\expandafter{\pgfmath@number#1}% + \let\pgfmath@parse@next=\pgfmath@parse@binary% \fi% - \pgfmath@stackpushoperator{\pgfmathsubtract@}% - \pgfmath@parse@} - -\def\pgfmath@parsemultiply{% - % If no operator has been assigned (i.e. * is the first operator scanned), - % do nothing, except push multiply onto the stack. - \ifx\pgfmath@stacknextoperator\pgfmath@empty% + \pgfmath@parse@next% +} + +\def\pgfmath@parse@hexadecimal#1{% + \expandafter\ifx\csname pgfmath@token@hexadecimal@#1\endcsname\relax% + \expandafter\pgfmathbasetobase\expandafter\pgfmathresult\expandafter{\pgfmath@number}{16}{10}% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \def\pgfmath@token@next{#1}% + \let\pgfmath@parse@next=\pgfmath@parse@operator% \else% - % Process all operations up to inequalites or addition/subtraction - \pgfmath@processoperationsuntil{\pgfmathequalto@\pgfmathlessthan@\pgfmathgreaterthan@% - \pgfmathadd@\pgfmathsubtract@}% + \expandafter\def\expandafter\pgfmath@number\expandafter{\pgfmath@number#1}% + \let\pgfmath@parse@next=\pgfmath@parse@hexadecimal% \fi% - \pgfmath@stackpushoperator{\pgfmathmultiply@}% - \pgfmath@parse@} + \pgfmath@parse@next% +} -\def\pgfmath@parsedivide{% - % If no operator has been assigned (i.e. / is the first operator scanned), - % do nothing, except push divide onto the stack. - \ifx\pgfmath@stacknextoperator\pgfmath@empty% +% Parse a function. +% +\def\pgfmath@parse@function{\pgfmath@parse@ifbgroup{\pgfmath@parse@function}{\pgfmath@parse@@function}} +\def\pgfmath@parse@function@{\futurelet\pgfmath@token@let\pgfmath@parse@@function} +\def\pgfmath@parse@@function{% + \ifx\pgfmath@token@let\pgfmath@sptoken% + \let\pgfmath@token=\pgfmath@empty% + \let\pgfmath@parse@next=\pgfmath@parse@@@@function% \else% - % Process all operations up to inequalites or addition/subtraction - \pgfmath@processoperationsuntil{\pgfmathequalto@\pgfmathlessthan@\pgfmathgreaterthan@% - \pgfmathadd@\pgfmathsubtract@}% + \let\pgfmath@parse@next=\pgfmath@parse@@@function% \fi% - \pgfmath@stackpushoperator{\pgfmathdivide@}% - \pgfmath@parse@} - -\def\pgfmath@parsegreaterthan{% - % On scanning an equality/inequality operator everything up to - % (but not including) the operator is evaluated... - \pgfmath@processalloperations% - % ...and the operation pushed onto the stack. - \pgfmath@stackpushoperator{\pgfmathgreaterthan@}% - \pgfmath@parse@} - -\def\pgfmath@parselessthan{% - \pgfmath@processalloperations% - \pgfmath@stackpushoperator{\pgfmathlessthan@}% - \pgfmath@parse@} - -\def\pgfmath@parseequalto={% - \pgfmath@processalloperations% - \pgfmath@stackpushoperator{\pgfmathequalto@}% - \pgfmath@parse@} - -\def\pgfmath@parsepower{% - % Easy, just push power onto the stack. - \pgfmath@stackpushoperator{\pgfmathpow@}% - \pgfmath@parse@} - -\def\pgfmath@parseradians{% - % r is a post-fix function... - \ifx\pgfmath@primaryoperation\pgfmath@empty% - \else% - \pgfmath@processoperationsuntil{\pgfmathequalto@\pgfmathlessthan@\pgfmathgreaterthan@% - \pgfmathadd@\pgfmathsubtract@}% - \fi% - \pgfmath@stackpop{\pgfmath@temp}% - \pgfmathdeg@{\pgfmath@temp}% - % ...so processing returns to \pgfmath@parseoperator - \pgfmath@parseoperator} - -\newcount\c@pgfmath@parsecounta -\newcount\c@pgfmath@parsecountb -\newcount\c@pgfmath@parsecountc -\newdimen\pgfmath@parsex + \pgfmath@parse@next} + +\def\pgfmath@parse@@@function#1{% + \expandafter\ifx\csname pgfmath@token@functional@\expandafter\string#1\endcsname\relax% + \expandafter\ifx\csname pgfmath@token@number@\expandafter\string#1\endcsname\relax% + \def\pgfmath@token{#1}% Not from A-Z, a-z, 0-9, or _. + \let\pgfmath@parse@next=\pgfmath@parse@@@@function% + \else% It is from 0-9. + \expandafter\def\expandafter\pgfmath@function\expandafter{\pgfmath@function#1}% + \let\pgfmath@parse@next=\pgfmath@parse@function@% + \fi% + \else% It is from from A-Z, a-z, or _. + \edef\pgfmath@function{\pgfmath@function#1}% + \let\pgfmath@parse@next=\pgfmath@parse@function@% + \fi% + \pgfmath@parse@next} -% \pgfmath@quickparseoperand -% -% An operand can *only* be a dimension. -% -\def\pgfmath@quickparseoperand{% - \afterassignment\pgfmath@quickparseoperand@% - \pgfmath@parsex\pgfmath@token} -\def\pgfmath@quickparseoperand@{% - \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@parsex}}% - \pgfmath@parseoperator% -} - -% \pgfmath@parseoperand -% -% An operand can be an ASCII number (with or without dimensions, with -% or without a decimal point), a TeX register (count, dimen or skip, -% which may have expanded with \the), or a function e.g. sin(X). -% -% It is assumed that after \edef-ing, the only unexpanded tokens are registers. -% -\def\pgfmath@parseoperand{% - \def\pgfmath@sign{}% - \expandafter\pgfmath@parseoperandsign\pgfmath@token} -\def\pgfmath@parseoperandsign#1{% - \pgfmath@in@#1{-+}% - \ifpgfmath@in@ - % Gobble multiple signs. - \edef\pgfmath@sign{\pgfmath@sign#1}% - \expandafter\pgfmath@parseoperandsign% +\def\pgfmath@parse@@@@function{% + \expandafter\ifx\csname pgfmath@function@\pgfmath@function\endcsname\relax% + \pgfmath@error{Unknown function `\pgfmath@function'}{}% + \def\pgfmathresult{0}% + \let\pgfmath@parse@next=\pgfmath@parse@end% \else% - \expandafter\pgfmath@parsenumberorfunction\expandafter#1% + \expandafter\ifnum\csname pgfmath@operation@\pgfmath@function @arity\endcsname=0\relax% + % Functions with zero arity are called directly. + \csname pgfmath\pgfmath@function @\endcsname% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \let\pgfmath@parse@next=\pgfmath@parse@@operator% + \else% Otherwise, they are pushed onto the operator stack + \expandafter\pgfmath@stack@push@operation\expandafter{\pgfmath@function}% + \let\pgfmath@parse@next=\pgfmath@parse@@operand% + \fi% + \fi% + \expandafter\pgfmath@parse@next\pgfmath@token} + +% Parse an operator. +% +\def\pgfmath@parse@operator{\pgfmath@parse@ifbgroup{\pgfmath@parse@operator}{\pgfmath@parse@operator@}}% +\def\pgfmath@parse@operator@#1{% Get one token. + \let\pgfmath@token=\pgfmath@token@next% + \def\pgfmath@token@next{#1}% + \pgfmath@parse@@@operator} + +\def\pgfmath@parse@@operator{\pgfmath@parse@ifbgroup{\pgfmath@parse@@operator}{\pgfmath@parse@@operator@}}% +\def\pgfmath@parse@@operator@#1{% Get first token... + \def\pgfmath@token{#1}% + \pgfmath@parse@ifbgroup{\pgfmath@parse@@operator@@}{\pgfmath@parse@@operator@@}}% +\def\pgfmath@parse@@operator@@#1{% ...and second token. + \def\pgfmath@token@next{#1}% + \pgfmath@parse@@@operator} + +\def\pgfmath@parse@@@operator{% + \expandafter\ifx\csname pgfmath@operator@\pgfmath@token\expandafter\string\pgfmath@token@next\endcsname\relax% + % Not a double character operator. + \expandafter\ifx\csname pgfmath@operator@\pgfmath@token\endcsname\relax% + % Not a single character operator. + \pgfmath@error{Unknown operator `\pgfmath@token' or `\pgfmath@token\pgfmath@token@next'}{}% + \def\pgfmathresult{0}% + \let\pgfmath@parse@next=\pgfmath@parse@end% + \else% + \expandafter\pgfmath@operation@process\expandafter{\pgfmath@token}% + \ifx\pgfmath@token\pgfmath@text@@% + \let\pgfmath@parse@next=\pgfmath@parse@end% + \else% + \expandafter\ifx\csname pgfmath@operation@\pgfmath@token @postfix\endcsname\pgfmath@token% + % Postfix operators are followed by an operator. + \ifx\pgfmath@token@next\pgfmath@char@leftbracket% Except [. + \let\pgfmath@parse@next=\pgfmath@parse@operand% + \else% + \let\pgfmath@parse@next=\pgfmath@parse@operator% + \fi% + \else% + % Any other operator is followed by an operand. + \let\pgfmath@parse@next=\pgfmath@parse@operand% + \fi% + \fi% + \fi% + \else% + % A double character operator... + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter% + \pgfmath@token\expandafter\expandafter\expandafter% + {\expandafter\pgfmath@token\pgfmath@token@next}% + \expandafter\pgfmath@operation@process\expandafter{\pgfmath@token}% + % ...is always followed by an operand. + \let\pgfmath@parse@next=\pgfmath@parse@@operand% \fi% + \pgfmath@parse@next% } -\newif\ifpgfmath@dimen@ -\def\pgfmath@ifregisterdimen@#1\pgfmath@{% - \pgfmath@in@{p}{#1}% - \ifpgfmath@in@% - \pgfmath@dimen@true% +% Process an operation. +% +\def\pgfmath@operation@process#1{% + \def\pgfmath@operator{#1}% + \ifx\pgfmath@stack@operation@top\pgfmath@stack@empty% \else% - \pgfmath@dimen@false% - \fi} - -\def\pgfmath@parsenumberorfunction#1{% - \let\pgfmath@parsenext\pgfmath@parsenumberorfunction@simple% - \ifx#1\wd\let\pgfmath@parsenext\pgfmath@boxdimen\fi% - \ifx#1\ht\let\pgfmath@parsenext\pgfmath@boxdimen\fi% - \ifx#1\dp\let\pgfmath@parsenext\pgfmath@boxdimen\fi% - \pgfmath@parsenext#1% -} - -\def\pgfmath@boxdimen#1#2{% - \pgfmath@parsex=\pgfmath@sign#1#2% - \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@parsex}}% - \global\pgfmathunitsdeclaredtrue% a dimension has units - \pgfmath@parseoperator% + \pgfmath@operation@@process% + \fi% + \expandafter\ifx\csname pgfmath@token@specials@#1\endcsname\relax% + \pgfmath@stack@push@operation{#1}% + \fi% } -\def\pgfmath@parsenumberorfunction@simple#1{% - \expandafter\ifcat#1\relax% - % So, a TeX register. - \afterassignment\pgfmath@ifregisterdimen@% - \pgfmath@parsex\pgfmath@sign#1pt\relax\pgfmath@% - \ifpgfmath@dimen@% - % A dimension! So stop scanning operand here. - \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@parsex}}% - \global\pgfmathunitsdeclaredtrue% a dimension has units - \def\pgfmath@temp{}% - \let\pgfmath@parsenext\pgfmath@parseoperator% +% Process the operation stack. +% +\def\pgfmath@operation@@process{% + \ifx\pgfmath@stack@operation@top\pgfmath@stack@empty% + \let\pgfmath@parse@next=\relax% + \else% + \ifnum\csname pgfmath@operation@\pgfmath@operator @precedence\endcsname>% + \csname pgfmath@operation@\pgfmath@stack@operation@top @precedence\endcsname\relax% + % If the precedence of the scanned operator is greater than the + % precedence of the operator at the top of the stack, do nothing. + \let\pgfmath@parse@next=\relax% \else% - % A count! Expand it, but carry on as usual as it might - % be immediately followed by a dimension. - \ifdim\pgfmath@parsex<0pt\relax% - \edef\pgfmath@sign{\pgfmath@sign-}% - \pgfmath@parsex-\pgfmath@parsex% + \let\pgfmath@stack@operation@last=\pgfmath@stack@operation@top% + \expandafter\ifx\csname pgfmath@operator@\pgfmath@stack@operation@top\endcsname\relax% + \pgfmath@function@@@process% + \else% + \pgfmath@operator@@@process% + \fi% + \expandafter\pgfmath@stack@push@operand\expandafter{\pgfmathresult}% + \expandafter\ifx\csname pgfmath@token@group@\pgfmath@stack@operation@last\pgfmath@operator\endcsname\relax% + \let\pgfmath@parse@next=\pgfmath@operation@@process% + \else% + \let\pgfmath@parse@next=\relax% \fi% - \edef\pgfmath@temp{\pgfmath@tonumber{\pgfmath@parsex}}% - \let\pgfmath@parsenext\pgfmath@parsenumberorfunction@% \fi% - \else% - % Could be a number or a function...? - \edef\pgfmath@temp{#1}% - \let\pgfmath@parsenext\pgfmath@parsenumberorfunction@% \fi% - \expandafter\pgfmath@parsenext\pgfmath@temp% -}% - -\def\pgfmath@parsenumberorfunction@#1{% - \ifx#1(% It might be a group e.g. -(1+2)... - \let\pgfmath@parsenext\pgfmath@parseoperandgroup% + \pgfmath@parse@next% +} + +% Process an operator. +% +\def\pgfmath@operator@@@process{% Process an operator. + \pgfmath@stack@pop@operation\pgfmath@@operator% + \pgfmath@stack@pop@operand\pgfmath@operand@a% + \ifcase\csname pgfmath@operation@\pgfmath@@operator @arity\endcsname\relax% + % Zero arity operators (!). + \or% + \pgfmath@operator@@@@process{\pgfmath@operand@a}% + \or% + \pgfmath@stack@pop@operand\pgfmath@operand@b% + \pgfmath@operator@@@@process{\pgfmath@operand@b}{\pgfmath@operand@a}% + \or% + \pgfmath@stack@pop@operand\pgfmath@operand@b% + \expandafter\pgfmath@operator@@@@process\expandafter% + {\expandafter\pgfmath@operand@b\expandafter}\pgfmath@operand@a% \else% - \pgfmath@in@{#1}{.0123456789}% - \ifpgfmath@in@% ... or a number... - \let\pgfmath@parsenext\pgfmath@parsenumber% - \else% ... or a function. - \let\pgfmath@parsenext\pgfmath@parsefunction% - \fi% + % No operators with more than tenary arity. \fi% - \pgfmath@parsenext#1% -}% - -\def\pgfmath@parseoperandgroup({% - \let\pgfmath@postparsegroup\pgfmath@@parseoperandgroup% - \pgfmath@startparsegroup% -} - -\def\pgfmath@@parseoperandgroup{% - \let\pgfmath@postparsegroup\pgfmath@parseoperator% - \edef\pgfmathresult{\pgfmath@sign\pgfmathresult}% - \pgfmath@parseoperator% } -\def\pgfmath@parsenumber{% - % Consider the number 3.14159 - % 3 is parsed by assignment to a, then '.' is absorbed and 14159 - % parsed by assignement to b (actually b=114159, see below). - \c@pgfmath@parsecountc0\relax% - \afterassignment\pgfmath@parsedecimalpoint% - \c@pgfmath@parsecounta0} - -\def\pgfmath@parsedecimalpoint#1{% - \ifx#1.% Is there a decimal point? If not, see if there are any units. - \let\pgfmath@parsenext\pgfmath@parsemantissa% - \else% - \c@pgfmath@parsecountb10\relax% The first digit of b is gobbled (see below). - \let\pgfmath@parsenext\pgfmath@parseunits% - \fi% - \pgfmath@parsenext#1} - - +\def\pgfmath@operator@@@@process{% + \csname pgfmath% + \csname pgfmath@operation@\pgfmath@@operator @name\endcsname% + @\endcsname} -% We would like to assign the following number (which is the mantisse) -% to a number. However, for a very long mantisse as in 3.141592653589793238462643 -% this will fail since the number becomes too large. +% Process a function. % -% Because of this, we have to do some ``magic'': We scan 9 tokens and -% then do an assignment with a guard after 9 tokens so that the -% assigment cannot fail. -% -\def\pgfmath@parsemantissa.#1#2#3#4#5#6#7#8#9{% - \afterassignment\pgfmath@checkforguard% - % Consider the number: 2.005 - % 2 is assigned to a, but b will be assigned 5, which is *not right*. - % So using 1 here hereresults in b=1005. The first digit is then - % gobbled later, when expanded with \the. - \c@pgfmath@parsecountb1#1#2#3#4#5#6#7#8#9\relax}% - -\def\pgfmath@checkforguard{% - \pgfmath@ifnextchar\relax% - {% - % Ok, this is a looong mantisse. Start gobbling all following - % numbers - \pgfmath@gobblemantisse% - }% - {% - \pgfmath@removeguard% - }% +\def\pgfmath@function@@@process{% Process a function. + \ifnum\csname pgfmath@operation@\pgfmath@stack@operation@top @arity\endcsname>0\relax% + \pgfmath@stack@pop@operation\pgfmath@@function% + \pgfmath@stack@pop@operand\pgfmath@@operand% + \ifnum\csname pgfmath@operation@\pgfmath@@function @arity\endcsname>1\relax% + \ifnum\csname pgfmath@operation@\pgfmath@@function @arity\endcsname>9\relax% + \csname pgfmath\pgfmath@@function @\endcsname{\pgfmath@@operand}% + \else% + \expandafter\pgfmath@function@@@@process\pgfmath@@operand% + \fi + \else% + \expandafter\pgfmath@function@@@@process\expandafter{\pgfmath@@operand}% + \fi% + \fi% } -\def\pgfmath@gobblemantisse\relax#1#2#3#4#5#6#7#8#9{% - \afterassignment\pgfmath@checkforguard% - \c@pgfmath@parsecountc0#1#2#3#4#5#6#7#8#9\relax% these digits are ignored -} +\def\pgfmath@function@@@@process{\csname pgfmath\pgfmath@@function @\endcsname} -\def\pgfmath@removeguard#1\relax{\pgfmath@parseunits#1} - - -\def\pgfmath@parseunits#1{% - % Here the extra first digit in b is gobbled. - \edef\pgfmath@resulttemp{% - \pgfmath@sign\the\c@pgfmath@parsecounta.\expandafter\pgfmath@gobbleone\the\c@pgfmath@parsecountb}% - % Check whether #1 is a \dp, \wd, or \ht - \let\pgfmath@parsenext=\pgfmath@parseunits@simple% - \ifx#1\wd\let\pgfmath@parsenext=\pgfmath@parseunits@boxdimen\fi% - \ifx#1\ht\let\pgfmath@parsenext=\pgfmath@parseunits@boxdimen\fi% - \ifx#1\dp\let\pgfmath@parsenext=\pgfmath@parseunits@boxdimen\fi% - \pgfmath@parsenext#1% -} +% Stack. +% +\newtoks\pgfmath@stack@operand +\newtoks\pgfmath@stack@operation +\let\pgfmath@stack@empty=\pgfmath@empty -\def\pgfmath@parseunits@boxdimen#1#2{% - \pgfmath@parsex=\pgfmath@sign#1#2% - \pgfmath@parsex\pgfmath@resulttemp\pgfmath@parsex% - \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@parsex}}% - \global\pgfmathunitsdeclaredtrue% a dimension has units - \pgfmath@parseoperator% -} +\def\pgfmath@stack@push#1#2{% + \def\pgfmath@stack@top{#2}% + \expandafter\expandafter\expandafter#1% + \expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter% + {\expandafter\pgfmath@stack@top\expandafter}\the#1}}% -\def\pgfmath@parseunits@simple#1{% - % Now check if #1 is actually a register. - \ifcat#1\relax% - \afterassignment\pgfmath@ifregisterdimen@% - \pgfmath@parsex#1pt\relax\pgfmath@% - \pgfmath@parsex\pgfmath@resulttemp\pgfmath@parsex% - \ifpgfmath@dimen@% If it's a dimen stop scanning operand here. - \global\pgfmathunitsdeclaredtrue% a dimension has units - \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@parsex}}% - \let\pgfmath@parsenext\pgfmath@parseoperator% - \else - \edef\pgfmath@resulttemp{\pgfmath@tonumber{\pgfmath@parsex}}% - \let\pgfmath@parsenext\pgfmath@parseunits@% - \fi% - \expandafter\pgfmath@parsenext% - \else% - \expandafter\pgfmath@parseunits@\expandafter#1% - \fi} +\def\pgfmath@stack@pop#1#2{\expandafter\pgfmath@stack@@pop\the#1\pgfmath@stack@stop{#1}{#2}} +\def\pgfmath@stack@@pop#1#2#3\pgfmath@stack@stop#4#5{\def#5{#1}#4={{#2}#3}\def\pgfmath@stack@top{#2}} -\def\pgfmath@parseunits@#1#2{% - % Check if #1 is an operator, or the character `@' indicating the end of the parse. - \pgfmath@in@#1{@+-*/^r<>=()}% - \ifpgfmath@in@% - \edef\pgfmath@tokens{#1#2}% - \edef\pgfmathresult{\pgfmath@resulttemp}% - \let\pgfmath@parsenext\pgfmath@parseoperator% - \else% - \pgfmath@in@#1{Ee}% e+0X - \ifpgfmath@in@% - % Oh no! It might be and em or an ex... - \pgfmath@in@#2{mx}% - \ifpgfmath@in@% - \global\pgfmathunitsdeclaredtrue% - \pgfmath@parsex\pgfmath@resulttemp#1#2\relax% - \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@parsex}}% - \edef\pgfmath@tokens{}% - \let\pgfmath@parsenext\pgfmath@parseoperator% - \else% - \edef\pgfmath@tokens{#2}% - \let\pgfmath@parsenext\pgfmath@parsescientific% - \fi% - \else - % Anything else *should* be a TeX unit. - \global\pgfmathunitsdeclaredtrue% - \pgfmath@parsex\pgfmath@resulttemp#1#2\relax% - \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@parsex}}% - \edef\pgfmath@tokens{}% - \let\pgfmath@parsenext\pgfmath@parseoperator% - \fi\fi% - \expandafter\pgfmath@parsenext\pgfmath@tokens% -} +\def\pgfmath@stack@push@operation#1{% + \pgfmath@stack@push\pgfmath@stack@operation{#1}% + \let\pgfmath@stack@operation@top=\pgfmath@stack@top} -% Parse 'Scientific' notation in the form xEyy -% -\def\pgfmath@parsescientific{% - \afterassignment\pgfmath@parsescientific@% - \c@pgfmath@parsecounta} - -\def\pgfmath@parsescientific@{% - \edef\pgfmath@parsesci@temp{\pgfmath@resulttemp\the\c@pgfmath@parsecountc}% - \expandafter\pgfmathscientific\expandafter{\pgfmath@parsesci@temp}% - {\the\c@pgfmath@parsecounta}% - \edef\pgfmath@resulttemp{\pgfmathresult}% - \pgfmath@parseunits@} - -% Functions parsed (not calculated) here are: -% -% round(X) 'half-up' rounding. -% floor(X) floor function. -% ciel(X) ceiling function. -% abs(X) absolute function. -% -% exp(X) e^X (0 <= X <~= 9.7). -% ln(X) logarithm of X. -% pow(X,Y) X^Y, -% -% sin(X) sine function. -% cos(X) cosine function. -% tan(X) tan function. -% asin(X) arcsine of X (in radians) -1 <= X <= 1 -% acos(X) arccosine of X (in radians) -1 <= X <= 1 -% atan(X) arctangent of X (in radians) -1 <= X <= 1 -% veclen(X,Y) the length Z where Z^2 = X^2 + Y^2 -% mod(X,Y) X modulo Y -% max(X,Y) the maximum of X or Y -% min(X,Y) the minimum of X or Y -% -% NB veclen, mod, max, and min *cannot* be nested. -% -% deg(X) converts X to degrees (X in radians) -% rad(X) converts X to radians (X in degrees) -% -% rnd generate pseudo-random number X (0 <= X <= 1). -% rand generate pseudo-random number X (1 <= X <= -1). -% sqrt(X) square root. -% -% pi the constant PI. - -\def\pgfmath@parsefunction{% - \def\pgfmath@parsedfunctionname{}% - \futurelet\pgfmath@parsetoken\pgfmath@parsefunction@@} -\def\pgfmath@parsefunction@@#1{% - \pgfmath@in@#1{()@+-*/^<>=}% A function name ends with one of these... - \ifpgfmath@in@% - \let\pgfmath@parsefunctionnext\pgfmath@parsefunction@end% - \else% - \ifx\pgfmath@parsetoken\pgfmath@sptoken% ...or a space. - \let\pgfmath@parsefunctionnext\pgfmath@parsefunction@end% - \else% - \let\pgfmath@parsefunctionnext\pgfmath@parsefunction@continue% - \fi\fi% - \pgfmath@parsefunctionnext#1} - -\def\pgfmath@parsefunction@end#1{% - \expandafter\ifx\csname pgfmath@parsefunction@\pgfmath@parsedfunctionname\endcsname\relax% - \pgfmath@reportunknownfunction% - \let\pgfmath@parsefunctionnext\relax% - \else% - \let\pgfmath@parsefunctionnext\pgfmath@executeparsefunction@% - \fi% - \pgfmath@parsefunctionnext#1} - -\def\pgfmath@parsefunction@continue#1{% - \edef\pgfmath@parsedfunctionname{\pgfmath@parsedfunctionname#1}% - \futurelet\pgfmath@parsetoken\pgfmath@parsefunction@@} +\def\pgfmath@stack@pop@operation#1{% + \pgfmath@stack@pop\pgfmath@stack@operation{#1}% + \let\pgfmath@stack@operation@top=\pgfmath@stack@top} -\def\pgfmath@executeparsefunction@{\csname pgfmath@parsefunction@\pgfmath@parsedfunctionname\endcsname} - - -\def\pgfmath@reportunknownfunction{% - \pgfmath@error{Unknown function `\pgfmath@parsedfunctionname'}{}% -} - -% \pgfmath@postfunction -% -% In scanning a function e.g. sin(40), we subvert the normal parsing -% group mechanism by messing around with \pgfmath@parsepostgroup, so -% that after scanning ), the parser doesn't scan for an operator, but -% returns to the macros scanning the function. -% Here the mechanism is restored, and the value of the function is -% stored along with the approprate sign, which was saved earlier. -% -\def\pgfmath@postfunction{% - \let\pgfmath@parsepostgroup\pgfmath@parseoperator% - \edef\pgfmathresult{\pgfmath@sign\pgfmathresult}% - \pgfmath@parseoperator} +% REMARK: This method will be overwritten by the FPU library. Please +% keep any changes consistent. +\def\pgfmath@stack@push@operand#1{% + \pgfmath@stack@push\pgfmath@stack@operand{#1}% + \let\pgfmath@stack@operand@top=\pgfmath@stack@top} + +\def\pgfmath@stack@pop@operand#1{% + \pgfmath@stack@pop\pgfmath@stack@operand{#1}% + \let\pgfmath@stack@operand@top=\pgfmath@stack@top} -% \pgfmath@parsefunction@abs +% Declare an operator for the parser. % -\def\pgfmath@parsefunction@abs{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@abs@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@abs@{% - \expandafter\pgfmathabs@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} - -% \pgfmath@parsefunction@sqrt +% It is not recommended that new operators be created as +% the parser is not fully robust for arbitrary operators. % -\def\pgfmath@parsefunction@sqrt{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@sqrt@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@sqrt@{% - \expandafter\pgfmathsqrt@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% +\def\pgfmathdeclareoperator#1#2#3#4#5{% + \pgfmath@namedef{pgfmath@operator@\string#1}{#1}% + \pgfmath@namedef{pgfmath@operation@\string#1@name}{#2}% + \pgfmath@namedef{pgfmath@operation@\string#1@arity}{#3}% + \pgfmath@namedef{pgfmath@operation@\string#1@#4}{#1}% + \pgfmath@namedef{pgfmath@operation@\string#1@precedence}{#5}% } -% \pgfmath@parsefunction@round -% -\def\pgfmath@parsefunction@round{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@round@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@round@{% - \expandafter\pgfmathround@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +\pgfmathdeclareoperator{+}{add} {2}{infix}{500} +\pgfmathdeclareoperator{-}{subtract}{2}{infix}{500} +\pgfmathdeclareoperator{*}{multiply}{2}{infix}{700} +\pgfmathdeclareoperator{/}{divide} {2}{infix}{700} +\pgfmathdeclareoperator{^}{pow} {2}{infix}{900} -% \pgfmath@parsefunction@floor -% -\def\pgfmath@parsefunction@floor{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@floor@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@floor@{% - \expandafter\pgfmathfloor@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +\pgfmathdeclareoperator{<} {} {1}{prefix} {1} -% \pgfmath@parsefunction@ceil -% -\def\pgfmath@parsefunction@ceil{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@ceil@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@ceil@{% - \expandafter\pgfmathceil@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +\pgfmathdeclareoperator{>} {greater} {2}{infix} {250} +\pgfmathdeclareoperator{<} {less} {2}{infix} {250} +\pgfmathdeclareoperator{==}{equal} {2}{infix} {250} +\pgfmathdeclareoperator{>=}{notless} {2}{infix} {250} +\pgfmathdeclareoperator{<=}{notgreater}{2}{infix} {250} +\pgfmathdeclareoperator{&&}{and} {2}{infix} {200} +\pgfmathdeclareoperator{||}{or} {2}{infix} {200} +\pgfmathdeclareoperator{!=}{notequalto}{2}{infix} {250} +\pgfmathdeclareoperator{!} {not} {1}{prefix}{975} +\pgfmathdeclareoperator{?} {ifthenelse}{3}{infix} {100} +\pgfmathdeclareoperator{:} {@@collect} {2}{infix}{101} -% \pgfmath@parsefunction@sin -% -\def\pgfmath@parsefunction@sin{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@sin@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@sin@{% - \expandafter\pgfmathsin@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +\pgfmathdeclareoperator{!}{factorial}{1}{postfix}{800}% Must be defined after prefix ! operator. +\pgfmathdeclareoperator{r}{deg} {1}{postfix}{600} -% \pgfmath@parsefunction@cos -% -\def\pgfmath@parsefunction@cos{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@cos@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@cos@{% - \expandafter\pgfmathcos@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +\pgfmathdeclareoperator{,}{@collect} {2}{infix} {10} +\pgfmathdeclareoperator{[}{@startindex}{2}{prefix} {7} +\pgfmathdeclareoperator{]}{@endindex} {0}{postfix}{6} +\pgfmathdeclareoperator{(}{@startgroup}{1}{prefix} {5} +\pgfmathdeclareoperator{)}{@endgroup} {0}{postfix}{4} -% \pgfmath@parsefunction@asin -% -\def\pgfmath@parsefunction@asin{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@asin@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@asin@{% - \expandafter\pgfmathasin@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +\pgfmathdeclareoperator{\pgfmath@bgroup}{@startarray}{1}{prefix} {3} +\pgfmathdeclareoperator{\pgfmath@egroup}{@endarray} {1}{postfix}{2}% -% \pgfmath@parsefunction@acos -% -\def\pgfmath@parsefunction@acos{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@acos@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@acos@{% - \expandafter\pgfmathacos@\expandafter{\pgfmathresult}% - \pgfmath@postfunction} - -% \pgfmath@parsefunction@atan -% -\def\pgfmath@parsefunction@atan{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@atan@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@atan@{% - \expandafter\pgfmathatan@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +% Special operators. +\pgfmathdeclareoperator{"}{}{1}{prefix}{1} +\pgfmathdeclareoperator{@}{}{0}{postfix}{0} -% \pgfmath@parsefunction@tan -% -\def\pgfmath@parsefunction@tan{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@tan@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@tan@{% - \expandafter\pgfmathtan@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +% Internal functions. -% \pgfmath@parsefunction@cot +% Begin and end parenthesis (). % -\def\pgfmath@parsefunction@cot{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@cot@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@cot@{% - \expandafter\pgfmathcot@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +\def\pgfmath@startgroup@#1{\edef\pgfmathresult{#1}} +\def\pgfmath@endgroup@{}% Never actually called. -% \pgfmath@parsefunction@sec +% Begin and end array access []. % -\def\pgfmath@parsefunction@sec{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@sec@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@sec@{% - \expandafter\pgfmathsec@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +\def\pgfmath@startindex@#1#2{% + \expandafter\pgfmatharray@#1{#2}% + \expandafter\pgfmath@bgroup@strip\expandafter{\pgfmathresult}% + \ifx\pgfmath@token@let\bgroup% + \expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{\pgfmathresult}}% + \fi} +\def\pgfmath@endindex@{}% Never actually called. -% \pgfmath@parsefunction@cosec +% Begin and end array {}. % -\def\pgfmath@parsefunction@cosec{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@cosec@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@cosec@{% - \expandafter\pgfmathcosec@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} +\def\pgfmath@startarray@#1{\expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{#1}}} +\def\pgfmath@endarray@#1{\expandafter\def\expandafter\pgfmathresult\expandafter{#1}}% Never actually called. -% \pgfmath@parsefunction@rad -% -\def\pgfmath@parsefunction@rad{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@rad@% - \pgfmath@parse@} -\def\pgfmath@parsefunction@rad@{% - \expandafter\pgfmathrad@\expandafter{\pgfmathresult}% - \pgfmath@postfunction}% - -% \pgfmath@parsefunction@rad -% -\def\pgfmath@parsefunction@deg{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@deg@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@deg@{% - \expandafter\pgfmathdeg@\expandafter{\pgfmathresult}% - \pgfmath@postfunction}% - -% \pgfmath@parsefunction@rnd -% -\def\pgfmath@parsefunction@rnd{% - \expandafter\pgfmathrnd% - \expandafter\pgfmath@postfunction} - -% \pgfmath@parsefunction@rand -% -\def\pgfmath@parsefunction@rand{% - \expandafter\pgfmathrand% - \expandafter\pgfmath@postfunction}% - -% \pgfmath@parsefunction@exp -% -\def\pgfmath@parsefunction@exp{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@exp@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@exp@{% - \expandafter\pgfmathexp@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% -} -% \pgfmath@parsefunction@ln -% -\def\pgfmath@parsefunction@ln{% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@ln@% - \expandafter\pgfmath@parse@} -\def\pgfmath@parsefunction@ln@{% - \expandafter\pgfmathln@\expandafter{\pgfmathresult}% - \pgfmath@postfunction% +\def\pgfmath@@collect@#1#2{% + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter% + \pgfmathresult\expandafter\expandafter\expandafter{\expandafter\expandafter\expandafter% + {\expandafter#1\expandafter}\expandafter{#2}}% } - -% \pgfmath@parsefunction@pi +% Collect items separated by ,. % -\def\pgfmath@parsefunction@pi{% - \pgfmathpi% - \pgfmath@postfunction% +\def\pgfmath@collect@#1#2{% + \expandafter\def\expandafter\pgfmath@collect@original\expandafter{#1}% + \expandafter\pgfmath@bgroup@strip\expandafter{#1}% + \ifx\pgfmath@token@let\bgroup% + \ifx\pgfmath@collect@original\pgfmath@bgroup@stripped% + \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmath@bgroup@stripped}% + \else% + \expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{\pgfmath@bgroup@stripped}}% + \fi% + \else% + \expandafter\def\expandafter\pgfmathresult\expandafter{\expandafter{\pgfmath@bgroup@stripped}}% + \fi% + \expandafter\pgfmath@bgroup@strip\expandafter{#2}% + \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter% + \pgfmathresult\expandafter\expandafter\expandafter% + {\expandafter\pgfmathresult\expandafter{\pgfmath@bgroup@stripped}}% } -% \pgfmath@parsefunction@veclen +% Strip braces from a token sequence. % -\def\pgfmath@parsefunction@veclen{% - \expandafter\pgfmath@parsefunction@veclen@} -\def\pgfmath@parsefunction@veclen@(#1,{% - \pgfmathparse@{#1}\edef\pgfmath@firstoperand{\pgfmathresult}% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@veclen@@ - \pgfmath@startparsegroup} -\def\pgfmath@parsefunction@veclen@@{% - \edef\pgfmath@secondoperand{\pgfmathresult}% - \pgfmathveclen@{\pgfmath@firstoperand}{\pgfmath@secondoperand}% - \pgfmath@postfunction} - -% \pgfmath@parsefunction@mod -% -\def\pgfmath@parsefunction@mod{% - \expandafter\pgfmath@parsefunction@mod@} -\def\pgfmath@parsefunction@mod@(#1,{% - \pgfmathparse@{#1}\edef\pgfmath@firstoperand{\pgfmathresult}% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@mod@@ - \pgfmath@startparsegroup} -\def\pgfmath@parsefunction@mod@@{% - \edef\pgfmath@secondoperand{\pgfmathresult}% - \pgfmathmod@{\pgfmath@firstoperand}{\pgfmath@secondoperand}% - \pgfmath@postfunction} - -% \pgfmath@parsefunction@max -% -\def\pgfmath@parsefunction@max{% - \expandafter\pgfmath@parsefunction@max@} -\def\pgfmath@parsefunction@max@(#1,{% - \pgfmathparse@{#1}\edef\pgfmath@firstoperand{\pgfmathresult}% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@max@@ - \pgfmath@startparsegroup} -\def\pgfmath@parsefunction@max@@{% - \edef\pgfmath@secondoperand{\pgfmathresult}% - \pgfmathmax@{\pgfmath@firstoperand}{\pgfmath@secondoperand}% - \pgfmath@postfunction} - -% \pgfmath@parsefunction@min -% -\def\pgfmath@parsefunction@min{% - \expandafter\pgfmath@parsefunction@min@} -\def\pgfmath@parsefunction@min@(#1,{% - \pgfmathparse@{#1}\edef\pgfmath@firstoperand{\pgfmathresult}% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@min@@ - \pgfmath@startparsegroup} -\def\pgfmath@parsefunction@min@@{% - \edef\pgfmath@secondoperand{\pgfmathresult}% - \pgfmathmin@{\pgfmath@firstoperand}{\pgfmath@secondoperand}% - \pgfmath@postfunction} - -% \pgfmath@parsefunction@pow -% -\def\pgfmath@parsefunction@pow{% - \expandafter\pgfmath@parsefunction@pow@} -\def\pgfmath@parsefunction@pow@(#1,{% - \pgfmathparse@{#1}\edef\pgfmath@firstoperand{\pgfmathresult}% - \let\pgfmath@parsepostgroup\pgfmath@parsefunction@pow@@ - \pgfmath@startparsegroup} -\def\pgfmath@parsefunction@pow@@{% - \edef\pgfmath@secondoperand{\pgfmathresult}% - \pgfmathpow@{\pgfmath@firstoperand}{\pgfmath@secondoperand}% - \pgfmath@postfunction}
\ No newline at end of file +\def\pgfmath@bgroup@strip#1{% + \def\pgfmath@bgroup@strip@last{#1}% + \pgfmath@bgroup@@strip{#1}\pgfmath@\pgfmath@@\pgfmath@@@} + +\def\pgfmath@bgroup@strip@#1{% + \def\pgfmath@bgroup@strip@last{#1}% + \pgfmath@bgroup@@strip#1\pgfmath@\pgfmath@@\pgfmath@@@} + +\def\pgfmath@bgroup@pgfmath@{\pgfmath@} + +\def\pgfmath@bgroup@@strip{\futurelet\pgfmath@token@let\pgfmath@bgroup@@@strip} +\def\pgfmath@bgroup@@@strip#1#2#3\pgfmath@@@{% + \ifx\pgfmath@token@let\bgroup% + \def\pgfmath@bgroup@test{#2}% + \ifx\pgfmath@bgroup@test\pgfmath@bgroup@pgfmath@% + \def\pgfmath@next{\pgfmath@bgroup@strip@{#1}}% + \else% + \let\pgfmath@bgroup@stripped=\pgfmath@bgroup@strip@last% + \let\pgfmath@next=\relax% + \fi% + \else% + \pgfmath@bgroup@@@@strip#1#2#3% + \let\pgfmath@next=\relax% + \fi% + \pgfmath@next% +} + +\def\pgfmath@bgroup@@@@strip#1\pgfmath@\pgfmath@@{\def\pgfmath@bgroup@stripped{#1}}% diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex index db2c38fa350..5e353007618 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathutil.code.tex @@ -20,14 +20,15 @@ % #1 - count or dimen. % #2 - a control sequence. % -\newbox\pgfmath@box% \def\pgfmath@ensureregister#1#2{% - \setbox\pgfmath@box\hbox\bgroup% In case #2 is a defined macro. Unlikely, but you never know... + \begingroup% + \setbox0=\hbox\bgroup\begingroup% In case #2 is a defined macro. Unlikely, but you never know... \afterassignment\pgfmath@@ensureregister% \noexpand#20.0pt\let\pgfmath@temp\relax\relax\pgfmath@#2#1\pgfmath@} \def\pgfmath@@ensureregister#1#2\pgfmath@#3#4#5\pgfmath@{% - \egroup% + \endgroup\egroup% + \endgroup% \ifx#4c% \ifx#1.% Already a count register. \else% @@ -181,8 +182,18 @@ \let\pgfmath@PackageError\PackageError% \fi% -\def\pgfmath@error#1#2{\pgfmath@PackageError{PGF Math}{#1}{#2}} -\def\pgfmath@warning#1{\pgfmath@PackageWarning{PGF Math}{#1}} +\def\pgfmath@error#1#2{% + \pgfmath@PackageError{PGF Math}{% + #1% + \pgfutil@ifundefined{pgfmath@expression}{}{ (in '\pgfmath@expression')}% + }{#2}% +} +\def\pgfmath@warning#1{% + \pgfmath@PackageWarning{PGF Math}{% + #1% + \pgfutil@ifundefined{pgfmath@expression}{}{ (in '\pgfmath@expression')}% + }% +} % \pgfmath@pt % @@ -208,6 +219,9 @@ \def\pgfmath@gobbleone#1{}% +\def\pgfmath@namedef#1{\expandafter\def\csname#1\endcsname} +\def\pgfmath@nameedef#1{\expandafter\edef\csname#1\endcsname} + % \pgfmathloop % % A version of the standard TeX and LaTeX @@ -233,9 +247,6 @@ % \pgfmath@returnone % -% \edef \pfgmathresult to the value of #1 after the end -% of a group, which *must directly follow*. -% % #1 - a dimension representing a number or dimension. % % Changed by TT: made faster and simpler since it is used @@ -248,11 +259,7 @@ \expandafter\endgroup\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmath@temp}% } - -% \pgfmath@returntwo -% -% Removed by TT: not used. - +\let\pgfmathreturn=\pgfmath@returnone % \pgfmath@smuggleone % @@ -263,3 +270,5 @@ % \def\pgfmath@smuggleone#1\endgroup{% \expandafter\endgroup\expandafter\def\expandafter#1\expandafter{#1}} + +\let\pgfmathsmuggle=\pgfmath@smuggleone |