diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/pgfplots/pgfmathlog.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/pgfplots/pgfmathlog.sty | 262 |
1 files changed, 27 insertions, 235 deletions
diff --git a/Master/texmf-dist/tex/latex/pgfplots/pgfmathlog.sty b/Master/texmf-dist/tex/latex/pgfplots/pgfmathlog.sty index 81e252bbe27..9e9b57ea137 100644 --- a/Master/texmf-dist/tex/latex/pgfplots/pgfmathlog.sty +++ b/Master/texmf-dist/tex/latex/pgfplots/pgfmathlog.sty @@ -36,243 +36,14 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -\ProvidesPackage{pgfmathlog}[2008/26/01 Version 0.9.] +\ProvidesPackage{pgfmathlog}[2008/02/17 Version 0.9.4] \RequirePackage{pgf}[2007/01/01] +\RequirePackage{sciformat}[2008/02/17] +\RequirePackage{pgfplotshelpers}[2008/02/17] -\RequirePackage{pgfplotshelpers}[2008/31/01] - -% Computes a normalised floating point representation for #1 of the -% form -% [+-]X.XXXXXXX*10^C -% where -% X.XXXXXX is a mantisse with first number != 0 -% and C is a count. -% -% 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 a -possibly non-normalized- number representation. Accepted input -% format is -% [+-]XXXXX.XXXXXX -% [+-]XXXXX.XXXXXXeXXXX -% [+-]0.0000XXXXXX -% [+-]0.0000XXXXXXeXXXX -% NOT accepted input format is -% [+-]XXXXX [the period is missing] -% [+-]XXXXXe10 [the period is missing] -% [+-]0000.XXXXXX [leading zeros not supported] -% [+-]XXXXX.XXXXXXEXXXXX [E notation not yet implemented] -% #2 a macro name. \def#2{.....} will be used to assign the mantisse. -% #3 a macro name. \def#3{.....} will be used to assign the exponent (base 10). -% -% Example: -% \def\normalize#1{% -% \pgfmathnormalisedfloatingpoint#1\to\M\powten\E -% \[ #1 \mapsto \M\cdot 10^{\E} \] -% } -% \normalize{123.41251}% -% \normalize{3.26101452e-06}% +% See \sciparse docs \def\pgfmathnormalisedfloatingpoint#1\to#2\powten#3{% - \pgfmathnormalisedfloatingpoint@impl@possibly@signed#1\to#2\powten{#3}% -} - -% first character MAY be + or -. This is checked, then -% \pgfmathnormalisedfloatingpoint@impl@positive will be called for the -% absolute value. The sign is inserted afterwards. -\def\pgfmathnormalisedfloatingpoint@impl@possibly@signed#1#2\to#3\powten#4{% - \def\pgfmathlogTMP{#1}% - \def\pgfmathlogTMPB{-}% - \if\pgfmathlogTMP\pgfmathlogTMPB - \pgfmathnormalisedfloatingpoint@impl@positive@possibly@noperiod#2.\to#3\powten{#4}% - \edef#3{-#3}% - \else - \def\pgfmathlogTMPB{+}% - \if\pgfmathlogTMP\pgfmathlogTMPB - \pgfmathnormalisedfloatingpoint@impl@positive@possibly@noperiod#2.\to#3\powten{#4}% - \else - \pgfmathnormalisedfloatingpoint@impl@positive@possibly@noperiod#1#2.\to#3\powten{#4}% - \fi - \fi -} - -% XXXX -> XXXX.0 -% XXXX.YYY -> XXXX.YYYY -\def\pgfmathnormalisedfloatingpoint@impl@positive@possibly@noperiod#1.#2\to#3\powten#4{% - %\tracingmacros=2\tracingcommands=2 - \def\pgfmathlogTMP{#2}% - \ifx\pgfmathlogTMP\empty - \pgfmathnormalisedfloatingpoint@impl@positive@noperiod@possibly@SCI#1e\to#3\powten{#4}% - \else - \expandafter\pgfmathnormalisedfloatingpoint@impl@positive\pgfmathlog@pop@last@of@two@dots#1.#2\to#3\powten{#4}% - \fi -} -\def\pgfmathlog@pop@last@of@two@dots#1.#2.{#1.#2}% - -\def\pgfmathnormalisedfloatingpoint@impl@positive@noperiod@possibly@SCI#1e#2\to#3\powten#4{% - \def\pgfmathlogTMP{#2}% - \ifx\pgfmathlogTMP\empty - % this case applies to - % 1234 -> 1234.0 - \pgfmathnormalisedfloatingpoint@impl@positive#1.0\to#3\powten{#4}% - \else - % this case applies to - % 1e1 -> 1.0e1 - % in this case, #1e#2 = 1e1e, so we have to discard a suffix 'e'. - \edef\pgfmathlogTMP{#1.0e\pgfmathlog@popsuffix@e@expansion#2}% - \expandafter\pgfmathnormalisedfloatingpoint@impl@positive\pgfmathlogTMP\to#3\powten{#4}% - \fi -} - -% XXXXX.XXXXX -> X.XXXXXXX * 10^4 -% 0.0000XXXXX -> X.XXXX * 10^{-5} -% -% or -% XXXX.XXXXXeYYY -> X.XXXXXX* 10^{3+YYY} -% 0.0000XXXXeYYY -> X.XXX* 10^{-5+YYY} -% -% this version does not accept a sign. A period is required. -\def\pgfmathnormalisedfloatingpoint@impl@positive#1#2.#3\to#4\powten#5{% -% \begingroup -% FIXME! restore variables!! - %\tracingmacros=2\tracingcommands=2 - %\tracingmacros=0\tracingcommands=0 - \pgfmathnormalisedfloatingpoint@positive@getexisting@exponent@e#3e\preexponentto\preexponentstring\exponenttocount\c@pgf@counta - % will \c@pgf@counta will be initialised in the line above - % \c@pgf@counta=0 - \ifnum#1=0 - % the case 0.0000XXXX - % does also handle 0.0000XXXXeXXX - \def\pgfmathlogTMP{#2}% - \ifx\pgfmathlogTMP\empty - \c@pgf@countb=0 - \expandafter\pgfmathlog@count@leading@zeros\preexponentstring\to\c@pgf@countb - \advance\c@pgf@countb by1 - \advance\c@pgf@counta by-\c@pgf@countb - \edef#5{\the\c@pgf@counta}% - \expandafter\pgfmathlog@assignmantisse\preexponentstring\to#4\countdownzerosfrom\c@pgf@countb - \else - % the case 000.0000XXXXX - % is not allowed and does not make sense. - \errmessage{INVALID NUMBER FORMAT: leading zeros 00*.* not supported yet}% - \fi - \else - % the case NXXXXX.XXXXXXX - % or NXXXXXX.XXXXXXeXXXX - % where N in [1-9] - \pgfmathlog@strlen#1#2\to\c@pgf@counta - \advance\c@pgf@counta by-1 - \edef#4{#1.#2\preexponentstring}% - \edef#5{\the\c@pgf@counta}% - \fi - %\tracingmacros=0\tracingcommands=0 -% \endgroup -} - -% parses scientific notation and returns the exponent and everything -% before the exponent like -% -% XXXXXXXeYYYY -> \def#2{XXXXXXX} #3=YYYY -% or -% XXXXXXXXe -> \def#2{XXXXXXXX} #3=0 -% -% Examples: -% - \pgfmathnormalisedfloatingpoint@exponent@e123456e\preexponentto\M\exponenttocount\acount -% \M->123456 -% \acount=0 -% Please note that the input was 123456e -> at least 'e' is expected! -% -% - \pgfmathnormalisedfloatingpoint@exponent@e123456e-10e\preexponentto\M\exponenttocount\acount -% \M->123456 -% \acount=-10 -% Again, the suffix 'e' is REQUIRED. This allows to reduce \ifs. -\def\pgfmathnormalisedfloatingpoint@positive@getexisting@exponent@e#1e#2\preexponentto#3\exponenttocount#4{% - \def#3{#1}% - \def\pgfmathlogTMP{#2}% - \ifx\pgfmathlogTMP\empty - #4=0 - \else - \pgfmathlog@popsuffix@e#2\tocount{#4}% - \fi -} - -% XXXXXe -> #2=XXXXX where X in [+-0-9]. -\def\pgfmathlog@popsuffix@e#1e\tocount#2{% - #2=#1 -} - -\def\pgfmathlog@popsuffix@e@expansion#1e{% - #1% -}% - -% 00000XXXXXX -> X.XXXXX -% Inputs: -% #1 = 00000XXXXXX -% #2 a macro name -% #3 a count in which the number of zeros plus one is contained (i.e. -% the number of shifts). -\def\pgfmathlog@assignmantisse#1\to#2\countdownzerosfrom#3{% - \toks0={#1}% - \loop - \ifnum#3=1 - \else - \expandafter\pgfmathlog@popfirst\the\toks0\to{\toks0}% - \advance#3 by-1 - \repeat - \edef\pgfmathlog@assignmantisseTMP{\the\toks0}% - \ifx\pgfmathlog@assignmantisseTMP\empty - % The case 0.0 * 10^0 - \def#2{0.0}% - \else - \expandafter\pgfmathlog@insertperiod\the\toks0\to{#2}% - \fi -} - -% XXXXXX -> X.XXXXX into #3 -\def\pgfmathlog@insertperiod#1#2\to#3{% - \def\pgfmathlogTMP{#2}% - \ifx\pgfmathlogTMP\empty - \def#3{#1.0}% - \else - \def#3{#1.#2}% - \fi -} - -% discards the first token. -\def\pgfmathlog@popfirst#1#2\to#3{% - #3={#2}% -} - -% adds the string length of #1#2 into the count register #3. -% -% The register won't be initialised to zero! -\def\pgfmathlog@strlen#1#2\to#3{% - \advance#3 by1 - \def\pgfmathlogTMP{#2}% - \ifx\pgfmathlogTMP\empty - \else - \pgfmathlog@strlen#2\to{#3}% - \fi -} - -% Adds the number of leadings zeros of #1#2 into the count register -% #3. -% -% The register won't be initialised to zero! -\def\pgfmathlog@count@leading@zeros#1#2\to#3{% - \ifnum#1=0 - \advance#3 by1 - \def\pgfmathlogTMP{#2}% - \ifx\pgfmathlogTMP\empty - \else - \pgfmathlog@count@leading@zeros#2\to{#3}% - \fi - \fi + \sciparse#1\to#2\powten{#3}% } % Evaluates the natural logarithm, log(x) for 0.1<=x<=1. @@ -386,7 +157,7 @@ \def\pgfmathlog@newton#1{% \begingroup% % compute #1 = M*10^E with normalised mantisse M = [+-]*[1-9].XXXXX - \pgfmathnormalisedfloatingpoint#1\to\newtoninput@mantisse\powten\newtoninput@exponent + \sciparse#1\to\newtoninput@mantisse\powten\newtoninput@exponent % % Now, compute log(#1) = log(M) + E*log(10) % \message{EVAL log(#1) = log(\newtoninput@mantisse) + \newtoninput@exponent*log(10) mit newton STARTS:}% @@ -421,3 +192,24 @@ \endgroup% } +% Usage: +% \pgfmathapproxequalto@macro\argone\argtwo\result +% +% -> will set \resulttrue or \resultfalse +% -> check with \ifresult +\def\pgfmathlog@approxequalto@macro#1#2#3{% + \begingroup% + \expandafter\pgfmath@x#1pt\relax% + \expandafter\pgfmath@y#2pt\relax% + \advance\pgfmath@x-\pgfmath@y% + \ifdim\pgfmath@x<0pt + \multiply\pgfmath@x by-1 + \fi + \ifdim\pgfmath@x<0.0001pt\relax% + \expandafter\aftergroup\csname #3true\endcsname + \else% + \expandafter\aftergroup\csname #3false\endcsname + \fi% + \endgroup% +} + |