diff options
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/math')
7 files changed, 243 insertions, 22 deletions
diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex index 727af976f8d..34a5e406a68 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex @@ -427,8 +427,29 @@ % 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{% +\def\pgfmathfloatvalueof#1{\expandafter\pgfmathfloatvalueof@@#1@@}% + +% Make it fool proof such that the following arguments work: +% \pgfmathfloatvalueof{1Y1.0e1} -> 1.0e1 +% \pgfmathfloatvalueof{2Y1.0e1} -> -1.0e1 +% and wrong arguments as well: +% \pgfmathfloatvalueof{1} -> 1 +% \pgfmathfloatvalueof{1e2} -> 1e2 +\def\pgfmathfloatvalueof@@#1#2{% + \if#2Y% + % keep in mind that \pgfmathfloatvalueof should be expandable! + % We must not use \let here. Let's hope that #1 and #2 are + % single tokens (not something which was enclosed by curly + % braces...) + \expandafter\pgfmathfloatvalueof@@@\expandafter#1\expandafter#2% + \else + % Oh - no float!? Ok, we cannot report errors in this context. + % So: make it a feature and return the input argument as-is. + % Might be useful, in fact... + \expandafter\pgfmathfloatvalueof@abort\expandafter#1\expandafter#2% + \fi +} +\def\pgfmathfloatvalueof@@@#1Y#2e#3]@@{% \ifcase#1 % 0.0e0% \or @@ -440,6 +461,8 @@ \or -inf% \fi }% +\def\pgfmathfloatvalueof@abort#1@@{#1}% + % Rounds a fixed point number #1 to \pgfmathfloat@round@precision digits precision and returns @@ -907,6 +930,7 @@ \newif\ifpgfmathprintnumber@showpositive \newif\ifpgfmathprintnumber@frac@warn \newif\ifpgfmathprintnumber@frac@whole +\newif\ifpgfmathparsenumber@comma@as@period \long\def\pgfmathfloatfrac@verbatim#1#2{#1/#2}% @@ -987,6 +1011,8 @@ showpos/.default=true, print sign/.is if=pgfmathprintnumber@showpositive, print sign/.default=true, + read comma as period/.is if=pgfmathparsenumber@comma@as@period, + read comma as period/.default=true, skip 0./.is if=pgfmathprintnumberskipzeroperiod, skip 0./.default=true, skip 0.= false, @@ -2245,6 +2271,9 @@ \pgfmathfloatcreate{0}{0.0}{0}% }% },% + /pgf/fpu/handlers/invalid separator/.code 2 args={% + \pgfmath@error{Could not parse input '#1' as a floating point number, sorry. The unreadable part was near the decimal separator '#2'. Do you need the option 'read comma as period'?}{}% + }, /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'.}{}% }, @@ -2317,6 +2346,30 @@ \expandafter\def\csname pgffltA@.\endcsname{% read '.9' like '0.9' \pgfmathfloat@a@E=-1 \pgfflt@leadingzero@foundperiod}% +\expandafter\def\csname pgffltA@,\endcsname{% read ',9' like '0,9' + \pgfmathfloat@frenchinput{% + \pgfmathfloat@a@E=-1 + \pgfflt@leadingzero@foundperiod + }% +}% + +\def\pgfmathfloat@frenchinput#1{% + \ifpgfmathparsenumber@comma@as@period + \def\pgf@marshal{#1}% + \expandafter\pgf@marshal + \else + \expandafter\pgfflt@error@separator\expandafter,% + \fi +}% +\def\pgfflt@error@separator#1\pgfflt@EOI{% + \begingroup + \pgfmathfloat@a@Mtok={#1}% + \xdef\pgfmathfloat@glob@TMP{% + \noexpand\pgfmathfloatparsenumber@handleerror + {invalid separator}{\pgfmathresult}{\the\pgfmathfloat@a@Mtok}}% + \endgroup + \pgfmathfloat@glob@TMP +}% \def\pgfflt@finish#1\pgfflt@EOI{} @@ -2374,6 +2427,12 @@ \expandafter\def\csname pgffltB@.\endcsname{% \pgfmathfloat@a@E=-1 \pgfflt@leadingzero@foundperiod}% +\expandafter\def\csname pgffltB@,\endcsname{% + \pgfmathfloat@frenchinput{% + \pgfmathfloat@a@E=-1 + \pgfflt@leadingzero@foundperiod + }% +}% \expandafter\def\csname pgffltB@e\endcsname{% \pgfmathfloat@a@S=0\relax% \pgfmathfloat@a@Mtok={0.0}% @@ -2438,6 +2497,7 @@ \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@,\endcsname{\pgfmathfloat@frenchinput{\pgfflt@finish@number@after@period}}% \expandafter\def\csname pgffltD@e\endcsname{\pgfflt@readexponent}% FIXME : inlining? \let\pgffltD@E=\pgffltD@e \expandafter\def\csname pgffltD@\pgfflt@EOI\endcsname{}% NOP @@ -2497,6 +2557,7 @@ \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? +\expandafter\def\csname pgffltE@,\endcsname{\pgfmathfloat@frenchinput{\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 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 index 99f8ccbb2c0..b6ac16c8bf3 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex @@ -308,6 +308,22 @@ \endgroup% } +% sign(x) +\pgfmathdeclarefunction{sign}{1}{% + \begingroup + \ifdim#1pt>0sp % + \def\pgfmathresult{1}% + \else + \ifdim#1pt=0sp % + \def\pgfmathresult{0}% + \else + \def\pgfmathresult{-1}% + \fi + \fi + \pgfmath@smuggleone\pgfmathresult + \endgroup +} + % e constant. % \pgfmathdeclarefunction{e}{0}{\def\pgfmathresult{2.718281828}} @@ -503,6 +519,12 @@ \endgroup% } +% This is needed since \pgfmathlog2 and \pgfmathlog10 are not legal macro names +\expandafter\let\expandafter\pgfmathlogtwo\csname pgfmathlog2\endcsname +\expandafter\let\expandafter\pgfmathlogtwo@\csname pgfmathlog2@\endcsname +\expandafter\let\expandafter\pgfmathlogten\csname pgfmathlog10\endcsname +\expandafter\let\expandafter\pgfmathlogten@\csname pgfmathlog10@\endcsname + % exp function. % \pgfmathdeclarefunction{exp}{1}{% diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex index 55ef700c14d..b35e3d2595b 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.code.tex @@ -28,7 +28,9 @@ \expandafter\ifx\csname pgfmath@function@#1\endcsname\relax% \pgfmath@error{The function `#1' does not exist}{}% \else% - \pgfmath@namedef{pgfmath#1@}{#2}% + % was: \pgfmath@namedef{pgfmath#1@}{#2}% TT + \edef\pgf@marshal{\noexpand\pgfmathdeclarefunction*{#1}{\csname pgfmath@operation@#1@arity\endcsname}}% + \pgf@marshal{#2}% \fi% } @@ -164,13 +166,21 @@ \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}}% + \noexpand\pgfmathnotifynewdeclarefunction{\pgfmath@local@name}{\the\c@pgf@counta}% + {\the\pgfmath@toks}% }% \endgroup% \pgfmath@local@temp% } +% #1: the name +% #2: the number of arguments <n> +% #3: a math expression containing '#1', '#2', ... ,'#'<n> +% This callback is overwritten by pgflibraryluamath. +\def\pgfmathnotifynewdeclarefunction#1#2#3{% + \pgfmathdeclarefunction{#1}{#2}{\pgfmathparse{#3}}% +}% + \def\pgfmath@local@function@@body#1,{% \def\pgfmath@local@test{#1}% \ifx\pgfmath@local@test\pgfutil@empty% 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 index e00786d7a37..9b807992787 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.misc.code.tex @@ -339,3 +339,11 @@ \expandafter\pgfmathmin@\expandafter{\pgfmathresult}% } + + +% scalar function. +% +\pgfmathdeclarefunction{scalar}{1}{% + \def\pgfmathresult{#1}% + \global\pgfmathunitsdeclaredfalse% +}
\ No newline at end of file diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex index 2811d67c101..44b8ef8f6ef 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.random.code.tex @@ -39,7 +39,11 @@ % % #1 -> the new seed. % -\def\pgfmathsetseed#1{\pgfmathparse{#1}\expandafter\pgfmath@setseed\pgfmathresult.0\pgfmath@stop}% +\def\pgfmathsetseed#1{% + % Attention pgflibraryluamath.code.tex relies on the fact that + % this method also modifies \pgfmathresult: + \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, @@ -236,4 +240,4 @@ \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 + diff --git a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code.tex b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code.tex index 02726731357..aa98934e807 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfunctions.trigonometric.code.tex @@ -18,6 +18,23 @@ % \pgfmathdeclarefunction{pi}{0}{\def\pgfmathresult{3.141592654}} +\pgfkeys{ + /pgf/trig format/.is choice, + % attention: the luamath library will hook into these code keys. + /pgf/trig format/deg/.code={\def\pgfmath@trig@format@choice{0}}, + /pgf/trig format/rad/.code={\def\pgfmath@trig@format@choice{1}}, + /pgf/trig format/deg, +} + +% Executes #1 if 'trig format=deg' and #2 otherwise. +\def\pgfmathiftrigonometricusesdeg#1#2{% + \if0\pgfmath@trig@format@choice + #1% + \else + #2% + \fi +}% + % \pgfmathradians % (for comptability with 1.18 beta, will be deprecated) % @@ -38,11 +55,15 @@ \pgfmathdeclarefunction{deg}{1}{% \begingroup% \expandafter\pgfmath@x#1pt\relax% - \pgfmath@x57.29577\pgfmath@x\relax% 57.29577 = 360/(2*pi) + \pgfmath@scale@rad@to@deg\pgfmath@x \pgfmath@returnone\pgfmath@x% \endgroup% }% +\def\pgfmath@scale@rad@to@deg#1{% + #1=57.29577#1\relax% 57.29577 = 360/(2*pi) +}% + % \pgfmathrad % % Convert #1 from degrees to radians. @@ -50,12 +71,16 @@ \pgfmathdeclarefunction{rad}{1}{% \begingroup% \expandafter\pgfmath@x#1pt\relax% - \pgfmath@x3.14159\pgfmath@x% - \divide\pgfmath@x180\relax% + \pgfmath@scale@deg@to@rad\pgfmath@x \pgfmath@returnone\pgfmath@x% \endgroup% }% +\def\pgfmath@scale@deg@to@rad#1{% + #1=3.14159#1% + \divide#1180\relax% +}% + % \pgfmathsin % % Calculate the sine of #1 (in degrees). @@ -66,6 +91,10 @@ % \begingroup% \expandafter\pgfmath@x#1pt\relax% + \if1\pgfmath@trig@format@choice + % trig format=rad + \pgfmath@scale@rad@to@deg\pgfmath@x + \fi \advance\pgfmath@x-90pt\relax% \afterassignment\pgfmath@gobbletilpgfmath@ \expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@ @@ -108,6 +137,10 @@ % \begingroup% \expandafter\pgfmath@x#1pt\relax% + \if1\pgfmath@trig@format@choice + % trig format=rad + \pgfmath@scale@rad@to@deg\pgfmath@x + \fi \afterassignment\pgfmath@gobbletilpgfmath@% \expandafter\c@pgfmath@counta\the\pgfmath@x\relax\pgfmath@% \divide\c@pgfmath@counta360\relax% @@ -229,6 +262,10 @@ \ifdim\pgfmath@xa<0pt\relax% \pgfmath@x-\pgfmath@x% \fi% + \if1\pgfmath@trig@format@choice + % trig format=rad + \pgfmath@scale@deg@to@rad\pgfmath@x + \fi \pgfmath@returnone\pgfmath@x% \endgroup% } @@ -281,6 +318,10 @@ \pgfmath@x-\pgfmath@x% \advance\pgfmath@x by180pt\relax% \fi% + \if1\pgfmath@trig@format@choice + % trig format=rad + \pgfmath@scale@deg@to@rad\pgfmath@x + \fi \pgfmath@returnone\pgfmath@x% \endgroup% } @@ -310,6 +351,10 @@ \ifdim\pgfmath@xa<0pt\relax% \pgfmath@x-\pgfmath@x% \fi% + \if1\pgfmath@trig@format@choice + % trig format=rad + \pgfmath@scale@deg@to@rad\pgfmath@x + \fi \pgfmath@returnone\pgfmath@x% \endgroup% } @@ -317,13 +362,15 @@ \pgfmathdeclarefunction{atan2}{2}{% % Note: first parameter is y (!), second is x (!) \begingroup% + \let\pgfmath@trig@format@choice@@=\pgfmath@trig@format@choice + \def\pgfmath@trig@format@choice{0}% \pgfmath@y=#1pt\relax% \ifdim\pgfmath@y<0pt\relax% \pgfmath@y=-\pgfmath@y% \fi% \ifdim\pgfmath@y<0.001pt\relax% \ifdim#2pt<0pt\relax% - \pgfmath@x=-180pt\relax% + \pgfmath@x=+180pt\relax% \else% \ifdim#2pt>0pt\relax% \pgfmath@x=0pt\relax% @@ -355,6 +402,10 @@ \pgfmath@x=-\pgfmath@x% \fi% \fi% + \if1\pgfmath@trig@format@choice@@ + % trig format=rad + \pgfmath@scale@deg@to@rad\pgfmath@x + \fi \pgfmath@returnone\pgfmath@x% \endgroup% } 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 71843fb2499..e2c78d1fdf4 100644 --- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex +++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathparser.code.tex @@ -25,10 +25,10 @@ \pgfmath@parse@next} \def\pgfmath@catcodes{% Maybe unecessary. - \catcode`\==12% - \catcode`\,=12% - \catcode`\|=12% - \catcode`\&=12% + \catcode`\==12 % + \catcode`\,=12 % + \catcode`\|=12 % + \catcode`\&=12 % } \def\pgfmathqparse{% @@ -38,6 +38,77 @@ \pgfmathparse@} \def\pgfmathparse@#1{% + % No (math) units yet. + \global\pgfmathunitsdeclaredfalse + \global\pgfmathmathunitsdeclaredfalse + % Expand expression so any reamining CSs are registers + % or box dimensions (i.e. |\wd|, |\ht|, |\dp|). + \edef\pgfmath@expression{#1}% + % + \expandafter\pgfmathparse@trynumber@loop\pgfmath@expression\pgfmath@parse@stop + % + % this here is the _real_ parser. it is invoked by + % \pgfmathparse@trynumber@loop if that says "this is no number" + %\pgfmathparse@@\pgfmath@parse@stop% +} + +\def\pgfmath@parse@stop{\pgfmath@parse@stop}% equals only itsself + +\def\pgfmathparse@trynumber@token{numeric} +\begingroup +\def\\{\global\let\pgf@let@space@token= } \\ % now, \pgf@let@space@token is a space token +\endgroup + +% This a "fast-lane": if the expressions consist merely of number +% tokens, we can simply return the number as-is. +% +% This is significantly faster and should resemble the 80% use-case. +% +% #1 a single token +\def\pgfmathparse@trynumber@loop{% + \futurelet\pgfmath@token@let\pgfmathparse@trynumber@loop@ +}% +\def\pgfmathparse@trynumber@loop@#1{% + \ifx\pgfmath@token@let\pgf@let@space@token + % Hm. we found a white space... and we have no support for + % trimming. That means we have to assume that the white space + % occurred somewhere in the middle - and fall back to the + % expensive method. + \def\pgfmath@parse@next{\pgfmathparse@@#1}% + \else + \ifx\pgfmath@token@let\bgroup% + % oh! We found '{' #1. + % Well, these braces appear to be special; fall back to + % the complicated routine... + \let\pgfmath@parse@next=\pgfmathparse@@ + \else + \ifx\pgfmath@token@let\pgfmath@parse@stop + % Ah: we have passed the check! The expression consists only + % of 0123456789. , so do not parse anything and return it + % as-is! + \let\pgfmath@parse@next=\pgfmathparse@expression@is@number + \else + \expandafter\ifx\csname pgfmath@token@\pgfmathparse@trynumber@token @\string#1\endcsname\relax% + % hm. It is none of 0123456789. + \let\pgfmath@parse@next=\pgfmathparse@@ + \else + % continue... we only found one of 0123456789. so + % far... + \let\pgfmath@parse@next=\pgfmathparse@trynumber@loop + \fi + \fi + \fi + \fi + \pgfmath@parse@next +}% + +\def\pgfmathparse@expression@is@number{% + \let\pgfmathresult=\pgfmath@expression + \pgfmath@smuggleone\pgfmathresult% + \endgroup + \ignorespaces +}% +\def\pgfmathparse@@#1\pgfmath@parse@stop{% % We are inside a group (opened in |\pgfmathparse| or % |\pgfmathqparse|). % Stuff for calc compatiability. @@ -50,12 +121,6 @@ \let\depthof=\pgfmath@calc@depthof % Restore font (defined in pgfmathutil.code.tex) \pgfmath@selectfont - % Expand expression so any reamining CSs are registers - % or box dimensions (i.e. |\wd|, |\ht|, |\dp|). - \edef\pgfmath@expression{#1}% - % No (math) units yet. - \global\pgfmathunitsdeclaredfalse - \global\pgfmathmathunitsdeclaredfalse % Set up stack. \pgfmath@stack@operation={{}{}{}}% \pgfmath@stack@operand={{}{}{}}% @@ -896,4 +961,4 @@ % Local Variables: % tab-width: 2 -% End:
\ No newline at end of file +% End: |