summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex')
-rw-r--r--Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex245
1 files changed, 224 insertions, 21 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 722856f3628..727af976f8d 100644
--- a/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex
+++ b/Master/texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex
@@ -10,7 +10,28 @@
% This file contains methods for basic floating point arithmetics, rounding
% to arbitrary precision and number pretty printing.
%
-% Version 1.0 2008/09/17
+
+
+\pgfkeys{
+ % The bug 3430171 (wrong minus sign spacing in pgfmathprintnumber)
+ % has been fixed in 2.10 CVS. Since it changes the spacing, its
+ % effects can be undone with this compatibility switch.
+ /pgf/compat/number printer/.is choice,
+ /pgf/compat/number printer/2.10/.code={%
+ \def\pgfmathprintnumber@begingroup{\bgroup}%
+ \def\pgfmathprintnumber@endgroup{\egroup}%
+ },
+ % I do not know the version number of the next release at this
+ % time. Please be so kind and KEEP THIS NAME INTACT. Add an alias
+ % if needed.
+ /pgf/compat/number printer/next after 2.10/.code={%
+ \def\pgfmathprintnumber@begingroup{\begingroup}%
+ \def\pgfmathprintnumber@endgroup{\endgroup}%
+ },
+ % activate the fix by default.
+ /pgf/compat/number printer/next after 2.10,%
+}
+
\global\newif\ifpgfmathfloatcomparison
\newif\ifpgfmathfloatroundhasperiod
@@ -34,6 +55,13 @@
% can be changed with options.
\def\pgfmathfloat@round@precision{2}
+% I introduced this to acces the "original" precision in case a
+% formatted changes it locally... in this case, the formatter may
+% overwrite \pgfmathfloat@round@precision@orig to provide the original
+% one.
+% The default implementation here does nothing:
+\def\pgfmathfloat@round@precision@orig{\pgfmathfloat@round@precision}%
+
\gdef\pgfmathfloat@glob@TMP{}
@@ -472,7 +500,7 @@
\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
+ \c@pgf@counta=#4\relax % it is the exponent here.
\ifnum#2=0
\c@pgf@counta=0
\fi
@@ -511,20 +539,30 @@
\else
\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI
\fi
+ \ifpgfmathprintnumber@thousand@sep@in@fractional
+ \let\pgfmathresultfractional\pgfutil@empty%
+ \pgfmathprintnumber@thousand@sep@in@fractional#2MMMM\@@
+ \else
+ \def\pgfmathresultfractional{#2}%
+ \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 }%
+ \toks2=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP}%
+ \toks3=\expandafter{\pgfmathresultfractional}%
+ \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 \the\toks3 }%
\endgroup
\let\pgfmathresult=\pgfmathfloat@glob@TMP
}%
+
+% assigns \pgfmathresult such that it contains the formatted result.
+% It assumes that none of the following tokens contains a period.
\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
+ \ifnum\c@pgf@counta<0\relax % exponent of the number in this context
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}%
\else
@@ -561,7 +599,7 @@
\fi
\fi
\fi
- \ifnum\c@pgf@counta>0
+ \ifnum\c@pgf@counta>0 % \c@pgf@counta = N MOD 3 in this context
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
\expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printtrailingdigits\pgfmathfloat@loc@TMPb
}%
@@ -573,7 +611,8 @@
\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
}
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printtrailingdigits#1#2{%
- \ifcase\c@pgf@counta
+ \ifcase\c@pgf@counta % = N MOD 3 in this context
+ % does not happen per construction
\or
\expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}%
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
@@ -585,7 +624,7 @@
\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird%
}%
\fi
- \ifnum\c@pgf@countb>0\relax
+ \ifnum\c@pgf@countb>0\relax % \c@pgf@countb = N DIV 3 in this context
\begingroup
\toks0=\expandafter{\pgfmathresult}%
\toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP}%
@@ -625,6 +664,32 @@
\fi
\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
}
+
+% \pgfmathprintnumber@thousand@sep@in@fractional 01234525MMMM\@@
+% ->
+% 012<sep>345<sep>25
+\def\pgfmathprintnumber@thousand@sep@in@fractional#1#2#3#4{%
+ \if#4M%
+ % Ok, no further separator
+ \def\pgfmathprint@next{\pgfmathprintnumber@thousand@sep@in@fractional@finish#1#2#3#4}%
+ \else
+ \begingroup
+ \toks0=\expandafter{\pgfmathresultfractional}%
+ \toks1={#1#2#3}%
+ \toks2=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP}%
+ \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 }%
+ \endgroup
+ \let\pgfmathresultfractional=\pgfmathfloat@glob@TMP
+ \def\pgfmathprint@next{\pgfmathprintnumber@thousand@sep@in@fractional#4}%
+ \fi
+ \pgfmathprint@next
+}%
+\def\pgfmathprintnumber@thousand@sep@in@fractional@finish#1M{%
+ \expandafter\def\expandafter\pgfmathresultfractional\expandafter{\pgfmathresultfractional #1}%
+ \pgfmathprintnumber@thousand@sep@in@fractional@finish@
+}%
+\def\pgfmathprintnumber@thousand@sep@in@fractional@finish@#1\@@{}%
+
\def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall#1{%
\def\pgfmathfloat@loc@TMPb{#1}%
\let\pgfmathfloat@loc@TMPc=\pgfutil@empty
@@ -662,7 +727,7 @@
% The default style to display fixed point numbers.
%
-% It does not apply numerics, but it is responsable to typeset the
+% It does not apply numerics, but it is responsable for typesetting the
% rounded number.
% It can access the \ifpgfmathfloatroundhasperiod boolean.
%
@@ -753,21 +818,23 @@
% #1: the part before the exponent code
% #2: the part for the exponent code.
\def\pgfmathfloatrounddisplaystyle@shared@impl@#1#2{%
- {\toks0={#1}%
+ \pgfmathprintnumber@begingroup
+ \toks0={#1}%
\toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}%
\xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
- }%
+ \pgfmathprintnumber@endgroup
\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}%
+ \pgfmathprintnumber@begingroup
+ \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 }%
- }%
+ \pgfmathprintnumber@endgroup
\let\pgfmathresult=\pgfmathfloat@glob@TMP
}
@@ -782,10 +849,11 @@
}
\def\pgfmathfloatrounddisplaystyle@e#1#2e#3\relax{%
\ifnum#3<0\relax
- {\count0=#3\relax
+ \pgfmathprintnumber@begingroup
+ \count0=#3\relax
\multiply\count0 by-1
\xdef\pgfmathfloat@glob@TMP{e{-}\the\count0}%
- }%
+ \pgfmathprintnumber@endgroup%
\let\pgfmathresult=\pgfmathfloat@glob@TMP
\else
\def\pgfmathresult{e{+}#3}%
@@ -795,10 +863,11 @@
}
\def\pgfmathfloatrounddisplaystyle@E#1#2e#3\relax{%
\ifnum#3<0\relax
- {\count0=#3\relax
+ \pgfmathprintnumber@begingroup
+ \count0=#3\relax
\multiply\count0 by-1
\xdef\pgfmathfloat@glob@TMP{E{-}\the\count0}%
- }%
+ \pgfmathprintnumber@endgroup%
\let\pgfmathresult=\pgfmathfloat@glob@TMP
\else
\def\pgfmathresult{E{+}#3}%
@@ -841,6 +910,14 @@
\long\def\pgfmathfloatfrac@verbatim#1#2{#1/#2}%
+\let\pgfmathround@@orig=\pgfmathround@
+
+% 2 = compatible
+% 0 = no
+% 1 = yes
+\def\pgfmathprintnumber@RELATIVE@choice@roundtofixed{2}%
+
+\newif\ifpgfmathprintnumber@thousand@sep@in@fractional
\pgfkeys{%
/pgf/number format/.is family,
/pgf/number format,
@@ -848,6 +925,22 @@
sci/.code= \pgfmath@set@number@printer{pgfmathprintnumber@SCI},
std/.code= {\pgfmath@set@number@printer{pgfmathprintnumber@STD}\pgfmathprintnumber@STD@setparam{#1}},
std/.default=,%
+ relative round mode/.is choice,
+ relative round mode/fixed/.code={\def\pgfmathprintnumber@RELATIVE@choice@roundtofixed{1}},
+ relative round mode/mantissa/.code={\def\pgfmathprintnumber@RELATIVE@choice@roundtofixed{0}},
+ relative round mode/compatible/.code={\def\pgfmathprintnumber@RELATIVE@choice@roundtofixed{2}},
+ % relative={<exponent base 10>}
+ relative/.code= {%
+ \pgfmath@set@number@printer{pgfmathprintnumber@RELATIVE}%
+ \pgfmathround@@orig{#1}%
+ \expandafter\pgfmathfloattoint@@\pgfmathresult\relax
+ \let\pgfmathprintnumber@RELATIVE@param=\pgfmathresult
+ },%
+ relative/.value required,
+ relative*/.style={/pgf/number format/relative={#1},/pgf/number format/relative round mode=fixed},
+ every relative/.style=std,
+ relative style/.style={/pgf/number format/every relative/.append style={#1}},
+ fixed relative/.code= \pgfmath@set@number@printer{pgfmathprintnumber@FIXED@RELATIVE},
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},%
@@ -880,11 +973,13 @@
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/.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},
+ 1000 sep in fractionals/.is if=pgfmathprintnumber@thousand@sep@in@fractional,
+ 1000 sep in fractionals/.default=true,
+ 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={.}},
@@ -946,7 +1041,7 @@
\ifx\pgfmathfloat@loc@TMPb\pgfutil@empty
% DEFAULT for lower and upper bound.
\def\pgfmathprintnumber@STD@getlowerbound{%
- \c@pgf@counta=\pgfmathfloat@round@precision\relax
+ \c@pgf@counta=\pgfmathfloat@round@precision@orig\relax
\divide\c@pgf@counta by-2\relax
}%
\def\pgfmathprintnumber@STD@upperbound{4}%
@@ -992,6 +1087,114 @@
\fi
}
+\def\pgfmathprintnumber@RELATIVE#1{%
+ % parse the input:
+ \pgfmathfloatparsenumber{#1}%
+ \pgfmathfloat@to@FMeE@style\pgfmathresult
+ \expandafter\pgfmathprintnumber@RELATIVE@issci\pgfmathresult\relax
+}
+
+\def\pgfmathprintnumber@RELATIVE@choice@roundtofixed@warn{%
+ \immediate\write16{! Package pgf warning: the use of /pgf/number format/relative is discouraged (buggy). Please use 'relative*' instead or type \string\pgfkeys{/pgf/number format/relative round mode=fixed} into your preamble.}%
+ \global\let\pgfmathprintnumber@RELATIVE@choice@roundtofixed@warn=\relax
+}
+
+\def\pgfmathprintnumber@RELATIVE@issci#1#2e#3\relax{%
+ \begingroup
+ % format X / 10^{relative}:
+ \c@pgf@counta=#3\relax
+ \advance\c@pgf@counta by-\pgfmathprintnumber@RELATIVE@param\relax
+ \pgfmathfloatcreate{#1}{#2}{\the\c@pgf@counta}%
+ % OK, round it to the desired precision:
+ \if0\pgfmathprintnumber@RELATIVE@choice@roundtofixed
+ % relative round mode=mantissa
+ \def\b@round@fixed{0}%
+ \else
+ \if1\pgfmathprintnumber@RELATIVE@choice@roundtofixed
+ % relative round mode=fixed
+ \def\b@round@fixed{1}%
+ \else
+ \pgfmathprintnumber@RELATIVE@choice@roundtofixed@warn
+ % relative round mode=compatible
+ \ifnum\c@pgf@counta>0
+ % hm. for positive exponents, we should round the
+ % mantissa rather than only the fractional part.
+ \def\b@round@fixed{0}%
+ \else
+ % negative exponent -> round fixed representation:
+ \def\b@round@fixed{1}%
+ \fi
+ \fi
+ \fi
+ \if1\b@round@fixed
+ % round fixed representation:
+ \pgfmathfloattofixed\pgfmathresult
+ \expandafter\pgfmathroundto\expandafter{\pgfmathresult}%
+ \pgfmathfloatparsenumber{\pgfmathresult}%
+ \pgfmathfloatroundhasperiodtrue% make sure the code below works:
+ \else
+ % round the mantissa:
+ \expandafter\pgfmathfloatround\expandafter{\pgfmathresult}%
+ \fi
+ % Now, compute result * 10^{relative} and format the result:
+ \pgfmathfloattoregisterstok\pgfmathresult\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
+ \ifnum\pgfmathfloat@a@S=0
+ \pgfmathfloat@a@E=\pgfmathfloat@a@S % avoid 0 * 10^8
+ \else
+ \advance\pgfmathfloat@a@E by+\pgfmathprintnumber@RELATIVE@param\relax
+ \fi
+ \edef\pgfmathresultX{%
+ \the\pgfmathfloat@a@S
+ \the\pgfmathfloat@a@Mtok
+ \ifpgfmathfloatroundhasperiod\else.0\fi
+ e\the\pgfmathfloat@a@E}%
+ % call another formatter for the result (but avoid rounding inside of it):
+ \pgfqkeys{/pgf/number format}{/pgf/number format/every relative,
+ fixed zerofill=false,% useless here!
+ sci zerofill=false}%
+ \ifx\pgfmathprintnumber@issci\pgfmathprintnumber@RELATIVE@issci
+ \pgfmath@error{The '/pgf/number format/every relative' style should set a valid display style}%
+ \fi
+ \let\pgfmathfloat@round@precision@orig=\pgfmathfloat@round@precision
+ \def\pgfmathfloat@round@precision{9999}%
+ \expandafter\pgfmathprintnumber@issci\pgfmathresultX\relax%
+ \pgfmath@smuggleone\pgfmathresult
+ \endgroup
+}
+
+\def\pgfmathprintnumber@FIXED@RELATIVE#1{%
+ % parse the input:
+ \pgfmathfloatparsenumber{#1}%
+ \pgfmathfloat@to@FMeE@style\pgfmathresult
+ \expandafter\pgfmathprintnumber@FIXED@RELATIVE@issci\pgfmathresult\relax
+}
+
+\def\pgfmathprintnumber@FIXED@RELATIVE@issci#1#2e#3\relax{%
+ \begingroup
+ \pgfmathfloatcreate{#1}{#2}{#3}%
+ % we want the first <precision> digits - not the first
+ % <precision>+1 digits:
+ \c@pgf@counta=\pgfmathfloat@round@precision\relax
+ \advance\c@pgf@counta by-1
+ \edef\pgfmathfloat@round@precision{\the\c@pgf@counta}%
+ \pgfmathfloatround{\pgfmathresult}%
+ \pgfmathfloattoregisterstok\pgfmathresult\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
+ \ifnum\pgfmathfloat@a@S=0
+ \pgfmathfloat@a@E=\pgfmathfloat@a@S % avoid 0 * 10^8
+ \fi
+ \edef\pgfmathresultX{%
+ \the\pgfmathfloat@a@S
+ \the\pgfmathfloat@a@Mtok
+ \ifpgfmathfloatroundhasperiod\else.0\fi
+ e\the\pgfmathfloat@a@E}%
+ \let\pgfmathfloat@round@precision@orig=\pgfmathfloat@round@precision
+ \pgfmathfloat@usezerofill@fixedfalse
+ \def\pgfmathfloat@round@precision{9999}% typeset all remaining digits!
+ \expandafter\pgfmathprintnumber@FIXED@issci\pgfmathresultX\relax%
+ \pgfmath@smuggleone\pgfmathresult
+ \endgroup
+}
+
\def\pgfmathprintnumber@frac#1{%
% parse the input:
\pgfmathfloatparsenumber{#1}%
@@ -1048,7 +1251,7 @@
% 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}{}%
+ \pgfmath@PackageError{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}%