Debian Codegraph @

texmf-dist/tex/generic/pgfplots/oldpgfcompatib/pgfplotsoldpgfsupp_pgfmathfloat.code.tex

raw
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %%% This file is a copy of some part of PGF/Tikz.
3 %%% It has been copied here to provide :
4 %%% - compatibility with older PGF versions
5 %%% - availability of PGF contributions by Christian Feuersaenger
6 %%% which are necessary or helpful for pgfplots.
7 %%%
8 %%% For reasons of simplicity, I have copied the whole file, including own contributions AND
9 %%% PGF parts. The copyrights are as they appear in PGF.
10 %%%
11 %%% Note that pgfplots has compatible licenses.
12 %%%
13 %%% This copy has been modified in the following ways:
14 %%% - nested \input commands have been updated
15 %%%
16 %
17 % Support for the contents of this file will NOT be done by the PGF/TikZ team.
18 % Please contact the author and/or maintainer of pgfplots (Christian Feuersaenger) if you need assistance in conjunction
19 % with the deployment of this patch or partial content of PGF. Note that the author and/or maintainer of pgfplots has no obligation to fix anything:
20 % This file comes without any warranty as the rest of pgfplots; there is no obligation for help.
21 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22 %%% Date of this copy: Mo 30. Apr 17:24:35 CEST 2018 %%%
23
24
25
26 % Copyright 2008 by Christian Feuersaenger
27 %
28 % This file may be distributed and/or modified
29 %
30 % 1. under the LaTeX Project Public License and/or
31 % 2. under the GNU Public License.
32 %
33 % See the file doc/generic/pgf/licenses/LICENSE for more details.
34 %
35 % This file contains methods for basic floating point arithmetics, rounding
36 % to arbitrary precision and number pretty printing.
37 %
38
39
40 \pgfkeys{
41 % The bug 3430171 (wrong minus sign spacing in pgfmathprintnumber)
42 % has been fixed in 2.10 CVS. Since it changes the spacing, its
43 % effects can be undone with this compatibility switch.
44 /pgf/compat/number printer/.is choice,
45 /pgf/compat/number printer/2.10/.code={%
46 \def\pgfmathprintnumber@begingroup{\bgroup}%
47 \def\pgfmathprintnumber@endgroup{\egroup}%
48 },
49 % I do not know the version number of the next release at this
50 % time. Please be so kind and KEEP THIS NAME INTACT. Add an alias
51 % if needed.
52 /pgf/compat/number printer/next after 2.10/.code={%
53 \def\pgfmathprintnumber@begingroup{\begingroup}%
54 \def\pgfmathprintnumber@endgroup{\endgroup}%
55 },
56 % activate the fix by default.
57 /pgf/compat/number printer/next after 2.10,%
58 }
59
60
61 \global\newif\ifpgfmathfloatcomparison
62 \newif\ifpgfmathfloatroundhasperiod
63 \newif\ifpgfmathprintnumberskipzeroperiod
64
65
66 % used internally in grouped macros:
67 \toksdef\pgfmathfloat@tmptoks=1
68 \newif\ifpgfmathfloat@fixed@digits@after@period
69 \newif\ifpgfmathfloatroundmayneedrenormalize
70 \toksdef\pgfmathfloat@a@Mtok=0
71
72 %% WARNING: avoid conflicting register names!
73 \let\pgfmathfloat@a@S=\c@pgf@counta
74 \let\pgfmathfloat@a@M=\pgf@xa
75 \let\pgfmathfloat@a@E=\c@pgf@countb
76 \let\pgfmathfloat@b@S=\c@pgf@countc
77 \let\pgfmathfloat@b@M=\pgf@xb
78 \let\pgfmathfloat@b@E=\c@pgf@countd
79
80 % can be changed with options.
81 \def\pgfmathfloat@round@precision{2}
82
83 % I introduced this to acces the "original" precision in case a
84 % formatted changes it locally... in this case, the formatter may
85 % overwrite \pgfmathfloat@round@precision@orig to provide the original
86 % one.
87 % The default implementation here does nothing:
88 \def\pgfmathfloat@round@precision@orig{\pgfmathfloat@round@precision}%
89
90 \gdef\pgfmathfloat@glob@TMP{}
91
92
93 % Computes a normalised floating point representation for #1 of the
94 % form
95 % [FLAGS] MANTISSE EXPONENT
96 % meaning
97 % [+-]X.XXXXXXX*10^C
98 % where
99 % X.XXXXXX is a mantissa with first number != 0, C is an integer and
100 % FLAGS contains the sign and some other special cases.
101 %
102 % This method does NOT use TeX Registers to represent the numbers! The
103 % computation is COMPLETELY STRING BASED.
104 % This allows numbers such at 10000000 or 5.23e-10 to be represented
105 % properly, although TeX-registers would produce overflow/underflow
106 % errors in these cases.
107 %
108 % It is to be used to compute logs, because log(X*10^Y) = log(X) + log(10)*Y
109 %
110 % Arguments:
111 % #1: an arbitrary number which shall be parsed. Maybe a macro.
112 % Examples:
113 % [+-]XXXXX.XXXXXX
114 % [+-]XXXXX.XXXXXXeXXXX
115 % [+-]0.0000XXXXXX
116 % [+-]0.0000XXXXXXeXXXX
117 % [+-]inf
118 % nan
119 % Maybe a macro containing such a number.
120 %
121 % Return value:
122 % \pgfmathresult will be \def'ed to
123 % FLAGS MANTISSE 'e' EXPONENT
124 % where
125 % FLAGS is a number in [0-5] where
126 % 0 == '0' (the number is +- 0.0),
127 % 1 == '+',
128 % 2 == '-',
129 % 3 == 'not a number'
130 % 4 == '+ infinity'
131 % 5 == '- infinity'
132 %
133 % MANTISSE is a normalised number 1 <= M < 10. It always contains a
134 % period and at least one digit after the period.
135 %
136 % EXPONENT is an integer value.
137 %
138 % Example:
139 % \pgfmathfloatparsenumber{1}
140 % -> \pgfmathresult = 11.0e0
141 % \pgfmathfloatparsenumber{141.212}
142 % -> \pgfmathresult = 11.41212e2
143 \def\pgfmathfloatparsenumber#1{%
144 \begingroup
145 \edef\pgfmathresult{#1}%
146 \expandafter\pgfflt@impl\pgfmathresult\pgfflt@EOI
147 \ifpgfmathfloatparsenumberpendingperiod
148 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@[email protected]}%
149 \fi
150 \pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}%
151 \pgfmath@smuggleone\pgfmathresult
152 \endgroup
153 }
154
155 % The same as \pgfmathfloatparsenumber, but does not perform sanity checking.
156 % FIXME: there is no longer any difference here.
157 \let\pgfmathfloatqparsenumber=\pgfmathfloatparsenumber
158
159 % Takes a floating point number #1 as input and writes flags to count
160 % register #2, mantissa to dimen register #3 and exponent to count
161 % register #4.
162 \def\pgfmathfloattoregisters#1#2#3#4{%
163 \expandafter\pgfmathfloat@decompose#1\relax{#2}{#3}{#4}%
164 }
165
166 % the same, but writes the mantissa into a token register.
167 \def\pgfmathfloattoregisterstok#1#2#3#4{%
168 \expandafter\pgfmathfloat@decompose@tok#1\relax{#2}{#3}{#4}%
169 }
170
171 % Extracts the flags of #1 into the count register #2.
172 \def\pgfmathfloatgetflags#1#2{%
173 \expandafter\pgfmathfloat@decompose@F#1\relax{#2}%
174 }
175 % Extracts the flags of #1 into the macro #2.
176 \def\pgfmathfloatgetflagstomacro#1#2{%
177 \expandafter\pgfmathfloat@decompose@Fmacro#1\relax{#2}%
178 }%
179
180 % Extracts the mantissa of #1 into the dimen register #2.
181 \def\pgfmathfloatgetmantissa#1#2{%
182 \expandafter\pgfmathfloat@decompose@M#1\relax{#2}%
183 }
184 \let\pgfmathfloatgetmantisse=\pgfmathfloatgetmantissa
185 % Extracts the mantissa of #1 into the token register #2.
186 \def\pgfmathfloatgetmantissatok#1#2{%
187 \expandafter\pgfmathfloat@decompose@Mtok#1\relax{#2}%
188 }
189 \let\pgfmathfloatgetmantissetok=\pgfmathfloatgetmantissatok
190 % Extracts the exponent of #1 into the count register #2.
191 \def\pgfmathfloatgetexponent#1#2{%
192 \expandafter\pgfmathfloat@decompose@E#1\relax{#2}%
193 }
194
195
196 % Assigns \pgfmathresult to be a float encoded as
197 % <FLAGS><MANTISSE>e<EXPONENT>
198 %
199 % example:
200 % \pgfmathfloatcreate{1}{2.0}{10}
201 % \pgfmathfloat@to@FMeE@style\pgfmathresult
202 % ->
203 % \pgfmathresult is now '12.0e10' regardless of the internal float
204 % format.
205 \def\pgfmathfloat@to@FMeE@style#1{\expandafter\pgfmathfloat@to@FMeE@style@#1\relax\relax}%
206 \def\pgfmathfloat@to@FMeE@style@#1#2{%
207 \ifx#2Y%
208 \expandafter\pgfmathfloat@to@FMeE@style@@%
209 \else
210 \expandafter\pgfmathfloat@to@FMeE@style@error%
211 \fi
212 #1#2%
213 }%
214 \def\pgfmathfloat@to@FMeE@style@@#1Y#2e#3]\relax\relax{\def\pgfmathresult{#1#2e#3}}%
215 \def\pgfmathfloat@to@FMeE@style@error#1\relax\relax{%
216 \begingroup
217 \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
218 \xdef\pgfmathfloat@decompose@TMP{%
219 \noexpand\pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}%
220 }%
221 \endgroup
222 \pgfmathfloat@decompose@TMP
223 }%
224
225
226 % decomposes a lowlevel floating point representation into flags,
227 % mantissa and exponent.
228 %
229 % #4: integer register for the flags.
230 % #5: dimen registers for the mantissa.
231 % #6: integer register for the exponent.
232 %
233 % \expandafter\pgfmathfloat@decompose\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@M\pgfmathfloat@a@E
234 % -> the three temp registers contain flags, mantissa and exponent
235 \def\pgfmathfloat@decompose#1#2{% sanitize!
236 \ifx#2Y%
237 \expandafter\pgfmathfloat@decompose@%
238 \else
239 \expandafter\pgfmathfloat@decompose@error%
240 \fi
241 #1#2%
242 }
243 \def\pgfmathfloat@decompose@#1Y#2e#3]\relax#4#5#6{%
244 #4=#1\relax
245 #5=#2pt % keep space here.
246 #6=#3\relax%
247 }
248
249 % overloaded, #5 needs to be a token register for the mantissa.
250 % @see also \pgfmathfloatvalueof which does also employ the load
251 % level repr.
252 % \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
253 % -> the three temp registers contain flags, mantissa and exponent
254 \def\pgfmathfloat@decompose@tok#1#2{%
255 \ifx#2Y%
256 \expandafter\pgfmathfloat@decompose@tok@%
257 \else
258 \expandafter\pgfmathfloat@decompose@tok@error%
259 \fi
260 #1#2%
261 }%
262 \def\pgfmathfloat@decompose@tok@#1Y#2e#3]\relax#4#5#6{%
263 #4=#1\relax
264 #5={#2}%
265 #6=#3\relax%
266 }
267 % overloaded, returns only ONE of the three components into #4:
268 % \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S
269 % -> \pgfmathfloat@a@S contains the flags field.
270 \def\pgfmathfloat@decompose@F#1#2{%
271 \ifx#2Y%
272 \expandafter\pgfmathfloat@decompose@F@%
273 \else
274 \expandafter\pgfmathfloat@decompose@F@error%
275 \fi
276 #1#2%
277 }%
278 \def\pgfmathfloat@decompose@Fmacro#1#2{%
279 \ifx#2Y%
280 \expandafter\pgfmathfloat@decompose@Fmacro@%
281 \else
282 \expandafter\pgfmathfloat@decompose@F@error%
283 \fi
284 #1#2%
285 }%
286 \def\pgfmathfloat@decompose@M#1#2{%
287 \ifx#2Y%
288 \expandafter\pgfmathfloat@decompose@M@%
289 \else
290 \expandafter\pgfmathfloat@decompose@M@error%
291 \fi
292 #1#2%
293 }%
294 \def\pgfmathfloat@decompose@E#1#2{%
295 \ifx#2Y%
296 \expandafter\pgfmathfloat@decompose@E@%
297 \else
298 \expandafter\pgfmathfloat@decompose@E@error%
299 \fi
300 #1#2%
301 }%
302 \def\pgfmathfloat@decompose@Mtok#1#2{%
303 \ifx#2Y%
304 \expandafter\pgfmathfloat@decompose@Mtok@%
305 \else
306 \expandafter\pgfmathfloat@decompose@Mtok@error%
307 \fi
308 #1#2%
309 }%
310 \def\pgfmathfloat@decompose@F@#1Y#2e#3]\relax#4{#4=#1\relax}%
311 \def\pgfmathfloat@decompose@Fmacro@#1Y#2e#3]\relax#4{\def#4{#1}}%
312 \def\pgfmathfloat@decompose@M@#1Y#2e#3]\relax#4{#4=#2pt}%
313 \def\pgfmathfloat@decompose@Mtok@#1Y#2e#3]\relax#4{#4={#2}}%
314 \def\pgfmathfloat@decompose@E@#1Y#2e#3]\relax#4{#4=#3\relax}%
315
316 \def\pgfmathfloat@decompose@error#1\relax#2#3#4{%
317 \begingroup
318 \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
319 \xdef\pgfmathfloat@decompose@TMP{%
320 \noexpand#2=\the\pgfmathfloat@a@S\space
321 \noexpand#3=\the\pgfmathfloat@a@Mtok pt
322 \noexpand#4=\the\pgfmathfloat@a@E\space
323 }%
324 \endgroup
325 \pgfmathfloat@decompose@TMP
326 }%
327 \def\pgfmathfloat@decompose@tok@error#1\relax#2#3#4{%
328 \begingroup
329 \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
330 \xdef\pgfmathfloat@decompose@TMP{%
331 \noexpand#2=\the\pgfmathfloat@a@S\space
332 \noexpand#3={\the\pgfmathfloat@a@Mtok}%
333 \noexpand#4=\the\pgfmathfloat@a@E\space
334 }%
335 \endgroup
336 \pgfmathfloat@decompose@TMP
337 }%
338 \def\pgfmathfloat@decompose@F@error#1\relax#2{%
339 \begingroup
340 \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
341 \xdef\pgfmathfloat@decompose@TMP{\noexpand#2=\the\pgfmathfloat@a@S\space}%
342 \endgroup
343 \pgfmathfloat@decompose@TMP
344 }%
345 \def\pgfmathfloat@decompose@M@error#1\relax#2{%
346 \begingroup
347 \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
348 \xdef\pgfmathfloat@decompose@TMP{\noexpand#2=\the\pgfmathfloat@a@Mtok pt }%
349 \endgroup
350 \pgfmathfloat@decompose@TMP
351 }%
352 \def\pgfmathfloat@decompose@Mtok@error#1\relax#2{%
353 \begingroup
354 \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
355 \xdef\pgfmathfloat@decompose@TMP{\noexpand#2={\the\pgfmathfloat@a@Mtok}}%
356 \endgroup
357 \pgfmathfloat@decompose@TMP
358 }%
359 \def\pgfmathfloat@decompose@E@error#1\relax#2{%
360 \begingroup
361 \pgfmathfloatparsenumber@handleerror{wrong lowlevel format}{#1}{#1}%
362 \xdef\pgfmathfloat@decompose@TMP{\noexpand#2=\the\pgfmathfloat@a@E\space}%
363 \endgroup
364 \pgfmathfloat@decompose@TMP
365 }%
366 % Takes a floating point number #1 as input and writes flags to macro
367 % #2, mantissa to macro #3 and exponent to macro #4.
368 \def\pgfmathfloattomacro#1#2#3#4{%
369 \begingroup
370 \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
371 \xdef\pgfmathfloat@glob@TMP{%
372 \noexpand\def\noexpand#2{\the\pgfmathfloat@a@S}%
373 \noexpand\def\noexpand#3{\the\pgfmathfloat@a@Mtok}%
374 \noexpand\def\noexpand#4{\the\pgfmathfloat@a@E}%
375 }%
376 \endgroup
377 \pgfmathfloat@glob@TMP
378 }
379
380
381 % Defines \pgfmathresult as the floating point number encoded by
382 % the flags #1, mantissa #2 and exponent #3.
383 %
384 % All arguments are characters and will be expanded using '\edef'.
385 \def\pgfmathfloatcreate#1#2#3{%
386 \edef\pgfmathresult{#1Y#2e#3]}%
387 }%
388 % This is the character present in any low-level floating point
389 % number. It is assumed to be the SECOND character of a float (after
390 % the flags integer).
391 \def\pgfmathfloat@POSTFLAGSCHAR{Y}
392
393
394
395 % Converts a composed floating point representation to fixed point.
396 %
397 % Example:
398 % \pgfmathfloattofixed{142e1}
399 % -> \pgfmathresult = 42.0
400 \def\pgfmathfloattofixed@#1{%
401 \begingroup
402 \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
403 \ifcase\pgfmathfloat@a@S
404 \def\pgfmathresult{0.0}%
405 \or
406 \expandafter\pgfmathfloattofixed@impl\the\pgfmathfloat@a@Mtok\relax
407 \or
408 \expandafter\pgfmathfloattofixed@impl\the\pgfmathfloat@a@Mtok\relax
409 \pgfmathfloat@a@Mtok=\expandafter{\pgfmathresult}%
410 \edef\pgfmathresult{-\the\pgfmathfloat@a@Mtok}%
411 \or\def\pgfmathresult{nan}%
412 \or\def\pgfmathresult{inf}%
413 \or\def\pgfmathresult{-inf}%
414 \fi
415 \pgfmath@smuggleone\pgfmathresult
416 \endgroup
417 }
418 \let\pgfmathfloattofixed=\pgfmathfloattofixed@
419
420 % Converts a float to an integer (in integer format).
421 %
422 % @see \pgfmathfloatint
423 \def\pgfmathfloattoint#1{%
424 \pgfmathfloattofixed{#1}%
425 \expandafter\pgfmathfloattoint@@\pgfmathresult\relax
426 }%
427 \def\pgfmathfloattoint@@#1.#2\relax{%
428 \def\pgfmathresult{#1}%
429 }%
430
431 % Converts a floating point number to scientific format 1.234e5.
432 %
433 % This operation is very fast.
434 \def\pgfmathfloattosci@#1{%
435 \begingroup
436 \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
437 \ifcase\pgfmathfloat@a@S
438 \def\pgfmathresult{0.0e0}%
439 \or
440 \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok e\the\pgfmathfloat@a@E}%
441 \or
442 \edef\pgfmathresult{-\the\pgfmathfloat@a@Mtok e\the\pgfmathfloat@a@E}%
443 \or\def\pgfmathresult{nan}%
444 \or\def\pgfmathresult{inf}%
445 \or\def\pgfmathresult{-inf}%
446 \fi
447 \pgfmath@smuggleone\pgfmathresult
448 \endgroup
449 }%
450 \let\pgfmathfloattosci=\pgfmathfloattosci@
451
452 % Expands a floating point number to scientific format 1.234e5.
453 %
454 % This operation is very fast.
455 \def\pgfmathfloatvalueof#1{\expandafter\pgfmathfloatvalueof@@#1@@}%
456
457 % Make it fool proof such that the following arguments work:
458 % \pgfmathfloatvalueof{1Y1.0e1} -> 1.0e1
459 % \pgfmathfloatvalueof{2Y1.0e1} -> -1.0e1
460 % and wrong arguments as well:
461 % \pgfmathfloatvalueof{1} -> 1
462 % \pgfmathfloatvalueof{1e2} -> 1e2
463 \def\pgfmathfloatvalueof@@#1#2{%
464 \if#2Y%
465 % keep in mind that \pgfmathfloatvalueof should be expandable!
466 % We must not use \let here. Let's hope that #1 and #2 are
467 % single tokens (not something which was enclosed by curly
468 % braces...)
469 \expandafter\pgfmathfloatvalueof@@@\expandafter#1\expandafter#2%
470 \else
471 % Oh - no float!? Ok, we cannot report errors in this context.
472 % So: make it a feature and return the input argument as-is.
473 % Might be useful, in fact...
474 \expandafter\pgfmathfloatvalueof@abort\expandafter#1\expandafter#2%
475 \fi
476 }
477 \def\pgfmathfloatvalueof@@@#1Y#2e#3]@@{%
478 \ifcase#1 %
479 0.0e0%
480 \or
481 #2e#3%
482 \or
483 -#2e#3%
484 \or nan%
485 \or inf%
486 \or -inf%
487 \fi
488 }%
489 \def\pgfmathfloatvalueof@abort#1@@{#1}%
490
491
492
493 % Rounds a fixed point number #1 to \pgfmathfloat@round@precision digits precision and returns
494 % the result into \pgfmathresult.
495 %
496 % Any trailing zeros after the period are discarded.
497 % See \pgfmathroundtozerofill if you want trailing zeros and fixed
498 % width.
499 %
500 % This method is PURELY text based and can work with arbirtrary
501 % precision (well, limited to TeX's stack size and integer size).
502 %
503 % Examples:
504 % \pgfmathroundto{1}
505 % -> \pgfmathresult = '1'
506 %
507 % \pgfmathroundto{19999.9996}
508 % -> \pgfmathresult = '20000'
509 %
510 % Arguments:
511 % #1 may be either a number or a macro (\pgfmathresult is allowed) expanding to a number.
512 %
513 % SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set.
514 \def\pgfmathroundto#1{%
515 \pgfmathfloatroundhasperiodtrue
516 \begingroup
517 \pgfmathfloat@fixed@digits@after@periodfalse
518 \pgfmathroundto@impl{#1}%
519 \pgfmath@smuggleone\pgfmathresult
520 \endgroup
521 }
522
523
524 % Overloaded method.
525 %
526 % This variant always uses a FIXED number behind the period and fills
527 % in zeros if necessary.
528 % Examples:
529 % \pgfmathroundtozerofill{1}
530 % -> \pgfmathresult = '1.00'
531 %
532 % \pgfmathroundtozerofill{19999.9996}
533 % -> \pgfmathresult = '20000.00'
534 %
535 % SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set.
536 \def\pgfmathroundtozerofill#1{%
537 \pgfmathfloatroundhasperiodtrue
538 \begingroup
539 \pgfmathfloat@fixed@digits@after@periodtrue
540 \pgfmathroundto@impl{#1}%
541 \pgfmath@smuggleone\pgfmathresult
542 \endgroup
543 }
544
545 % see \pgfmathprintnumber@fixed@style for docs
546 \def\pgfmathprintnumber@fixed@styleDEFAULT#1#2#3e#4\relax{%
547 \begingroup
548 \pgfkeysgetvalue{/pgf/number format/set decimal separator}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP
549 \pgfkeysgetvalue{/pgf/number format/@dec sep mark}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK
550 \pgfkeysgetvalue{/pgf/number format/set thousands separator}\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP
551 \c@pgf@counta=#4\relax % it is the exponent here.
552 \ifnum#2=0
553 \c@pgf@counta=0
554 \fi
555 \def\pgfmathresult{}%
556 \ifpgfmathfloatroundhasperiod
557 \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@period#1\pgfmathfloat@EOI
558 \else
559 \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI%
560 \begingroup
561 \toks0=\expandafter{\pgfmathresult}%
562 \toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK}%
563 \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
564 \endgroup
565 \let\pgfmathresult=\pgfmathfloat@glob@TMP
566 \fi
567 \pgfmath@smuggleone\pgfmathresult
568 \endgroup
569 }
570 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@period#1.#2\pgfmathfloat@EOI{%
571 \ifpgfmathprintnumberskipzeroperiod
572 \def\pgfmathfloat@loc@TMPb{#1}%
573 \ifx\pgfmathfloatparsenumber@tok@ZERO\pgfmathfloat@loc@TMPb
574 \else
575 \def\pgfmathfloat@loc@TMPc{-0}%
576 \ifx\pgfmathfloat@loc@TMPc\pgfmathfloat@loc@TMPb
577 \def\pgfmathresult{-}%
578 \else
579 \def\pgfmathfloat@loc@TMPc{+0}%
580 \ifx\pgfmathfloat@loc@TMPc\pgfmathfloat@loc@TMPb
581 \def\pgfmathresult{+}%
582 \else
583 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI
584 \fi
585 \fi
586 \fi
587 \else
588 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI
589 \fi
590 \ifpgfmathprintnumber@thousand@sep@in@fractional
591 \let\pgfmathresultfractional\pgfutil@empty%
592 \pgfmathprintnumber@thousand@sep@in@fractional#2MMMM\@@
593 \else
594 \def\pgfmathresultfractional{#2}%
595 \fi
596 \begingroup
597 \toks0=\expandafter{\pgfmathresult}%
598 \toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK}%
599 \toks2=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP}%
600 \toks3=\expandafter{\pgfmathresultfractional}%
601 \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 \the\toks3 }%
602 \endgroup
603 \let\pgfmathresult=\pgfmathfloat@glob@TMP
604 }%
605
606 % assigns \pgfmathresult such that it contains the formatted result.
607 % It assumes that none of the following tokens contains a period.
608 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod{%
609 \ifx\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP\pgfutil@empty
610 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
611 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}%
612 \else
613 \ifnum\c@pgf@counta<0\relax % exponent of the number in this context
614 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
615 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}%
616 \else
617 \ifnum\c@pgf@counta<\pgfkeysvalueof{/pgf/number format/min exponent for 1000 sep}\relax
618 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
619 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall}%
620 \else
621 \advance\c@pgf@counta by1 % counta:= total number of digits, N.
622 \c@pgf@countb=\c@pgf@counta
623 \divide\c@pgf@countb by3 % countb := N DIV 3
624 \c@pgf@countc=\c@pgf@countb
625 \multiply\c@pgf@countc by3
626 \advance\c@pgf@counta by-\c@pgf@countc% now counta := N MOD 3
627 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
628 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printsign
629 }%
630 \fi
631 \fi
632 \fi
633 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
634 }
635 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printsign#1{%
636 \def\pgfmathfloat@loc@TMPb{#1}%
637 \ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@MINUS
638 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}%
639 \let\pgfmathfloat@loc@TMPb=\pgfutil@empty
640 \else
641 \ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@PLUS
642 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}%
643 \let\pgfmathfloat@loc@TMPb=\pgfutil@empty
644 \else
645 \ifpgfmathprintnumber@showpositive
646 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult +}%
647 \fi
648 \fi
649 \fi
650 \ifnum\c@pgf@counta>0 % \c@pgf@counta = N MOD 3 in this context
651 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
652 \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printtrailingdigits\pgfmathfloat@loc@TMPb
653 }%
654 \else
655 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
656 \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird\pgfmathfloat@loc@TMPb
657 }%
658 \fi
659 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
660 }
661 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printtrailingdigits#1#2{%
662 \ifcase\c@pgf@counta % = N MOD 3 in this context
663 % does not happen per construction
664 \or
665 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}%
666 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
667 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird#2%
668 }%
669 \or
670 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1#2}%
671 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
672 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird%
673 }%
674 \fi
675 \ifnum\c@pgf@countb>0\relax % \c@pgf@countb = N DIV 3 in this context
676 \begingroup
677 \toks0=\expandafter{\pgfmathresult}%
678 \toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP}%
679 \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
680 \endgroup
681 \let\pgfmathresult=\pgfmathfloat@glob@TMP
682 \fi
683 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
684 }
685 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird#1#2#3{%
686 \ifnum\c@pgf@countb>0\relax
687 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1#2#3}%
688 \advance\c@pgf@countb by-1
689 \ifnum\c@pgf@countb>0\relax
690 \begingroup
691 \toks0=\expandafter{\pgfmathresult}%
692 \toks1=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP}%
693 \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
694 \endgroup
695 \let\pgfmathresult=\pgfmathfloat@glob@TMP
696 \fi
697 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT{%
698 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@counteverythird%
699 }%
700 \else
701 % in thise case, #1#2#3 are expected to be
702 % \pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI
703 %--------------------------------------------------
704 % \def\pgfmathfloat@loc@TMPb{\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI}%
705 % \def\pgfmathfloat@loc@TMPc{#1#2#3}%
706 % \ifx\pgfmathfloat@loc@TMPc\pgfmathfloat@loc@TMPb
707 % \else
708 % \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}{}%
709 % \fi
710 %--------------------------------------------------
711 \let\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT=\relax
712 \fi
713 \pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@NEXT
714 }
715
716 % \pgfmathprintnumber@thousand@sep@in@fractional 01234525MMMM\@@
717 % ->
718 % 012<sep>345<sep>25
719 \def\pgfmathprintnumber@thousand@sep@in@fractional#1#2#3#4{%
720 \if#4M%
721 % Ok, no further separator
722 \def\pgfmathprint@next{\pgfmathprintnumber@thousand@sep@in@fractional@finish#1#2#3#4}%
723 \else
724 \begingroup
725 \toks0=\expandafter{\pgfmathresultfractional}%
726 \toks1={#1#2#3}%
727 \toks2=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@THOUSAND@SEP}%
728 \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 }%
729 \endgroup
730 \let\pgfmathresultfractional=\pgfmathfloat@glob@TMP
731 \def\pgfmathprint@next{\pgfmathprintnumber@thousand@sep@in@fractional#4}%
732 \fi
733 \pgfmathprint@next
734 }%
735 \def\pgfmathprintnumber@thousand@sep@in@fractional@finish#1M{%
736 \expandafter\def\expandafter\pgfmathresultfractional\expandafter{\pgfmathresultfractional #1}%
737 \pgfmathprintnumber@thousand@sep@in@fractional@finish@
738 }%
739 \def\pgfmathprintnumber@thousand@sep@in@fractional@finish@#1\@@{}%
740
741 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall#1{%
742 \def\pgfmathfloat@loc@TMPb{#1}%
743 \let\pgfmathfloat@loc@TMPc=\pgfutil@empty
744 \ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@MINUS
745 \else
746 \ifx\pgfmathfloat@loc@TMPb\pgfmathfloatparsenumber@tok@PLUS
747 \else
748 \ifpgfmathprintnumber@showpositive
749 \def\pgfmathfloat@loc@TMPc{+}%
750 \fi
751 \fi
752 \fi
753 \expandafter\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall@\pgfmathfloat@loc@TMPc#1%
754 }
755 \def\pgfmathprintnumber@fixed@styleDEFAULT@impl@noperiod@printall@#1\pgfmathfloat@EOI\pgfmathfloat@EOI\pgfmathfloat@EOI{%
756 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult #1}%
757 }%
758
759 % @deprecated. It has been replaced by \pgfmathprintnumber@fixed@styleDEFAULT
760 % #1 maybe a macro
761 \def\pgfmathprintnumber@fixed@stylePERIOD#1#2#3e#4\relax{%
762 \def\pgfmathresult{#1}%
763 }
764
765 % @deprecated. It has been replaced by \pgfmathprintnumber@fixed@styleDEFAULT
766 % #1 maybe a macro
767 \def\pgfmathprintnumber@fixed@styleCOMMA#1#2#3e#4\relax{%
768 \ifpgfmathfloatroundhasperiod
769 \expandafter\pgfmathprintnumber@fixed@styleCOMMA@impl#1\pgfmathfloat@EOI
770 \else
771 \def\pgfmathresult{#1}%
772 \fi
773 }
774 \def\pgfmathprintnumber@fixed@styleCOMMA@impl#1.#2\pgfmathfloat@EOI{\def\pgfmathresult{#1{,}#2}}
775
776 % The default style to display fixed point numbers.
777 %
778 % It does not apply numerics, but it is responsable for typesetting the
779 % rounded number.
780 % It can access the \ifpgfmathfloatroundhasperiod boolean.
781 %
782 % Arguments:
783 % #1#2#3e#4\relax
784
785 % Input:
786 % #1 the fixed point number to be displayed (maybe a macro).
787 % #2#3e#4: the (possibly unformatted) floating point representation
788 % which belongs to #1. This format is returned (only!) by
789 % \pgfmathfloat@to@FMeE@style.
790 % It is used to determine sign and exponent.
791 \let\pgfmathprintnumber@fixed@style=\pgfmathprintnumber@fixed@styleDEFAULT
792
793
794 % Rounds a normalized floating point number to \pgfmathfloat@round@precision
795 % digits precision and writes the result to \pgfmathresult.
796 %
797 % This method uses \pgfmathroundto for the mantissa.
798 %
799 % @see pgfmathfloatroundzerofill
800 %
801 % SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set to
802 % whether the final mantissa #5 has a period or not.
803 \def\pgfmathfloatround#1{%
804 \pgfmathfloatroundhasperiodtrue
805 \begingroup
806 \pgfmathfloat@fixed@digits@after@periodfalse
807 \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
808 \pgfmathfloatround@impl
809 \pgfmath@smuggleone\pgfmathresult
810 \endgroup
811 }
812
813 % Overload.
814 %
815 % This method uses a fixed width for the mantissa and fills in zeros
816 % if necessary.
817 %
818 % This method uses \pgfmathroundtozerofill for the mantissa.
819 %
820 % SIDE EFFECT: the global variable \ifpgfmathfloatroundhasperiod will be set to
821 % whether the final mantissa #5 has a period or not.
822 \def\pgfmathfloatroundzerofill#1{%
823 \pgfmathfloatroundhasperiodtrue
824 \begingroup
825 \pgfmathfloat@fixed@digits@after@periodtrue
826 \expandafter\pgfmathfloat@decompose@tok#1\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
827 \pgfmathfloatround@impl
828 \pgfmath@smuggleone\pgfmathresult
829 \endgroup
830 }
831
832 \newif\ifpgfmathfloatround@allow@empty@mantissa
833 \def\pgfmathfloatround@mantissa@ONE{1.0}%
834
835 % #1: sign
836 % #2: mantissa
837 % #3: exponent
838 % #4: CODE to display if the mantissa is drawn.
839 % This code will be shown just before the exponent.
840 % Example: #4=\cdot
841 % #5: CODE to display if the mantissa is NOT draw. (unused currently)
842 % Might be used to display '10^1' instead of '1*10^1'.
843 % #6: CODE to display the exponent.
844 \def\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax#4#5#6{%
845 \pgfkeysgetvalue{/pgf/number format/@sci exponent mark}\pgfmathfloatrounddisplaystyle@e@mark
846 \ifcase#1\relax
847 \pgfmathprintnumber@fixed@style{#2}#1#2e0\relax%
848 \expandafter\pgfmathfloatrounddisplaystyle@shared@impl@\expandafter{\pgfmathresult}{#4#6}%
849 \or\pgfmathprintnumber@fixed@style{#2}#1#2e0\relax%
850 \expandafter\pgfmathfloatrounddisplaystyle@shared@impl@\expandafter{\pgfmathresult}{#4#6}%
851 \or\pgfmathprintnumber@fixed@style{-#2}#1#2e0\relax%
852 \expandafter\pgfmathfloatrounddisplaystyle@shared@impl@\expandafter{\pgfmathresult}{#4#6}%
853 \or
854 \pgfmathfloatrounddisplaystyle@shared@impl@@{\hbox{NaN}}{}%
855 \or
856 \ifpgfmathprintnumber@showpositive
857 \pgfmathfloatrounddisplaystyle@shared@impl@@{+\infty}{}%
858 \else
859 \pgfmathfloatrounddisplaystyle@shared@impl@@{\infty}{}%
860 \fi
861 \or
862 \pgfmathfloatrounddisplaystyle@shared@impl@@{-\infty}{}%
863 \fi
864 }
865
866 % #1: the part before the exponent code
867 % #2: the part for the exponent code.
868 \def\pgfmathfloatrounddisplaystyle@shared@impl@#1#2{%
869 \pgfmathprintnumber@begingroup
870 \toks0={#1}%
871 \toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}%
872 \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 }%
873 \pgfmathprintnumber@endgroup
874 \let\pgfmathresult=\pgfmathfloat@glob@TMP
875 }%
876 % Same as \pgfmathfloatrounddisplaystyle@shared@impl@, but it also
877 % inserts the '@dec sep mark' at the end.
878 \def\pgfmathfloatrounddisplaystyle@shared@impl@@#1#2{%
879 \pgfmathprintnumber@begingroup
880 \toks0={#1}%
881 \toks1=\expandafter{\pgfmathfloatrounddisplaystyle@e@mark #2}%
882 \pgfkeysgetvalue{/pgf/number format/@dec sep mark}\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK
883 \toks2=\expandafter{\pgfmathprintnumber@fixed@styleDEFAULT@DEC@SEP@MARK}%
884 \xdef\pgfmathfloat@glob@TMP{\the\toks0 \the\toks1 \the\toks2 }%
885 \pgfmathprintnumber@endgroup
886 \let\pgfmathresult=\pgfmathfloat@glob@TMP
887 }
888
889 \def\pgfmathfloatrounddisplaystyle@std#1#2e#3\relax{%
890 \pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{\cdot}{}{10^{#3}}%
891 }
892 \def\pgfmathfloatrounddisplaystyle@subscript#1#2e#3\relax{%
893 \pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}{_{#3}}%
894 }
895 \def\pgfmathfloatrounddisplaystyle@superscript#1#2e#3\relax{%
896 \pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}{^{#3}}%
897 }
898 \def\pgfmathfloatrounddisplaystyle@e#1#2e#3\relax{%
899 \ifnum#3<0\relax
900 \pgfmathprintnumber@begingroup
901 \count0=#3\relax
902 \multiply\count0 by-1
903 \xdef\pgfmathfloat@glob@TMP{e{-}\the\count0}%
904 \pgfmathprintnumber@endgroup%
905 \let\pgfmathresult=\pgfmathfloat@glob@TMP
906 \else
907 \def\pgfmathresult{e{+}#3}%
908 \fi
909 \def\pgfmathfloat@loc@TMPb{\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}}%
910 \expandafter\pgfmathfloat@loc@TMPb\expandafter{\pgfmathresult}%
911 }
912 \def\pgfmathfloatrounddisplaystyle@E#1#2e#3\relax{%
913 \ifnum#3<0\relax
914 \pgfmathprintnumber@begingroup
915 \count0=#3\relax
916 \multiply\count0 by-1
917 \xdef\pgfmathfloat@glob@TMP{E{-}\the\count0}%
918 \pgfmathprintnumber@endgroup%
919 \let\pgfmathresult=\pgfmathfloat@glob@TMP
920 \else
921 \def\pgfmathresult{E{+}#3}%
922 \fi
923 \def\pgfmathfloat@loc@TMPb{\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\relax{}{1}}%
924 \expandafter\pgfmathfloat@loc@TMPb\expandafter{\pgfmathresult}%
925 }
926
927 \def\pgfmathfloatrounddisplaystyle@generic#1#2e#3\relax{%
928 \begingroup
929 \pgfkeysvalueof {/pgf/number format/sci generic/@/.@cmd}{#3}{#1}{#2}\pgfeov
930 \pgfkeysgetvalue{/pgf/number format/sci generic/mantissa sep}\pgfmathdisplay@aftermantissa
931 \pgfkeysgetvalue{/pgf/number format/sci generic/empty mantissa sep}\pgfmathdisplay@nomantissa
932 \pgfkeysgetvalue{/pgf/number format/sci generic/exponent}\pgfmathdisplay@e
933 \toks0=\expandafter{\pgfmathdisplay@aftermantissa}%
934 \toks1=\expandafter{\pgfmathdisplay@nomantissa}%
935 \toks2=\expandafter{\pgfmathdisplay@e}%
936 \xdef\pgfmathfloat@glob@TMP{\noexpand\pgfmathfloatrounddisplaystyle@shared@impl#1#2e#3\noexpand\relax{\the\toks0}{\the\toks1}{\the\toks2}}%
937 \endgroup
938 \pgfmathfloat@glob@TMP
939 }
940
941 % A macro which takes the argument '<SIGN><MANTISSE>e<EXPONENT>' and
942 % expands to the final TeX-representation for that floating point
943 % number.
944 %
945 % PRECONDITION:
946 % the floating point number has already been rounded properly and
947 % the mantissa has been rounded correcty.
948 %
949 % The argument needs to be in the format returned by
950 % \pgfmathfloat@to@FMeE@style and terminated by '\relax'.
951 \let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@std
952 \newif\ifpgfmathfloat@usezerofill@sci
953 \newif\ifpgfmathfloat@usezerofill@fixed
954 \newif\ifpgfmathprintnumber@assumemathmode
955 \newif\ifpgfmathprintnumber@showpositive
956 \newif\ifpgfmathprintnumber@frac@warn
957 \newif\ifpgfmathprintnumber@frac@whole
958 \newif\ifpgfmathparsenumber@comma@as@period
959
960 \long\def\pgfmathfloatfrac@verbatim#1#2{#1/#2}%
961
962 \let\pgfmathround@@orig=\pgfmathround@
963
964 % 2 = compatible
965 % 0 = no
966 % 1 = yes
967 \def\pgfmathprintnumber@RELATIVE@choice@roundtofixed{2}%
968
969 \newif\ifpgfmathprintnumber@thousand@sep@in@fractional
970 \pgfkeys{%
971 /pgf/number format/.is family,
972 /pgf/number format,
973 fixed/.code= \pgfmath@set@number@printer{pgfmathprintnumber@FIXED},
974 sci/.code= \pgfmath@set@number@printer{pgfmathprintnumber@SCI},
975 std/.code= {\pgfmath@set@number@printer{pgfmathprintnumber@STD}\pgfmathprintnumber@STD@setparam{#1}},
976 std/.default=,%
977 relative round mode/.is choice,
978 relative round mode/fixed/.code={\def\pgfmathprintnumber@RELATIVE@choice@roundtofixed{1}},
979 relative round mode/mantissa/.code={\def\pgfmathprintnumber@RELATIVE@choice@roundtofixed{0}},
980 relative round mode/compatible/.code={\def\pgfmathprintnumber@RELATIVE@choice@roundtofixed{2}},
981 % relative={<exponent base 10>}
982 relative/.code= {%
983 \pgfmath@set@number@printer{pgfmathprintnumber@RELATIVE}%
984 \pgfmathround@@orig{#1}%
985 \expandafter\pgfmathfloattoint@@\pgfmathresult\relax
986 \let\pgfmathprintnumber@RELATIVE@param=\pgfmathresult
987 },%
988 relative/.value required,
989 relative*/.style={/pgf/number format/relative={#1},/pgf/number format/relative round mode=fixed},
990 every relative/.style=std,
991 relative style/.style={/pgf/number format/every relative/.append style={#1}},
992 fixed relative/.code= \pgfmath@set@number@printer{pgfmathprintnumber@FIXED@RELATIVE},
993 int detect/.code= \pgfmath@set@number@printer{pgfmathprintnumber@INT@DETECT},
994 int trunc/.code= \pgfmath@set@number@printer{pgfmathprintnumber@INT@TRUNC},
995 frac/.code= \pgfmath@set@number@printer{pgfmathprintnumber@frac},%
996 frac TeX/.initial=\frac,
997 frac whole format/.code={\def\pgfmathresult{#1}},
998 frac denom/.initial=,
999 frac whole/.is if=pgfmathprintnumber@frac@whole,
1000 frac whole=true,
1001 frac shift/.initial=4,
1002 frac warning/.is if=pgfmathprintnumber@frac@warn,
1003 frac warning=true,
1004 assume math mode/.is if=pgfmathprintnumber@assumemathmode,
1005 assume math mode/.default=true,
1006 fixed zerofill/.is if= pgfmathfloat@usezerofill@fixed,
1007 fixed zerofill/.default=true,
1008 sci zerofill/.is if= pgfmathfloat@usezerofill@sci,
1009 sci zerofill/.default=true,
1010 zerofill/.style= {/pgf/number format/fixed zerofill=#1,/pgf/number format/sci zerofill=#1},
1011 zerofill/.default= true,
1012 precision/.store in= \pgfmathfloat@round@precision,
1013 sci precision/.code={%
1014 \edef\pgfmathfloat@loc@TMPa{#1}%
1015 \ifx\pgfmathfloat@loc@TMPa\pgfutil@empty
1016 \def\pgfmathprintnumber@sci@precision{\pgfmathfloat@round@precision}%
1017 \else
1018 \let\pgfmathprintnumber@sci@precision=\pgfmathfloat@loc@TMPa
1019 \fi
1020 },%
1021 sci precision/.default=,
1022 sci precision=,
1023 fixed default/.code= {\let\pgfmathprintnumber@fixed@style=\pgfmathprintnumber@fixed@styleDEFAULT},
1024 set decimal separator/.initial=,
1025 dec sep/.style={/pgf/number format/set decimal separator={#1}},
1026 @dec sep mark/.initial=,
1027 @sci exponent mark/.initial=,
1028 set thousands separator/.initial=,
1029 1000 sep in fractionals/.is if=pgfmathprintnumber@thousand@sep@in@fractional,
1030 1000 sep in fractionals/.default=true,
1031 1000 sep/.style={/pgf/number format/set thousands separator={#1}},
1032 min exponent for 1000 sep/.initial=0,
1033 use period/.style= {/pgf/number format/set decimal separator={.},/pgf/number format/set thousands separator={{{,}}}},
1034 use comma/.style= {/pgf/number format/set decimal separator={{{,}}},/pgf/number format/set thousands separator={.}},
1035 showpos/.is if=pgfmathprintnumber@showpositive,
1036 showpos/.default=true,
1037 print sign/.is if=pgfmathprintnumber@showpositive,
1038 print sign/.default=true,
1039 read comma as period/.is if=pgfmathparsenumber@comma@as@period,
1040 read comma as period/.default=true,
1041 skip 0./.is if=pgfmathprintnumberskipzeroperiod,
1042 skip 0./.default=true,
1043 skip 0.= false,
1044 use period,
1045 sci 10^e/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@std},
1046 sci 10e/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@std},
1047 sci e/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@e},
1048 sci E/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@E},
1049 sci subscript/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@subscript},
1050 sci superscript/.code= {\let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@superscript},
1051 sci generic/.code= {%
1052 \let\pgfmathfloatrounddisplaystyle=\pgfmathfloatrounddisplaystyle@generic
1053 \pgfkeysdefargs{/pgf/number format/sci generic/@}%
1054 {##1##2##3}%
1055 {\pgfqkeys{/pgf/number format/sci generic}{#1}}%
1056 },
1057 sci generic/mantissa sep/.initial=,%
1058 sci generic/empty mantissa sep/.initial=,%
1059 sci generic/mantisse sep/.style={/pgf/number format/sci generic/mantissa sep={#1}},%
1060 sci generic/empty mantisse sep/.style={/pgf/number format/sci generic/empty mantissa sep={#1}},%
1061 sci generic/exponent/.initial=,%
1062 sci generic/.value required,
1063 verbatim/.code={%
1064 \pgfqkeys{/pgf/number format}{%
1065 sci generic={mantissa sep=,exponent={e##1}},
1066 1000 sep=,
1067 skip 0.=false,
1068 print sign=false,
1069 dec sep=.,
1070 assume math mode,
1071 frac TeX=\pgfmathfloatfrac@verbatim,
1072 frac whole format/.code={\def\pgfmathresult{##1 }},
1073 @dec sep mark=,
1074 @sci exponent mark=,
1075 }%
1076 },
1077 % sci may skip mantissa/.is if=pgfmathfloatround@allow@empty@mantissa,
1078 % sci may skip mantissa/.default=true,
1079 }
1080
1081
1082
1083 \def\pgfmathprintnumber@STD#1{%
1084 % parse the input:
1085 \pgfmathfloatparsenumber{#1}%
1086 \pgfmathfloat@to@FMeE@style\pgfmathresult
1087 \expandafter\pgfmathprintnumber@STD@issci\pgfmathresult\relax
1088 }
1089
1090 \def\pgfmathprintnumber@STD@setparam#1{%
1091 \edef\pgfmathfloat@loc@TMPb{#1}%
1092 \ifx\pgfmathfloat@loc@TMPb\pgfutil@empty
1093 % DEFAULT for lower and upper bound.
1094 \def\pgfmathprintnumber@STD@getlowerbound{%
1095 \c@pgf@counta=\pgfmathfloat@round@precision@orig\relax
1096 \divide\c@pgf@counta by-2\relax
1097 }%
1098 \def\pgfmathprintnumber@STD@upperbound{4}%
1099 \else
1100 \expandafter\pgfutil@in@\expandafter:\expandafter{\pgfmathfloat@loc@TMPb}%
1101 \ifpgfutil@in@
1102 % we have -4:5 or something like that.
1103 % parse both values:
1104 \def\pgfmathfloat@loc@TMPa##1:##2\relax{%
1105 \edef\pgfmathprintnumber@STD@getlowerbound{%
1106 \noexpand\c@pgf@counta=##1\space
1107 }%
1108 \edef\pgfmathprintnumber@STD@upperbound{##2}%
1109 }%
1110 \expandafter\pgfmathfloat@loc@TMPa\pgfmathfloat@loc@TMPb\relax
1111 \else
1112 % we have just the lower bound:
1113 \def\pgfmathprintnumber@STD@upperbound{4}%
1114 \edef\pgfmathprintnumber@STD@getlowerbound{%
1115 \noexpand\c@pgf@counta=\pgfmathfloat@loc@TMPb\space
1116 }%
1117 \fi
1118 \fi
1119 }%
1120
1121 \def\pgfmathprintnumber@STD@issci#1#2e#3\relax{%
1122 \expandafter\ifnum#1<3
1123 \expandafter\ifnum#3>\pgfmathprintnumber@STD@upperbound\relax
1124 \pgfmathprintnumber@SCI@issci#1#2e#3\relax%
1125 \else
1126 \begingroup
1127 \pgfmathprintnumber@STD@getlowerbound
1128 \ifnum#3<\c@pgf@counta
1129 \pgfmathprintnumber@SCI@issci#1#2e#3\relax%
1130 \else
1131 \pgfmathprintnumber@FIXED@issci#1#2e#3\relax%
1132 \fi
1133 \pgfmath@smuggleone\pgfmathresult
1134 \endgroup
1135 \fi
1136 \else% nan or inf:
1137 \pgfmathfloatrounddisplaystyle#1#2e#3\relax%
1138 \fi
1139 }
1140
1141 \def\pgfmathprintnumber@RELATIVE#1{%
1142 % parse the input:
1143 \pgfmathfloatparsenumber{#1}%
1144 \pgfmathfloat@to@FMeE@style\pgfmathresult
1145 \expandafter\pgfmathprintnumber@RELATIVE@issci\pgfmathresult\relax
1146 }
1147
1148 \def\pgfmathprintnumber@RELATIVE@choice@roundtofixed@warn{%
1149 \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.}%
1150 \global\let\pgfmathprintnumber@RELATIVE@choice@roundtofixed@warn=\relax
1151 }
1152
1153 \def\pgfmathprintnumber@RELATIVE@issci#1#2e#3\relax{%
1154 \begingroup
1155 % format X / 10^{relative}:
1156 \c@pgf@counta=#3\relax
1157 \advance\c@pgf@counta by-\pgfmathprintnumber@RELATIVE@param\relax
1158 \pgfmathfloatcreate{#1}{#2}{\the\c@pgf@counta}%
1159 % OK, round it to the desired precision:
1160 \if0\pgfmathprintnumber@RELATIVE@choice@roundtofixed
1161 % relative round mode=mantissa
1162 \def\b@round@fixed{0}%
1163 \else
1164 \if1\pgfmathprintnumber@RELATIVE@choice@roundtofixed
1165 % relative round mode=fixed
1166 \def\b@round@fixed{1}%
1167 \else
1168 \pgfmathprintnumber@RELATIVE@choice@roundtofixed@warn
1169 % relative round mode=compatible
1170 \ifnum\c@pgf@counta>0
1171 % hm. for positive exponents, we should round the
1172 % mantissa rather than only the fractional part.
1173 \def\b@round@fixed{0}%
1174 \else
1175 % negative exponent -> round fixed representation:
1176 \def\b@round@fixed{1}%
1177 \fi
1178 \fi
1179 \fi
1180 \if1\b@round@fixed
1181 % round fixed representation:
1182 \pgfmathfloattofixed\pgfmathresult
1183 \expandafter\pgfmathroundto\expandafter{\pgfmathresult}%
1184 \pgfmathfloatparsenumber{\pgfmathresult}%
1185 \pgfmathfloatroundhasperiodtrue% make sure the code below works:
1186 \else
1187 % round the mantissa:
1188 \expandafter\pgfmathfloatround\expandafter{\pgfmathresult}%
1189 \fi
1190 % Now, compute result * 10^{relative} and format the result:
1191 \pgfmathfloattoregisterstok\pgfmathresult\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
1192 \ifnum\pgfmathfloat@a@S=0
1193 \pgfmathfloat@a@E=\pgfmathfloat@a@S % avoid 0 * 10^8
1194 \else
1195 \advance\pgfmathfloat@a@E by+\pgfmathprintnumber@RELATIVE@param\relax
1196 \fi
1197 \edef\pgfmathresultX{%
1198 \the\pgfmathfloat@a@S
1199 \the\pgfmathfloat@a@Mtok
1200 \ifpgfmathfloatroundhasperiod\else.0\fi
1201 e\the\pgfmathfloat@a@E}%
1202 % call another formatter for the result (but avoid rounding inside of it):
1203 \pgfqkeys{/pgf/number format}{/pgf/number format/every relative,
1204 fixed zerofill=false,% useless here!
1205 sci zerofill=false}%
1206 \ifx\pgfmathprintnumber@issci\pgfmathprintnumber@RELATIVE@issci
1207 \pgfmath@error{The '/pgf/number format/every relative' style should set a valid display style}%
1208 \fi
1209 \let\pgfmathfloat@round@precision@orig=\pgfmathfloat@round@precision
1210 \def\pgfmathfloat@round@precision{9999}%
1211 \expandafter\pgfmathprintnumber@issci\pgfmathresultX\relax%
1212 \pgfmath@smuggleone\pgfmathresult
1213 \endgroup
1214 }
1215
1216 \def\pgfmathprintnumber@FIXED@RELATIVE#1{%
1217 % parse the input:
1218 \pgfmathfloatparsenumber{#1}%
1219 \pgfmathfloat@to@FMeE@style\pgfmathresult
1220 \expandafter\pgfmathprintnumber@FIXED@RELATIVE@issci\pgfmathresult\relax
1221 }
1222
1223 \def\pgfmathprintnumber@FIXED@RELATIVE@issci#1#2e#3\relax{%
1224 \begingroup
1225 \pgfmathfloatcreate{#1}{#2}{#3}%
1226 % we want the first <precision> digits - not the first
1227 % <precision>+1 digits:
1228 \c@pgf@counta=\pgfmathfloat@round@precision\relax
1229 \advance\c@pgf@counta by-1
1230 \edef\pgfmathfloat@round@precision{\the\c@pgf@counta}%
1231 \pgfmathfloatround{\pgfmathresult}%
1232 \pgfmathfloattoregisterstok\pgfmathresult\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
1233 \ifnum\pgfmathfloat@a@S=0
1234 \pgfmathfloat@a@E=\pgfmathfloat@a@S % avoid 0 * 10^8
1235 \fi
1236 \edef\pgfmathresultX{%
1237 \the\pgfmathfloat@a@S
1238 \the\pgfmathfloat@a@Mtok
1239 \ifpgfmathfloatroundhasperiod\else.0\fi
1240 e\the\pgfmathfloat@a@E}%
1241 \let\pgfmathfloat@round@precision@orig=\pgfmathfloat@round@precision
1242 \pgfmathfloat@usezerofill@fixedfalse
1243 \def\pgfmathfloat@round@precision{9999}% typeset all remaining digits!
1244 \expandafter\pgfmathprintnumber@FIXED@issci\pgfmathresultX\relax%
1245 \pgfmath@smuggleone\pgfmathresult
1246 \endgroup
1247 }
1248
1249 \def\pgfmathprintnumber@frac#1{%
1250 % parse the input:
1251 \pgfmathfloatparsenumber{#1}%
1252 \pgfmathfloatgetfrac{\pgfmathresult}%
1253 \expandafter\pgfmathprintnumber@frac@formatresult\pgfmathresult
1254 }
1255 \def\pgfmathprintnumber@frac@issci#1#2e#3\relax{%
1256 \pgfmathfloatcreate{#1}{#2}{#3}%
1257 \pgfmathfloatgetfrac{\pgfmathresult}%
1258 \expandafter\pgfmathprintnumber@frac@formatresult\pgfmathresult
1259 }
1260 \def\pgfmathprintnumber@frac@formatresult#1#2#3{%
1261 \begingroup
1262 \pgfkeysgetvalue{/pgf/number format/frac TeX}\pgfmathresult
1263 \toks0=\expandafter{\pgfmathresult}%
1264 \def\pgfmathfloat@loc@TMPa{#1}%
1265 \ifx\pgfmathfloat@loc@TMPa\pgfutil@empty
1266 \ifpgfmathprintnumber@showpositive
1267 \def\pgfmathfloat@loc@TMPa{+}%
1268 \fi
1269 \else
1270 \ifx\pgfmathfloat@loc@TMPa-%
1271 \else
1272 \ifx\pgfmathfloat@loc@TMPa+%
1273 \else
1274 \ifpgfmathprintnumber@showpositive
1275 \edef\pgfmathfloat@loc@TMPa{+\pgfmathfloat@loc@TMPa}%
1276 \fi
1277 \def\pgfmathfloat@loc@TMPb{\pgfkeysvalueof{/pgf/number format/frac whole format/.@cmd}}%
1278 \expandafter\pgfmathfloat@loc@TMPb\pgfmathfloat@loc@TMPa\pgfeov
1279 \let\pgfmathfloat@loc@TMPa=\pgfmathresult
1280 \fi
1281 \fi
1282 \fi
1283 \toks1=\expandafter{\pgfmathfloat@loc@TMPa}%
1284 \edef\pgfmathresult{%
1285 \the\toks1 \ifnum#2=0 \else\the\toks0 {#2}{#3}\fi%
1286 }%
1287 \pgfmath@smuggleone\pgfmathresult
1288 \endgroup
1289 }%
1290
1291 % Defines \pgfmathresult to contain three sets of braces containing
1292 % the sign (optionally containing any components >1), the numerator and the denominator for #1.
1293 %
1294 % \pgfmathfloatgetfrac{0.5} -> \pgfmathresult contains {}{1}{2}
1295 % \pgfmathfloatgetfrac{-0.5} -> \pgfmathresult contains {-}{1}{2}
1296 % \pgfmathfloatgetfrac{1.5} -> \pgfmathresult contains {1}{1}{2}
1297 %
1298 % special cases:
1299 % \pgfmathfloatgetfrac{0} -> \pgfmathresult contains {0}{0}{1}
1300 % \pgfmathfloatgetfrac{1} -> \pgfmathresult contains {1}{0}{1}
1301 %
1302 % The numerator and denominator is always a number (not empty)
1303 \def\pgfmathfloatgetfrac#1{%
1304 \pgfutil@ifundefined{pgfmathfloatmultiply@}{%
1305 \pgfmath@PackageError{Sorry, the number format 'frac' requires '\string\usetikzlibrary{fpu}' (and, optionally, \string\usepackage{fp}) in order to work correctly}%
1306 \edef\pgfmathresult{{#1}{0}{1}}%
1307 }{%
1308 \pgfmathfloatgetfrac@{#1}%
1309 }%
1310 }%
1311 \def\pgfmathfloatgetfrac@#1{%
1312 \begingroup
1313 \edef\pgfmathfloat@arg{#1}%
1314 \expandafter\pgfmathfloat@decompose@tok\pgfmathfloat@arg\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
1315 \def\pgfmathfloat@loc@TMPa{0}%
1316 \ifcase\pgfmathfloat@a@S
1317 % #1 = 0:
1318 \def\pgfmathresult{{0}{0}{1}}%
1319 \or% #1 > 0
1320 \pgfmathfloat@a@S=1
1321 \def\pgfmathfloat@loc@TMPa{1}%
1322 \or% #1 < 0
1323 \pgfmathfloat@a@S=-1
1324 \def\pgfmathfloat@loc@TMPa{1}%
1325 \or
1326 \edef\pgfmathresult{{}{NaN}{1}}%
1327 \or
1328 \edef\pgfmathresult{{}{\infty}{1}}%
1329 \or
1330 \edef\pgfmathresult{{-}{\infty}{1}}%
1331 \fi
1332 \if1\pgfmathfloat@loc@TMPa
1333 \ifnum\pgfmathfloat@a@E<0
1334 \def\pgfmathfloat@wholenumber{}%
1335 \else
1336 \pgfmathfloatcreate{1}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}%
1337 \pgfmathfloattofixed\pgfmathresult%
1338 \def\pgfmathfloat@loc@TMPa##1.##2\relax{%
1339 \def\pgfmathfloat@wholenumber{##1}%
1340 \pgfmathfloatparsenumber{0.##2}%
1341 }%
1342 \expandafter\pgfmathfloat@loc@TMPa\pgfmathresult\relax
1343 \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@b@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
1344 \fi
1345 %
1346 \def\pgfmathfloat@loc@TMPa##1.##2\relax{%
1347 \def\pgfmathfloat@mantissa@first{##1}%
1348 \def\pgfmathfloat@mantissa@ltone{0.##2}%
1349 }%
1350 \expandafter\pgfmathfloat@loc@TMPa\the\pgfmathfloat@a@Mtok\relax
1351 %
1352 \def\pgfmathfloat@loc@@to@int##1.##2\relax##3{%
1353 ##3=##1
1354 \ifdim0.##2pt>0.5pt
1355 \advance##3 by1
1356 \fi
1357 }%
1358 %
1359 % alias registers names:
1360 \let\pgfmathresultnumerator=\pgfmathfloat@b@S
1361 \let\pgfmathresultdenom=\pgfmathfloat@b@E
1362 %
1363 \pgfkeysgetvalue{/pgf/number format/frac denom}\pgfmath@target@denominator
1364 \ifx\pgfmath@target@denominator\pgfutil@empty
1365 %
1366 \pgfmathfloat@a@E=-\pgfmathfloat@a@E
1367 \ifdim\pgfmathfloat@mantissa@ltone pt=0pt
1368 \def\pgfmathfloat@factor{1}%
1369 \edef\pgfmathfloat@scaled@numerator{\the\pgfmathfloat@a@Mtok}%
1370 \else
1371 % FIXME : this here is numerically instable.
1372 %
1373 % The errors of 1/r are magnified by 10^k which
1374 % doesn't work.
1375 \pgfutil@ifundefined{FPdiv}{%
1376 \pgfmathfloatparsenumber{\pgfmathfloat@mantissa@ltone}%
1377 \pgfmathfloatreciprocal@{\pgfmathresult}%
1378 }{%
1379 % \usepackage{fp}.
1380 % yields higher absolute precision.
1381 \FPmessagesfalse%
1382 \FPdebugfalse%
1383 \FPdiv\pgfmathresult{1}{\pgfmathfloat@mantissa@ltone}%
1384 \pgfmathfloatparsenumber{\pgfmathresult}%
1385 }%
1386 \let\pgfmathfloat@inv=\pgfmathresult
1387 \pgfmathfloatcreate{1}{1.0}{\pgfkeysvalueof{/pgf/number format/frac shift}}%
1388 \let\pgfmathfloat@scalebaseten=\pgfmathresult
1389 \pgfmathfloatmultiply@{\pgfmathfloat@inv}{\pgfmathfloat@scalebaseten}%
1390 \let\pgfmathfloat@factor=\pgfmathresult
1391 %
1392 \expandafter\pgfmathfloatparsenumber\expandafter{\the\pgfmathfloat@a@Mtok}%
1393 \let\pgfmathfloat@loc@TMPa=\pgfmathresult
1394 \pgfmathfloatmultiply@{\pgfmathfloat@factor}{\pgfmathfloat@loc@TMPa}%
1395 \pgfmathfloattofixed\pgfmathresult
1396 \let\pgfmathfloat@scaled@numerator=\pgfmathresult
1397 %
1398 \pgfmathfloattofixed\pgfmathfloat@factor
1399 \expandafter\pgfmathfloat@loc@@to@int\pgfmathresult\relax{\pgfmathfloat@b@S}%
1400 \edef\pgfmathfloat@factor{\the\pgfmathfloat@b@S}%
1401 \fi
1402 %
1403 %
1404 \pgfmathresultdenom=\pgfmathfloat@factor\relax
1405 \pgfmathfloat@multiply@ten@to@the@E\pgfmathresultdenom
1406 %
1407 \expandafter\pgfmathfloat@loc@@to@int\pgfmathfloat@scaled@numerator\relax{\pgfmathresultnumerator}%
1408 %\message{scale = \pgfmathfloat@factor; Z = \the\pgfmathresultnumerator\space ( von \pgfmathfloat@scaled@numerator), N = \the\pgfmathresultdenom.}%
1409 %
1410 \pgfmathgreatestcommondivisor{\pgfmathresultnumerator}{\pgfmathresultdenom}%
1411 \divide\pgfmathresultnumerator by\pgfmathresult\relax
1412 \divide\pgfmathresultdenom by\pgfmathresult\relax
1413 \ifpgfmathprintnumber@frac@warn
1414 \ifnum\pgfmathresultdenom>1000
1415 \pgfutil@ifundefined{FPdiv}{%
1416 \pgfmathfloattosci@\pgfmathfloat@arg
1417 \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.}%
1418 }{}%
1419 \fi
1420 \fi
1421 \else
1422 % use target denominator:
1423 \pgfmathresultdenom=\pgfmath@target@denominator\relax
1424 \pgfmathfloatcreate{1}{\the\pgfmathfloat@a@Mtok}{\the\pgfmathfloat@a@E}%
1425 \pgfmathfloattofixed\pgfmathresult
1426 \pgf@xa=\pgfmathresult pt
1427 \multiply\pgf@xa by\pgfmathresultdenom
1428 \edef\pgfmathfloat@scaled@numerator{\pgf@sys@tonumber\pgf@xa}%
1429 \expandafter\pgfmathfloat@loc@@to@int\pgfmathfloat@scaled@numerator\relax{\pgfmathresultnumerator}%
1430 \fi
1431 \ifpgfmathprintnumber@frac@whole
1432 \else
1433 \ifx\pgfmathfloat@wholenumber\pgfutil@empty
1434 \else
1435 \count0=\pgfmathfloat@wholenumber\relax
1436 \multiply\count0 by\pgfmathresultdenom
1437 \advance\pgfmathresultnumerator by\count0
1438 \def\pgfmathfloat@wholenumber{}%
1439 \fi
1440 \fi
1441 \ifnum\pgfmathfloat@a@S<0
1442 \edef\pgfmathresult{{-\pgfmathfloat@wholenumber}{\the\pgfmathresultnumerator}{\the\pgfmathresultdenom}}%
1443 \else
1444 \edef\pgfmathresult{{\pgfmathfloat@wholenumber}{\the\pgfmathresultnumerator}{\the\pgfmathresultdenom}}%
1445 \fi
1446 \fi
1447 \pgfmath@smuggleone\pgfmathresult
1448 \endgroup
1449 }%
1450 \def\pgfmathfloat@gobble@until@relax#1\relax{}
1451
1452 % computes the greatest common divisor of two integer numbers (in
1453 % integer arithmetics).
1454 \def\pgfmathgreatestcommondivisor#1#2{%
1455 \begingroup
1456 \count0=#1\relax
1457 \count1=#2\relax
1458 \ifnum\count0=0
1459 \edef\pgfmathresult{\the\count1}%
1460 \else
1461 \pgfmathgreatestcommondivisor@loop
1462 \edef\pgfmathresult{\the\count0}%
1463 \fi
1464 \pgfmath@smuggleone\pgfmathresult
1465 \endgroup
1466 }
1467 \def\pgfmathgreatestcommondivisor@loop{%
1468 \ifnum\count1=0
1469 \else
1470 \ifnum\count0>\count1
1471 \advance\count0 by-\count1
1472 \else
1473 \advance\count1 by-\count0
1474 \fi
1475 \expandafter\pgfmathgreatestcommondivisor@loop
1476 \fi
1477 }%
1478
1479 % multiplies a TeX register by 10^E where E is stored in the register
1480 % \pgfmathfloat@a@E (and it should be positive!)%
1481 %
1482 % #1 a TeX register
1483 \def\pgfmathfloat@multiply@ten@to@the@E#1{%
1484 \ifnum\pgfmathfloat@a@E>0
1485 \multiply#1 by10
1486 \advance\pgfmathfloat@a@E by-1
1487 \def\pgfmathfloat@multiply@ten@to@the@E@next{\pgfmathfloat@multiply@ten@to@the@E{#1}}%
1488 \else
1489 \let\pgfmathfloat@multiply@ten@to@the@E@next=\relax%
1490 \fi
1491 \pgfmathfloat@multiply@ten@to@the@E@next
1492 }%
1493
1494 \def\pgfmathprintnumber@INT@TRUNC#1{%
1495 \pgfmathfloatparsenumber{#1}%
1496 \pgfmathfloat@to@FMeE@style\pgfmathresult
1497 \expandafter\pgfmathprintnumber@INT@TRUNC@issci\pgfmathresult\relax
1498 }
1499
1500 \def\pgfmathprintnumber@INT@TRUNC@impl#1.#2\relax#3#4e#5\relax{%
1501 \pgfmathfloatroundhasperiodfalse
1502 \pgfmathprintnumber@fixed@style{#1}#3#4e#5\relax%
1503 }
1504 \def\pgfmathprintnumber@INT@TRUNC@issci#1#2e#3\relax{%
1505 \ifnum#1<3\relax
1506 \pgfmathfloatcreate{#1}{#2}{#3}%
1507 \pgfmathfloattofixed{\pgfmathresult}%
1508 \expandafter\pgfmathprintnumber@INT@TRUNC@impl\pgfmathresult\relax#1#2e#3\relax
1509 \else
1510 \pgfmathfloatrounddisplaystyle#1#2e#3\relax%
1511 \fi
1512 }
1513
1514 % Invokes '#2' if '#1' is actually an integer or '#3' if not.
1515 %
1516 % As a side--effect, \pgfretval will be set to the integer value if it
1517 % actually *is* an integer. Otherwise, \pgfretval will contain the
1518 % parsed floating point number.
1519 %
1520 % #1 a number constant (not necessarily a parsed float).
1521 \def\pgfmathifisint#1#2#3{%
1522 \gdef\pgfmathfloatisint@@{0}%
1523 \begingroup
1524 \pgfmathfloatparsenumber{#1}%
1525 \let\pgfretval\pgfmathresult
1526 \pgfmathfloat@to@FMeE@style\pgfmathresult
1527 \expandafter\pgfmathfloatisint@\pgfmathresult\relax
1528 \pgfmath@smuggleone\pgfretval
1529 \endgroup
1530 \if1\pgfmathfloatisint@@ #2\else #3\fi
1531 }%
1532 \def\pgfmathfloatisint@#1#2e#3\relax{%
1533 \ifnum#1<3\relax
1534 \pgfmathfloatcreate{#1}{#2}{#3}%
1535 \pgfmathfloattofixed{\pgfmathresult}%
1536 \def\pgfmathfloat@round@precision{6}%
1537 \expandafter\pgfmathroundto\expandafter{\pgfmathresult}%
1538 \ifpgfmathfloatroundhasperiod
1539 \else
1540 \let\pgfretval\pgfmathresult%
1541 \gdef\pgfmathfloatisint@@{1}%
1542 \fi
1543 \fi
1544 }
1545
1546 \def\pgfmathprintnumber@INT@DETECT#1{%
1547 \pgfmathfloatparsenumber{#1}%
1548 \pgfmathfloat@to@FMeE@style\pgfmathresult
1549 \expandafter\pgfmathprintnumber@INT@DETECT@issci\pgfmathresult\relax
1550 }
1551
1552 \def\pgfmathprintnumber@INT@DETECT@issci#1#2e#3\relax{%
1553 \begingroup
1554 \ifnum#1<3\relax
1555 \pgfmathfloatcreate{#1}{#2}{#3}%
1556 \pgfmathfloattofixed{\pgfmathresult}%
1557 \let\pgfmathfloat@round@precision@=\pgfmathfloat@round@precision
1558 \def\pgfmathfloat@round@precision{6}%
1559 \expandafter\pgfmathroundto\expandafter{\pgfmathresult}%
1560 \let\pgfmathfloat@round@precision=\pgfmathfloat@round@precision@
1561 \ifpgfmathfloatroundhasperiod
1562 \pgfmathprintnumber@SCI@issci#1#2e#3\relax
1563 \else
1564 \expandafter\pgfmathprintnumber@fixed@style\expandafter{\pgfmathresult}#1#2e#3\relax
1565 \fi
1566 \else
1567 \pgfmathfloatrounddisplaystyle#1#2e#3\relax%
1568 \fi
1569 \pgfmath@smuggleone\pgfmathresult
1570 \endgroup
1571 }
1572
1573 \def\pgfmathprintnumber@FIXED#1{%
1574 \pgfmathfloatparsenumber{#1}%
1575 \pgfmathfloat@to@FMeE@style\pgfmathresult
1576 \expandafter\pgfmathprintnumber@FIXED@issci\pgfmathresult\relax
1577 }
1578
1579 \def\pgfmathprintnumber@FIXED@issci#1#2e#3\relax{%
1580 \begingroup
1581 \ifnum#1<3
1582 \pgfmathfloatcreate{#1}{#2}{#3}%
1583 \pgfmathfloattofixed{\pgfmathresult}%
1584 \ifpgfmathfloat@usezerofill@fixed
1585 \expandafter\pgfmathroundtozerofill\expandafter{\pgfmathresult}%
1586 \else
1587 \expandafter\pgfmathroundto\expandafter{\pgfmathresult}%
1588 \fi
1589 \ifpgfmathfloatroundmayneedrenormalize
1590 \pgfmathfloat@a@E=#3\relax
1591 \advance\pgfmathfloat@a@E by1
1592 \edef\pgfmathfloat@loc@TMPb{\noexpand\pgfmathprintnumber@fixed@style{\pgfmathresult}#1#2e\the\pgfmathfloat@a@E}%
1593 \pgfmathfloat@loc@TMPb\relax%
1594 \else
1595 \expandafter\pgfmathprintnumber@fixed@style\expandafter{\pgfmathresult}#1#2e#3\relax%
1596 \fi
1597 \else% nan or inf:
1598 \pgfmathfloatrounddisplaystyle#1#2e#3\relax%
1599 \fi
1600 \pgfmath@smuggleone\pgfmathresult
1601 \endgroup
1602 }
1603
1604
1605 \def\pgfmathprintnumber@SCI#1{%
1606 \pgfmathfloatparsenumber{#1}%
1607 \pgfmathfloat@to@FMeE@style\pgfmathresult
1608 \expandafter\pgfmathprintnumber@SCI@issci\pgfmathresult\relax
1609 }
1610
1611 \def\pgfmathprintnumber@SCI@issci#1#2e#3\relax{%
1612 \begingroup
1613 \pgfmathfloatcreate{#1}{#2}{#3}%
1614 \edef\pgfmathfloat@round@precision{\pgfmathprintnumber@sci@precision}%
1615 \ifpgfmathfloat@usezerofill@sci
1616 \pgfmathfloatroundzerofill{\pgfmathresult}%
1617 \else
1618 \pgfmathfloatround{\pgfmathresult}%
1619 \fi
1620 \pgfmathfloat@to@FMeE@style\pgfmathresult
1621 \expandafter\pgfmathfloatrounddisplaystyle\pgfmathresult\relax
1622 \pgfmath@smuggleone\pgfmathresult
1623 \endgroup
1624 }
1625
1626 % Prints argument #1 using the current pretty printer environment (all
1627 % variables in /pgf/number format).
1628 %
1629 % You may specify optional arguments with \pgfmathprintnumber[...].
1630 \def\pgfmathprintnumber{%
1631 % \protect allows to supply \pgfmathprintnumber inside of latex
1632 % captions. The \csname yields \relax in case protect is undefined.
1633 \pgf@texdist@protect\pgfmathprintnumber@protected
1634 }%
1635 \def\pgfmathprintnumber@protected{%
1636 \pgfutil@ifnextchar[%
1637 {\pgfmathprintnumber@OPT}%
1638 {\pgfmathprintnumber@noopt}%
1639 }
1640
1641 \def\pgfmathprintnumber@noopt#1{%
1642 \pgfmathprintnumber@{#1}%
1643 \ifpgfmathprintnumber@assumemathmode
1644 \pgfmathresult
1645 \else
1646 \pgfutilensuremath{\pgfmathresult}%
1647 \fi
1648 }%
1649 \def\pgfmathprintnumber@OPT[#1]#2{%
1650 \begingroup
1651 \pgfqkeys{/pgf/number format}{#1}%
1652 \pgfmathprintnumber@{#2}%
1653 \ifpgfmathprintnumber@assumemathmode
1654 \pgfmathresult
1655 \else
1656 \pgfutilensuremath{\pgfmathresult}%
1657 \fi
1658 \endgroup
1659 }%
1660
1661 % As \pgfmathprintnumber, but it produces its output into the second
1662 % argument.
1663 \def\pgfmathprintnumberto{%
1664 \pgfutil@ifnextchar[%
1665 {\pgfmathprintnumberto@OPT}%
1666 {\pgfmathprintnumberto@noopt}%
1667 }
1668
1669 \def\pgfmathprintnumberto@noopt#1#2{%
1670 \begingroup
1671 \pgfmathprintnumber@{#1}%
1672 \ifpgfmathprintnumber@assumemathmode
1673 \global\let\pgfmathfloat@glob@TMP=\pgfmathresult
1674 \else
1675 \toks0=\expandafter{\pgfmathresult}%
1676 \xdef\pgfmathfloat@glob@TMP{\noexpand\pgfutilensuremath{\the\toks0 }}%
1677 \fi
1678 \endgroup
1679 \let#2=\pgfmathfloat@glob@TMP
1680 }%
1681 \def\pgfmathprintnumberto@OPT[#1]#2#3{%
1682 \begingroup
1683 \pgfqkeys{/pgf/number format}{#1}%
1684 \pgfmathprintnumber@{#2}%
1685 \ifpgfmathprintnumber@assumemathmode
1686 \global\let\pgfmathfloat@glob@TMP=\pgfmathresult
1687 \else
1688 \toks0=\expandafter{\pgfmathresult}%
1689 \xdef\pgfmathfloat@glob@TMP{\noexpand\pgfutilensuremath{\the\toks0 }}%
1690 \fi
1691 \endgroup
1692 \let#3=\pgfmathfloat@glob@TMP
1693 }%
1694
1695
1696 % Changes the current number pretty printer to #1.
1697 %
1698 % #1 is the macro base name for the pretty print routine, without the
1699 % leading '\'.
1700 \def\pgfmath@set@number@printer#1{%
1701 \expandafter\let\expandafter\pgfmathprintnumber@\csname #1\endcsname
1702 \expandafter\let\expandafter\pgfmathprintnumber@issci\csname #1@issci\endcsname
1703 }
1704
1705 \pgfkeys{/pgf/number format/std}
1706
1707 %%%%%%%%%%%%%%%%%%%%%%%%%%
1708 %
1709 % IMPL
1710 %
1711 %%%%%%%%%%%%%%%%%%%%%%%%%%
1712
1713 % equals only itsself when compared with \ifx:
1714 \def\pgfmathfloat@EOI{\pgfmathfloat@EOI}%
1715
1716 % Re-use counters internally.
1717 %
1718 % They are always grouped and only used inside of the rounding
1719 % routines.
1720 \let\c@pgfmathroundto@prec=\pgfmathfloat@b@S% ATTENTION: DOUBLE-USED REGISTERS!
1721 \let\c@pgfmathroundto@offsetbehindperiod=\pgfmathfloat@b@E
1722 \newcount\c@pgfmathroundto@lastzeros
1723
1724 \newif\ifpgfmathround@impl@PREPERIOD@is@negative@zero
1725
1726 % PRECONDITION:
1727 % \ifpgfmathfloatroundhasperiod=\iftrue holds outside of the
1728 % current TeX group.
1729 %
1730 % POSTCONDITION:
1731 % \ifpgfmathfloatroundhasperiod will be set correctly AFTER the
1732 % current TeX group.
1733 % \ifpgfmathfloatroundmayneedrenormalize will be set globally
1734 \def\pgfmathroundto@impl#1{%
1735 \edef\pgfmathround@input{#1}%
1736 \global\pgfmathfloatroundmayneedrenormalizefalse
1737 \pgfmathfloat@tmptoks={}%
1738 \let\pgfmathround@next=\pgfutil@empty
1739 \let\pgfmathround@cur=\pgfutil@empty
1740 \let\pgfmathresult=\pgfutil@empty
1741 \expandafter\c@pgfmathroundto@prec\pgfmathfloat@round@precision\relax
1742 \c@pgfmathroundto@lastzeros=0
1743 \c@pgfmathroundto@offsetbehindperiod=-1 % means: no period found so far
1744 \pgfmathround@impl@PREPERIOD@is@negative@zerotrue
1745 \expandafter\pgfmathroundto@impl@ITERATE@NODOT@firstcall\pgfmathround@input\pgfmathfloat@EOI
1746 }
1747
1748 % \pgfmathroundto implementation in WORDS:
1749 %
1750 % coarse idea:
1751 % 1. collect all digits/sign BEFORE the first period in REVERSE order
1752 % 2. then, collect UP TO \prec digits after the period in REVERSE order
1753 % Steps 1. and 2. lead to the digit [sign] sequence
1754 % "x_{-p} x_{-p+1} ... x_{-2} x_{-1} '.' x_0 ... x_r"
1755 % where 'r' is the total number of digits. The integer 'p' denotes the
1756 % ACTUALLY collected number of digits behind the period.
1757 %
1758 % Let 'k' be the desired precision.
1759 %
1760 % Please note that pgfmathroundto rounds the mantissa, that means |abs(x)|.
1761 %
1762 % There are exactly TWO cases:
1763 % 1. The case with p<=k and x_{-p-1} = end of input.
1764 % 2. The case with p=k and x_{-p-1} is a further, next character.
1765 %
1766 % Then, for case 1.):
1767 % discard any unused zeros at the tail of our number (possibly
1768 % including the period)
1769 %
1770 % and in case 2.)
1771 % if NEXT DIGIT < 5:
1772 % do exactly the same as in case 1.) above and discard any
1773 % following digits.
1774 % else
1775 % let q := -p
1776 % while(x_q = 9 and q<=r )
1777 % if q>=0
1778 % set x_q = '0'
1779 % else
1780 % discard digit x_q='9'
1781 % fi
1782 % ++q
1783 % if q=0
1784 % discard the period
1785 % fi
1786 % end while
1787 % if q = r+1
1788 % insert a '1'
1789 % else
1790 % set x_q = x_q + 1
1791 % fi
1792 % fi
1793 %
1794 % All these loops have been implemented in spaghetti-code below.
1795 % Sorry, I fear its hard to understand. In principle, everything is
1796 % realised using more or less finite state machines (with some number
1797 % counting logic).
1798 %
1799 % Some comments:
1800 % - The token register \pgfmathfloat@tmptoks is used to accumulate the REVERSED input number.
1801 % - \pgfmathfloat@EOI always denotes 'END OF INPUT'.
1802 % - in the second stage, we need to reverse \pgfmathfloat@tmptoks.
1803 % This is -again- done with \pgfmathfloat@tmptoks.
1804
1805 \def\pgfmathroundto@impl@discard@period#1.#2\pgfmathfloat@EOI{%
1806 \pgfmathfloatroundhasperiodfalse
1807 \aftergroup\pgfmathfloatroundhasperiodfalse
1808 \def\pgfmathresult{#1}%
1809 }
1810
1811 \def\pgfmathroundto@impl@gobble@rest@and@start#1\pgfmathfloat@EOI{%
1812 \pgfmathroundto@impl@start
1813 }
1814 \def\pgfmathroundto@impl@gobble@and@start\pgfmathfloat@EOI{%
1815 \pgfmathroundto@impl@start
1816 }
1817 \def\pgfmathroundto@impl@gobble\pgfmathfloat@EOI{}%
1818 \def\pgfmathroundto@impl@gobble@rest#1\pgfmathfloat@EOI{}%
1819
1820 % This method will be invoked as soon as the first step, the reverse
1821 % collection of up to PREC digits after the period, has finished.
1822 \def\pgfmathroundto@impl@start{%
1823 \ifx\pgfmathround@next\pgfutil@empty
1824 \ifnum\c@pgfmathroundto@offsetbehindperiod<0
1825 % no period found.
1826 \ifpgfmathfloat@fixed@digits@after@period
1827 \ifnum\c@pgfmathroundto@prec=0\relax
1828 \pgfmathfloatroundhasperiodfalse
1829 \aftergroup\pgfmathfloatroundhasperiodfalse
1830 \edef\pgfmathresult{\pgfmathround@input}%
1831 \else
1832 \pgfmathfloat@tmptoks=\expandafter{\pgfmathround@input.}%
1833 \c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec
1834 \pgfmathroundto@impl@append@zeros
1835 \edef\pgfmathresult{\the\pgfmathfloat@tmptoks}%
1836 \fi
1837 \else
1838 \pgfmathfloatroundhasperiodfalse
1839 \aftergroup\pgfmathfloatroundhasperiodfalse
1840 \edef\pgfmathresult{\pgfmathround@input}%
1841 \fi
1842 \else
1843 %\ifnum\c@pgfmathroundto@offsetbehindperiod>\c@pgfmathroundto@prec
1844 % \pgfmath@error{Internal logic error in pgfmathroundto at [I] - should not have happened!?}{}%
1845 %\fi
1846 \pgfmathroundto@impl@finish@with@truncation
1847 \fi
1848 \else
1849 %\ifnum\c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec
1850 %\else
1851 % \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}{}%
1852 %\fi
1853 \expandafter\ifnum\pgfmathround@next<5\relax
1854 \pgfmathroundto@impl@finish@with@truncation
1855 \else
1856 \multiply\c@pgfmathroundto@offsetbehindperiod by-1
1857 \expandafter\pgfmathroundto@impl@ADD@ONE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
1858 \fi
1859 \fi
1860 }
1861
1862 % takes the current input and decides whether trailing zeros shall be
1863 % discarded or more zeros need to be filled in.
1864 \def\pgfmathroundto@impl@finish@with@truncation{%
1865 \ifpgfmathfloat@fixed@digits@after@period
1866 \expandafter\pgfmathroundto@impl@REVERSE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
1867 \ifnum\c@pgfmathroundto@lastzeros=\c@pgfmathroundto@offsetbehindperiod
1868 \ifpgfmathround@impl@PREPERIOD@is@negative@zero
1869 % write '0.0000' instead of '-0.0000':
1870 \expandafter\pgfmathroundto@impl@discard@minus\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
1871 \fi
1872 \fi
1873 \ifnum\c@pgfmathroundto@prec=0\relax
1874 \expandafter\pgfmathroundto@impl@discard@period\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
1875 \else
1876 \advance\c@pgfmathroundto@prec by-\c@pgfmathroundto@offsetbehindperiod
1877 \c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec
1878 \pgfmathroundto@impl@append@zeros
1879 \edef\pgfmathresult{\the\pgfmathfloat@tmptoks}%
1880 \fi
1881 \else
1882 \pgfmathroundto@impl@discard@suffix@zeros
1883 \fi
1884 }
1885
1886 \def\pgfmathroundto@impl@discard@minus-#1\pgfmathfloat@EOI{\pgfmathfloat@tmptoks={#1}}%
1887
1888 % appends \c@pgfmathroundto@offsetbehindperiod zeros at the end of \pgfmathfloat@tmptoks.
1889 \def\pgfmathroundto@impl@append@zeros{%
1890 \ifnum\c@pgfmathroundto@offsetbehindperiod>0
1891 \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
1892 \advance\c@pgfmathroundto@offsetbehindperiod by-1
1893 \pgfmathroundto@impl@append@zeros
1894 \fi
1895 }
1896
1897 \def\pgfmathroundto@impl@ADD@ONE{%
1898 \pgfmathfloat@tmptoks={}% no longer needed because its old value will be read from input
1899 \pgfmathroundto@impl@ADD@ONE@ITERATE
1900 }
1901 \def\pgfmathroundto@impl@ADD@ONE@ITERATE{%
1902 \pgfutil@ifnextchar\pgfmathfloat@EOI{%
1903 \global\pgfmathfloatroundmayneedrenormalizetrue
1904 \edef\pgfmathresult{1\the\pgfmathfloat@tmptoks}%
1905 \pgfmathroundto@impl@gobble
1906 }{%
1907 \pgfutil@ifnextchar.{%
1908 \ifnum\c@pgfmathroundto@prec=0
1909 % silently discard period in special case precision=0
1910 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE@gobble@dot}%
1911 \else
1912 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@NEXT@COLLECT}%
1913 \fi
1914 \pgfmathround@nextcmd
1915 }{%
1916 \pgfutil@ifnextchar+{%
1917 \global\pgfmathfloatroundmayneedrenormalizetrue
1918 \edef\pgfmathresult{1\the\pgfmathfloat@tmptoks}%
1919 \pgfmathroundto@impl@gobble@rest
1920 }{%
1921 \pgfutil@ifnextchar-{%
1922 \global\pgfmathfloatroundmayneedrenormalizetrue
1923 \edef\pgfmathresult{-1\the\pgfmathfloat@tmptoks}%
1924 \pgfmathroundto@impl@gobble@rest
1925 }{%
1926 \pgfmathroundto@impl@ADD@ONE@NEXT
1927 }%
1928 }%
1929 }%
1930 }%
1931 }
1932
1933 \def\pgfmathroundto@impl@ADD@ONE@ITERATE@gobble@dot.{%
1934 \pgfmathfloatroundhasperiodfalse
1935 \aftergroup\pgfmathfloatroundhasperiodfalse
1936 \pgfmathroundto@impl@ADD@ONE@ITERATE
1937 }
1938
1939 \def\pgfmathroundto@impl@ADD@ONE@NEXT@COLLECT#1{%
1940 \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
1941 \pgfmathroundto@impl@ADD@ONE@ITERATE
1942 }
1943 \def\pgfmathroundto@impl@ADD@ONE@NEXT#1{%
1944 \ifnum#1=9
1945 \ifnum\c@pgfmathroundto@offsetbehindperiod<0
1946 \ifpgfmathfloat@fixed@digits@after@period
1947 \pgfmathfloat@tmptoks=\expandafter{\expandafter0\the\pgfmathfloat@tmptoks}%
1948 \else
1949 % silently DROP digit
1950 \fi
1951 \else
1952 \pgfmathfloat@tmptoks=\expandafter{\expandafter0\the\pgfmathfloat@tmptoks}%
1953 \fi
1954 \advance\c@pgfmathroundto@offsetbehindperiod by1
1955 \ifnum\c@pgfmathroundto@offsetbehindperiod=0
1956 \ifpgfmathfloat@fixed@digits@after@period
1957 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE}%
1958 \else
1959 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE@gobble@dot}%
1960 \fi
1961 \else
1962 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ADD@ONE@ITERATE}%
1963 \fi
1964 \else
1965 % re-use this counter:
1966 \c@pgfmathroundto@lastzeros=#1
1967 \advance\c@pgfmathroundto@lastzeros by1
1968 \edef\pgfmathresult{\the\c@pgfmathroundto@lastzeros\the\pgfmathfloat@tmptoks}%
1969 \pgfmathfloat@tmptoks=\expandafter{\pgfmathresult}%
1970 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@REVERSE@ITERATE}%
1971 \fi
1972 \pgfmathround@nextcmd
1973 }
1974
1975
1976 \def\pgfmathroundto@impl@discard@suffix@zeros{%
1977 \ifnum\c@pgfmathroundto@lastzeros=\c@pgfmathroundto@offsetbehindperiod
1978 \ifpgfmathround@impl@PREPERIOD@is@negative@zero
1979 \pgfmathfloatroundhasperiodfalse
1980 \aftergroup\pgfmathfloatroundhasperiodfalse
1981 \def\pgfmathresult{0}% write '0' instead of '-0'
1982 \else
1983 \expandafter\pgfmathroundto@impl@discard@period\pgfmathround@input\pgfmathfloat@EOI
1984 \fi
1985 \else
1986 \ifnum\c@pgfmathroundto@lastzeros=0
1987 \expandafter\pgfmathroundto@impl@REVERSE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
1988 \else
1989 \expandafter\pgfmathroundto@impl@discard@suffix@zeros@ITERATE\the\pgfmathfloat@tmptoks\pgfmathfloat@EOI
1990 \fi
1991 \fi
1992 }
1993
1994 % PRECONDITION:
1995 % \c@pgfmathroundto@lastzeros > 0
1996 \def\pgfmathroundto@impl@discard@suffix@zeros@ITERATE#1{%
1997 \advance\c@pgfmathroundto@lastzeros by-1
1998 \ifnum\c@pgfmathroundto@lastzeros=0
1999 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@REVERSE}%
2000 \else
2001 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@discard@suffix@zeros@ITERATE}%
2002 \fi
2003 \pgfmathround@nextcmd
2004 }
2005
2006 % Usage:
2007 % \pgfmathroundto@impl@REVERSE#1\pgfmathfloat@EOI
2008 % -> writes #1 reversed into \pgfmathfloat@tmptoks
2009 \def\pgfmathroundto@impl@REVERSE{%
2010 \pgfmathfloat@tmptoks={}%
2011 \pgfmathroundto@impl@REVERSE@ITERATE
2012 }
2013
2014 \def\pgfmathroundto@impl@REVERSE@ITERATE{%
2015 \pgfutil@ifnextchar\pgfmathfloat@EOI{%
2016 \edef\pgfmathresult{\the\pgfmathfloat@tmptoks}%
2017 \pgfmathroundto@impl@gobble
2018 }{%
2019 \pgfmathroundto@impl@REVERSE@NEXT
2020 }%
2021 }
2022
2023 \def\pgfmathroundto@impl@REVERSE@NEXT#1{%
2024 \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
2025 \pgfmathroundto@impl@REVERSE@ITERATE
2026 }
2027
2028 \def\pgfmathroundto@impl@BEGIN@DOT.{%
2029 \pgfmathfloat@tmptoks=\expandafter{\expandafter.\the\pgfmathfloat@tmptoks}%
2030 \c@pgfmathroundto@offsetbehindperiod=0
2031 \pgfmathroundto@impl@ITERATE@DOT
2032 }
2033 \def\pgfmathroundto@impl@ITERATE@DOT{%
2034 \pgfutil@ifnextchar\pgfmathfloat@EOI{%
2035 % finished.
2036 \pgfmathroundto@impl@gobble@and@start
2037 }{%
2038 \pgfmathroundto@impl@NEXT@DOT
2039 }%
2040 }
2041 \def\pgfmathroundto@impl@NEXT@DOT#1{%
2042 \ifnum\c@pgfmathroundto@offsetbehindperiod=\c@pgfmathroundto@prec
2043 \def\pgfmathround@next{#1}%
2044 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@gobble@rest@and@start}%
2045 \else
2046 \advance\c@pgfmathroundto@offsetbehindperiod by1
2047 \ifnum#1=0
2048 \advance\c@pgfmathroundto@lastzeros by1
2049 \else
2050 \c@pgfmathroundto@lastzeros=0
2051 \fi
2052 \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
2053 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ITERATE@DOT}%
2054 \fi
2055 \pgfmathround@nextcmd
2056 }%
2057
2058 % in contrast to pgfmathroundto@impl@ITERATE@NODOT, this method here
2059 % checks also for signs
2060 \def\pgfmathroundto@impl@ITERATE@NODOT@firstcall#1{%
2061 \def\pgfmathround@cur{#1}%
2062 \ifx\pgfmathround@cur\pgfmathfloat@EOI
2063 \pgfmathround@impl@PREPERIOD@is@negative@zerofalse
2064 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@start}%
2065 \else
2066 \ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@PERIOD
2067 \pgfmathround@impl@PREPERIOD@is@negative@zerofalse
2068 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@BEGIN@DOT.}%
2069 \else
2070 \ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@MINUS
2071 \else
2072 \pgfmathround@impl@PREPERIOD@is@negative@zerofalse
2073 \fi
2074 \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
2075 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ITERATE@NODOT}%
2076 \fi
2077 \fi
2078 \pgfmathround@nextcmd
2079 }
2080
2081 \def\pgfmathroundto@impl@ITERATE@NODOT#1{%
2082 \def\pgfmathround@cur{#1}%
2083 \ifx\pgfmathround@cur\pgfmathfloat@EOI
2084 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@start}%
2085 \else
2086 \ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@PERIOD
2087 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@BEGIN@DOT.}%
2088 \else
2089 \ifx\pgfmathround@cur\pgfmathfloatparsenumber@tok@ZERO
2090 \else
2091 \pgfmathround@impl@PREPERIOD@is@negative@zerofalse
2092 \fi
2093 \pgfmathfloat@tmptoks=\expandafter{\expandafter#1\the\pgfmathfloat@tmptoks}%
2094 \def\pgfmathround@nextcmd{\pgfmathroundto@impl@ITERATE@NODOT}%
2095 \fi
2096 \fi
2097 \pgfmathround@nextcmd
2098 }
2099
2100 %--------------------------------------------
2101 % END of pgfmathroundto implementation.
2102 %--------------------------------------------
2103
2104
2105 % flags, mantissa and exponent has already been stored into
2106 % \pgfmathfloat@a@* [using ...@Mtok]
2107 %
2108 % PRECONDITION:
2109 % \ifpgfmathfloatroundhasperiod = \iftrue outside of the current
2110 % group
2111 %
2112 % POSTCONDITION:
2113 % \ifpgfmathfloatroundhasperiod will be set after the current TeX
2114 % group.
2115 \def\pgfmathfloatround@impl{%
2116 \expandafter\pgfmathroundto@impl\expandafter{\the\pgfmathfloat@a@Mtok}%
2117 \ifpgfmathfloatroundmayneedrenormalize
2118 \ifpgfmathfloatroundhasperiod
2119 \expandafter\pgfmathfloatround@impl@renormalize\pgfmathresult\pgfmathfloat@EOI%
2120 \else
2121 \expandafter\pgfmathfloatround@impl@renormalize\pgfmathresult.\pgfmathfloat@EOI%
2122 \fi
2123 \advance\pgfmathfloat@a@E by1
2124 \fi
2125 \pgfmathfloatcreate{\the\pgfmathfloat@a@S}{\pgfmathresult}{\the\pgfmathfloat@a@E}%
2126 }
2127
2128 \def\pgfmathfloatround@impl@renormalize#1#2.#3\pgfmathfloat@EOI{%
2129 \pgfmathroundto@impl{#1.#2#3}%
2130 }
2131
2132
2133
2134
2135
2136 % ATTENTION: this thing REQUIRES a period in the mantissa!
2137 % collects everything into \pgfmathresult
2138 \def\pgfmathfloattofixed@impl#1.#2\relax{%
2139 \ifnum\pgfmathfloat@a@E<0
2140 \ifcase-\pgfmathfloat@a@E
2141 \or%e-1
2142 \pgfmathfloat@a@Mtok={0.}%
2143 \or%e-2
2144 \pgfmathfloat@a@Mtok={0.0}%
2145 \or%e-3
2146 \pgfmathfloat@a@Mtok={0.00}%
2147 \or%e-4
2148 \pgfmathfloat@a@Mtok={0.000}%
2149 \or%e-5
2150 \pgfmathfloat@a@Mtok={0.0000}%
2151 \or%e-6
2152 \pgfmathfloat@a@Mtok={0.00000}%
2153 \or%e-7
2154 \pgfmathfloat@a@Mtok={0.000000}%
2155 \or%e-8
2156 \pgfmathfloat@a@Mtok={0.0000000}%
2157 \or%e-9
2158 \pgfmathfloat@a@Mtok={0.00000000}%
2159 \or%e-10
2160 \pgfmathfloat@a@Mtok={0.000000000}%
2161 \else%<= -11
2162 \pgfmathfloat@a@Mtok={0.0000000000}%
2163 \advance\pgfmathfloat@a@E by10
2164 \pgfutil@loop
2165 \ifnum\pgfmathfloat@a@E<-1
2166 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok 0}%
2167 \advance\pgfmathfloat@a@E by1
2168 \pgfutil@repeat
2169 \fi
2170 \def\pgfmathfloat@loc@TMPb{#2}%
2171 \def\pgfmathfloat@loc@TMPc{0}%
2172 \ifx\pgfmathfloat@loc@TMPb\pgfmathfloat@loc@TMPc
2173 \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok #1}%
2174 \else
2175 \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok #1#2}%
2176 \fi
2177 \else
2178 %--------------------------------------------------
2179 % \ifnum\pgfmathfloat@a@E=0%
2180 % \edef\pgfmathresult{#1.#2}%
2181 % \else
2182 % \pgfmathfloat@a@Mtok={#1}%
2183 % \pgfmathfloattofixed@impl@collectmantissa#2\count\pgfmathfloat@a@E
2184 % \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok}%
2185 % \fi
2186 %--------------------------------------------------
2187 \pgfmathfloat@a@Mtok{#1}%
2188 \pgfmathfloattofixed@impl@pos#2000000000\pgfmathfloat@EOI
2189 \edef\pgfmathresult{\the\pgfmathfloat@a@Mtok}%
2190 \fi
2191 }
2192
2193 % FIXME: this implementation here is very fast, but it introduces trailing zeros. Is that acceptable?
2194 \def\pgfmathfloattofixed@impl@pos#1#2#3#4#5#6#7#8#9\pgfmathfloat@EOI{%
2195 \ifcase\pgfmathfloat@a@E
2196 % e+0
2197 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok .#1#2#3#4#5#6#7#8#9}%
2198 \or%e+1
2199 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1.#2#3#4#5#6#7#8#9}%
2200 \or%e+2
2201 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2.#3#4#5#6#7#8#9}%
2202 \or%e+3
2203 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3.#4#5#6#7#8#9}%
2204 \or%e+4
2205 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4.#5#6#7#8#9}%
2206 \or%e+5
2207 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5.#6#7#8#9}%
2208 \or%e+6
2209 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6.#7#8#9}%
2210 \or%e+7
2211 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6#7.#8#9}%
2212 \or%e+8
2213 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6#7#8.#9}%
2214 \else%>=9
2215 \pgfmathfloat@a@Mtok\expandafter{\the\pgfmathfloat@a@Mtok #1#2#3#4#5#6#7#8}%
2216 \advance\pgfmathfloat@a@E by-8
2217 \pgfmathfloattofixed@impl@collectmantissa#9\count\pgfmathfloat@a@E
2218 \fi
2219 }%
2220
2221 \def\pgfmathfloattofixed@impl@collectmantissa#1#2\count#3{%
2222 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok #1}%
2223 \advance\pgfmathfloat@a@E by-1%
2224 \def\pgfmathfloat@loc@TMPb{#2}%
2225 \ifx\pgfmathfloat@loc@TMPb\pgfutil@empty
2226 \pgfutil@loop
2227 \ifnum\pgfmathfloat@a@E>0%
2228 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok 0}%
2229 \advance\pgfmathfloat@a@E by-1%
2230 \pgfutil@repeat
2231 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok .0}%
2232 \else
2233 \ifnum\pgfmathfloat@a@E=0
2234 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok .#2}%
2235 \else
2236 \pgfmathfloattofixed@impl@collectmantissa#2\count#3%
2237 \fi
2238 \fi
2239 }
2240
2241
2242 % ============================================
2243 %
2244 %
2245 % \pgfmathfloatparsenumber implementation
2246 %
2247 %
2248 % ============================================
2249
2250 % accepted parser tokens:
2251 \def\pgfmathfloatparsenumber@tok@ZERO{0}
2252 \def\pgfmathfloatparsenumber@tok@PLUS{+}
2253 \def\pgfmathfloatparsenumber@tok@MINUS{-}
2254 \def\pgfmathfloatparsenumber@tok@PERIOD{.}
2255
2256 \newif\ifpgfmathfloatparsenumberpendingperiod
2257
2258 \def\pgfflt@EOI{p@EOI}%
2259 \def\pgfflt@EOI@unexpanded{\pgfflt@EOI}%
2260
2261 % Starts a finite-start-machine parser to read a number.
2262 %
2263 % The machine's state is represented by the macro which is currently
2264 % processed; state transitions are realised using \csname...#1\endcsname
2265 % constructions.
2266 %
2267 % It assigns \pgfmathfloat@a@S, \pgfmathfloat@a@Mtok, \pgfmathfloat@a@E.
2268 \def\pgfflt@impl#1{%
2269 \pgfmathfloatparsenumberpendingperiodfalse
2270 \pgfmathfloat@tmptoks={}% this register is used to collect PENDING ZEROS
2271 \pgfmathfloat@a@E=0
2272 % start parsing: check for sign:
2273 \expandafter\ifx\csname pgfflt@#1\endcsname\relax
2274 \pgfmathfloat@a@S=1
2275 \expandafter\pgfflt@init\expandafter#1%
2276 \else
2277 \expandafter\expandafter\csname pgfflt@#1\endcsname
2278 \fi
2279 }
2280 % State transitions:
2281 \expandafter\def\csname pgfflt@+\endcsname{%
2282 \pgfmathfloat@a@S=1 %
2283 \pgfflt@init}%
2284 \expandafter\def\csname pgfflt@-\endcsname{%
2285 \pgfmathfloat@a@S=2 %
2286 \pgfflt@init}%
2287 \expandafter\def\csname pgfflt@\pgfflt@EOI\endcsname{%
2288 \pgfmathfloatparsenumber@handleerror{empty number}{}{}}%
2289
2290 \pgfkeys{
2291 /pgf/fpu/handlers/empty number/.style 2 args={%
2292 /pgf/fpu/handlers/invalid number={#1}{#2}%
2293 },
2294 /pgf/fpu/empty number is zero/.style={%
2295 /pgf/fpu/handlers/empty number/.code 2 args={%
2296 \pgfmathfloatcreate{0}{0.0}{0}%
2297 }%
2298 },%
2299 /pgf/fpu/handlers/invalid separator/.code 2 args={%
2300 \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'?}{}%
2301 },
2302 /pgf/fpu/handlers/invalid number/.code 2 args={%
2303 \pgfmath@error{Could not parse input '#1' as a floating point number, sorry. The unreadable part was near '#2'.}{}%
2304 },
2305 /pgf/fpu/handlers/wrong lowlevel format/.code 2 args={%
2306 \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'.}{}%
2307 \let\pgfmathresult=\pgfutil@empty
2308 },
2309 }
2310
2311 % #1 the error handler
2312 % #2 the number which was invalid.
2313 % #3 the part which produced the error
2314 %
2315 % POSTCONDITION: the three registers
2316 % \pgfmathfloat@a@S
2317 % \pgfmathfloat@a@Mtok
2318 % \pgfmathfloat@a@E
2319 % will contain the number which results from the error handler.
2320 \def\pgfmathfloatparsenumber@handleerror#1#2#3{%
2321 \let\pgfmathresult=\pgfutil@empty
2322 \pgfmathfloatparsenumberpendingperiodfalse
2323 \pgfkeys{/pgf/fpu/handlers/#1={#2}{#3}}%
2324 \ifx\pgfmathresult\pgfutil@empty
2325 \pgfmathfloat@a@S=3
2326 \pgfmathfloat@a@Mtok={0.0}%
2327 \pgfmathfloat@a@E=0
2328 \else
2329 \expandafter\pgfmathfloat@decompose@tok\pgfmathresult\relax\pgfmathfloat@a@S\pgfmathfloat@a@Mtok\pgfmathfloat@a@E
2330 \fi
2331 }
2332 \def\pgfflt@error#1\pgfflt@EOI{%
2333 \begingroup
2334 \pgfmathfloat@a@Mtok={#1}%
2335 \xdef\pgfmathfloat@glob@TMP{%
2336 \noexpand\pgfmathfloatparsenumber@handleerror
2337 {invalid number}{\pgfmathresult}{\the\pgfmathfloat@a@Mtok}}%
2338 \endgroup
2339 \pgfmathfloat@glob@TMP
2340 }%
2341
2342
2343
2344 % FROM: checksign.
2345 %
2346 \def\pgfflt@init#1{%
2347 \expandafter\ifx\csname pgffltA@#1\endcsname\relax
2348 \expandafter\pgfflt@error\expandafter#1%
2349 \else
2350 \expandafter\expandafter\csname pgffltA@#1\endcsname
2351 \fi}
2352 % state transitions:
2353 \expandafter\def\csname pgffltA@0\endcsname{\pgfflt@leadingzero}% FIXME: inline optimization!
2354 \expandafter\def\csname pgffltA@1\endcsname{\pgfflt@nonzerodigit1}%
2355 \expandafter\def\csname pgffltA@2\endcsname{\pgfflt@nonzerodigit2}%
2356 \expandafter\def\csname pgffltA@3\endcsname{\pgfflt@nonzerodigit3}%
2357 \expandafter\def\csname pgffltA@4\endcsname{\pgfflt@nonzerodigit4}%
2358 \expandafter\def\csname pgffltA@5\endcsname{\pgfflt@nonzerodigit5}%
2359 \expandafter\def\csname pgffltA@6\endcsname{\pgfflt@nonzerodigit6}%
2360 \expandafter\def\csname pgffltA@7\endcsname{\pgfflt@nonzerodigit7}%
2361 \expandafter\def\csname pgffltA@8\endcsname{\pgfflt@nonzerodigit8}%
2362 \expandafter\def\csname pgffltA@9\endcsname{\pgfflt@nonzerodigit9}%
2363 \def\pgfflt@nonzerodigit#1{%
2364 \pgfmathfloat@a@Mtok={#1}%
2365 \pgfmathfloatparsenumberpendingperiodtrue
2366 \pgfflt@positiveexp}%
2367 \expandafter\def\csname pgffltA@n\endcsname{\pgfflt@readnan}% FIXME: inlining?
2368 \expandafter\def\csname pgffltA@N\endcsname{\pgfflt@readnan}% FIXME: inlining?
2369 \expandafter\def\csname pgffltA@i\endcsname{\pgfflt@readinf}% FIXME: inlining?
2370 \expandafter\def\csname pgffltA@I\endcsname{\pgfflt@readinf}% FIXME: inlining?
2371 \expandafter\def\csname pgffltA@.\endcsname{% read '.9' like '0.9'
2372 \pgfmathfloat@a@E=-1
2373 \pgfflt@leadingzero@foundperiod}%
2374 \expandafter\def\csname pgffltA@,\endcsname{% read ',9' like '0,9'
2375 \pgfmathfloat@frenchinput{%
2376 \pgfmathfloat@a@E=-1
2377 \pgfflt@leadingzero@foundperiod
2378 }%
2379 }%
2380
2381 \def\pgfmathfloat@frenchinput#1{%
2382 \ifpgfmathparsenumber@comma@as@period
2383 \def\pgf@marshal{#1}%
2384 \expandafter\pgf@marshal
2385 \else
2386 \expandafter\pgfflt@error@separator\expandafter,%
2387 \fi
2388 }%
2389 \def\pgfflt@error@separator#1\pgfflt@EOI{%
2390 \begingroup
2391 \pgfmathfloat@a@Mtok={#1}%
2392 \xdef\pgfmathfloat@glob@TMP{%
2393 \noexpand\pgfmathfloatparsenumber@handleerror
2394 {invalid separator}{\pgfmathresult}{\the\pgfmathfloat@a@Mtok}}%
2395 \endgroup
2396 \pgfmathfloat@glob@TMP
2397 }%
2398
2399 \def\pgfflt@finish#1\pgfflt@EOI{}
2400
2401 \def\pgfflt@readnan #1#2{%
2402 \def\pgfflt@readnan@ok{1}%
2403 \if#1a\else\if#1A\else\def\pgfflt@readnan@ok{0}\fi\fi
2404 \if#2n\else\if#2N\else\def\pgfflt@readnan@ok{0}\fi\fi
2405 \if\pgfflt@readnan@ok1%
2406 \pgfmathfloat@a@S=3\relax%
2407 \pgfmathfloat@a@Mtok={0.0}%
2408 \pgfmathfloat@a@E=0%
2409 \expandafter\pgfflt@finish
2410 \else
2411 \def\pgfflt@readnan@{\pgfflt@error #1#2}%
2412 \expandafter\pgfflt@readnan@
2413 \fi
2414 }
2415 \def\pgfflt@readinf #1#2{%
2416 \def\pgfflt@readinf@ok{1}%
2417 \if#1n\else\if#1N\else\def\pgfflt@readinf@ok{0}\fi\fi
2418 \if#2f\else\if#2F\else\def\pgfflt@readinf@ok{0}\fi\fi
2419 \if\pgfflt@readinf@ok1%
2420 \ifnum\pgfmathfloat@a@S=1 %
2421 \pgfmathfloat@a@S=4 %
2422 \pgfmathfloat@a@Mtok={0.0}%
2423 \else
2424 \pgfmathfloat@a@S=5 %
2425 \pgfmathfloat@a@Mtok={0.0}%
2426 \fi
2427 \pgfmathfloat@a@E=0 %
2428 \expandafter\pgfflt@finish
2429 \else
2430 \def\pgfflt@readinf@{\pgfflt@error #1#2}%
2431 \expandafter\pgfflt@readinf@
2432 \fi
2433 }
2434 \def\pgfflt@leadingzero#1{%
2435 \expandafter\ifx\csname pgffltB@#1\endcsname\relax
2436 \expandafter\pgfflt@error\expandafter#1%
2437 \else
2438 \expandafter\expandafter\csname pgffltB@#1\endcsname
2439 \fi}
2440 % State transitions:
2441 \expandafter\def\csname pgffltB@0\endcsname{\pgfflt@leadingzero}%
2442 \expandafter\def\csname pgffltB@1\endcsname{\pgfmathfloat@a@Mtok={1}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
2443 \expandafter\def\csname pgffltB@2\endcsname{\pgfmathfloat@a@Mtok={2}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
2444 \expandafter\def\csname pgffltB@3\endcsname{\pgfmathfloat@a@Mtok={3}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
2445 \expandafter\def\csname pgffltB@4\endcsname{\pgfmathfloat@a@Mtok={4}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
2446 \expandafter\def\csname pgffltB@5\endcsname{\pgfmathfloat@a@Mtok={5}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
2447 \expandafter\def\csname pgffltB@6\endcsname{\pgfmathfloat@a@Mtok={6}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
2448 \expandafter\def\csname pgffltB@7\endcsname{\pgfmathfloat@a@Mtok={7}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
2449 \expandafter\def\csname pgffltB@8\endcsname{\pgfmathfloat@a@Mtok={8}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
2450 \expandafter\def\csname pgffltB@9\endcsname{\pgfmathfloat@a@Mtok={9}\pgfmathfloatparsenumberpendingperiodtrue \pgfflt@positiveexp}
2451 \expandafter\def\csname pgffltB@\pgfmathfloat@POSTFLAGSCHAR\endcsname{\pgfmathfloat@a@Mtok={0}\pgfflt@readlowlevelfloat}%
2452 \expandafter\def\csname pgffltB@.\endcsname{%
2453 \pgfmathfloat@a@E=-1
2454 \pgfflt@leadingzero@foundperiod}%
2455 \expandafter\def\csname pgffltB@,\endcsname{%
2456 \pgfmathfloat@frenchinput{%
2457 \pgfmathfloat@a@E=-1
2458 \pgfflt@leadingzero@foundperiod
2459 }%
2460 }%
2461 \expandafter\def\csname pgffltB@e\endcsname{%
2462 \pgfmathfloat@a@S=0\relax%
2463 \pgfmathfloat@a@Mtok={0.0}%
2464 \pgfmathfloat@a@E=0%
2465 \pgfflt@readexponent}%
2466 \let\pgffltB@E=\pgffltB@e
2467 \expandafter\def\csname pgffltB@\pgfflt@EOI\endcsname{%
2468 \pgfmathfloat@a@S=0\relax%
2469 \pgfmathfloat@a@Mtok={0.0}%
2470 \pgfmathfloat@a@E=0}%
2471
2472 \def\pgfflt@leadingzero@foundperiod#1{%
2473 \expandafter\ifx\csname pgffltC@#1\endcsname\relax
2474 \expandafter\pgfflt@error\expandafter#1%
2475 \else
2476 \expandafter\expandafter\csname pgffltC@#1\endcsname
2477 \fi}
2478 % State transitions:
2479 \expandafter\def\csname pgffltC@0\endcsname{%
2480 \advance\pgfmathfloat@a@E by-1
2481 \pgfflt@leadingzero@foundperiod}%
2482 \expandafter\def\csname pgffltC@1\endcsname{\pgfmathfloat@a@Mtok={1}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
2483 \expandafter\def\csname pgffltC@2\endcsname{\pgfmathfloat@a@Mtok={2}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
2484 \expandafter\def\csname pgffltC@3\endcsname{\pgfmathfloat@a@Mtok={3}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
2485 \expandafter\def\csname pgffltC@4\endcsname{\pgfmathfloat@a@Mtok={4}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
2486 \expandafter\def\csname pgffltC@5\endcsname{\pgfmathfloat@a@Mtok={5}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
2487 \expandafter\def\csname pgffltC@6\endcsname{\pgfmathfloat@a@Mtok={6}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
2488 \expandafter\def\csname pgffltC@7\endcsname{\pgfmathfloat@a@Mtok={7}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
2489 \expandafter\def\csname pgffltC@8\endcsname{\pgfmathfloat@a@Mtok={8}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
2490 \expandafter\def\csname pgffltC@9\endcsname{\pgfmathfloat@a@Mtok={9}\pgfmathfloatparsenumberpendingperiodtrue\pgfflt@finish@number@after@period}%
2491 \expandafter\def\csname pgffltC@e\endcsname{%
2492 \pgfmathfloat@a@S=0\relax%
2493 \pgfmathfloat@a@Mtok={0.0}%
2494 \pgfmathfloat@a@E=0%
2495 \pgfflt@readexponent}%
2496 \let\pgffltC@E=\pgffltC@e
2497 \expandafter\def\csname pgffltC@\pgfflt@EOI\endcsname{%
2498 \pgfmathfloat@a@S=0\relax%
2499 \pgfmathfloat@a@Mtok={0.0}%
2500 \pgfmathfloat@a@E=0}%
2501
2502
2503 \def\pgfflt@positiveexp#1{%
2504 \expandafter\ifx\csname pgffltD@#1\endcsname\relax
2505 \expandafter\pgfflt@error\expandafter#1%
2506 \else
2507 \expandafter\expandafter\csname pgffltD@#1\endcsname
2508 \fi}
2509 % State transitions:
2510 \expandafter\def\csname pgffltD@0\endcsname{%
2511 \advance\pgfmathfloat@a@E by1
2512 \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
2513 \pgfflt@pendingzeros@positiveexp}%
2514 \expandafter\def\csname pgffltD@1\endcsname{\pgffltD@nonzerodigit1}%
2515 \expandafter\def\csname pgffltD@2\endcsname{\pgffltD@nonzerodigit2}%
2516 \expandafter\def\csname pgffltD@3\endcsname{\pgffltD@nonzerodigit3}%
2517 \expandafter\def\csname pgffltD@4\endcsname{\pgffltD@nonzerodigit4}%
2518 \expandafter\def\csname pgffltD@5\endcsname{\pgffltD@nonzerodigit5}%
2519 \expandafter\def\csname pgffltD@6\endcsname{\pgffltD@nonzerodigit6}%
2520 \expandafter\def\csname pgffltD@7\endcsname{\pgffltD@nonzerodigit7}%
2521 \expandafter\def\csname pgffltD@8\endcsname{\pgffltD@nonzerodigit8}%
2522 \expandafter\def\csname pgffltD@9\endcsname{\pgffltD@nonzerodigit9}%
2523 \expandafter\def\csname pgffltD@\pgfmathfloat@POSTFLAGSCHAR\endcsname{\pgfflt@readlowlevelfloat}%
2524 \expandafter\def\csname pgffltD@.\endcsname{\pgfflt@finish@number@after@period}% FIXME : inlining?
2525 \expandafter\def\csname pgffltD@,\endcsname{\pgfmathfloat@frenchinput{\pgfflt@finish@number@after@period}}%
2526 \expandafter\def\csname pgffltD@e\endcsname{\pgfflt@readexponent}% FIXME : inlining?
2527 \let\pgffltD@E=\pgffltD@e
2528 \expandafter\def\csname pgffltD@\pgfflt@EOI\endcsname{}% NOP
2529 \def\pgffltD@nonzerodigit#1{%
2530 \advance\pgfmathfloat@a@E by1
2531 \ifpgfmathfloatparsenumberpendingperiod
2532 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}%
2533 \pgfmathfloatparsenumberpendingperiodfalse
2534 \fi
2535 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}%
2536 \pgfflt@positiveexp}%
2537
2538 % Read a low-level floating point.
2539 % Since we are in the second state, \pgfmathfloat@a@Mtok contains the
2540 % FLAGS. The post-flags-char has also been read.
2541 \def\pgfflt@readlowlevelfloat#1e#2]\pgfflt@EOI{%
2542 \pgfmathfloatparsenumberpendingperiodfalse
2543 \pgfmathfloat@a@S=\the\pgfmathfloat@a@Mtok\relax
2544 \pgfmathfloat@a@Mtok={#1}%
2545 \pgfmathfloat@a@E=#2
2546 }%
2547
2548 \def\pgfflt@readexponent#1\pgfflt@EOI{%
2549 \afterassignment\pgfflt@readexponent@
2550 \pgfmathfloat@b@E=#1 \pgfflt@EOI% the white space is important, otherwise \pgfflt@EOI will be expanded.
2551 }
2552 \def\pgfflt@readexponent@#1{%
2553 \advance\pgfmathfloat@a@E by\pgfmathfloat@b@E\relax
2554 %
2555 % sanity checking:
2556 \def\pgfmathfloat@loc@TMPb{#1}%
2557 \ifx\pgfmathfloat@loc@TMPb\pgfflt@EOI@unexpanded
2558 \else
2559 \def\pgfmathfloat@loc@TMPb{\pgfflt@error#1}%
2560 \expandafter\pgfmathfloat@loc@TMPb
2561 \fi
2562 }
2563
2564 \def\pgfflt@pendingzeros@positiveexp#1{%
2565 \expandafter\ifx\csname pgffltE@#1\endcsname\relax
2566 \expandafter\pgfflt@error\expandafter#1%
2567 \else
2568 \expandafter\expandafter\csname pgffltE@#1\endcsname
2569 \fi}
2570 % State transitions:
2571 \expandafter\def\csname pgffltE@0\endcsname{%
2572 \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
2573 \advance\pgfmathfloat@a@E by1
2574 \pgfflt@pendingzeros@positiveexp}%
2575 \expandafter\def\csname pgffltE@1\endcsname{\pgffltE@nonzerodigit1}%
2576 \expandafter\def\csname pgffltE@2\endcsname{\pgffltE@nonzerodigit2}%
2577 \expandafter\def\csname pgffltE@3\endcsname{\pgffltE@nonzerodigit3}%
2578 \expandafter\def\csname pgffltE@4\endcsname{\pgffltE@nonzerodigit4}%
2579 \expandafter\def\csname pgffltE@5\endcsname{\pgffltE@nonzerodigit5}%
2580 \expandafter\def\csname pgffltE@6\endcsname{\pgffltE@nonzerodigit6}%
2581 \expandafter\def\csname pgffltE@7\endcsname{\pgffltE@nonzerodigit7}%
2582 \expandafter\def\csname pgffltE@8\endcsname{\pgffltE@nonzerodigit8}%
2583 \expandafter\def\csname pgffltE@9\endcsname{\pgffltE@nonzerodigit9}%
2584 \expandafter\def\csname pgffltE@.\endcsname{\pgfflt@finish@number@after@period}% FIXME : inlining?
2585 \expandafter\def\csname pgffltE@,\endcsname{\pgfmathfloat@frenchinput{\pgfflt@finish@number@after@period}}% FIXME : inlining?
2586 \def\pgffltE@e{\pgfflt@readexponent}% FIXME : inlining?
2587 \let\pgffltE@E=\pgffltE@e
2588 \expandafter\def\csname pgffltE@\pgfflt@EOI\endcsname{}% NOP
2589 \def\pgffltE@nonzerodigit#1{%
2590 \advance\pgfmathfloat@a@E by1
2591 \ifpgfmathfloatparsenumberpendingperiod
2592 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}%
2593 \pgfmathfloatparsenumberpendingperiodfalse
2594 \fi
2595 \pgfmathfloat@a@Mtok=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfmathfloat@a@Mtok\the\pgfmathfloat@tmptoks}%
2596 \pgfmathfloat@tmptoks={}%
2597 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}%
2598 \pgfflt@positiveexp}%
2599
2600 \def\pgfflt@finish@number@after@period#1{%
2601 \expandafter\ifx\csname pgffltF@#1\endcsname\relax
2602 \expandafter\pgfflt@error\expandafter#1%
2603 \else
2604 \expandafter\expandafter\csname pgffltF@#1\endcsname
2605 \fi}
2606 % State transitions:
2607 \expandafter\def\csname pgffltF@0\endcsname{%
2608 \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
2609 \pgfflt@pendingzeros}%
2610 \expandafter\def\csname pgffltF@1\endcsname{\pgffltF@nonzerodigit1}%
2611 \expandafter\def\csname pgffltF@2\endcsname{\pgffltF@nonzerodigit2}%
2612 \expandafter\def\csname pgffltF@3\endcsname{\pgffltF@nonzerodigit3}%
2613 \expandafter\def\csname pgffltF@4\endcsname{\pgffltF@nonzerodigit4}%
2614 \expandafter\def\csname pgffltF@5\endcsname{\pgffltF@nonzerodigit5}%
2615 \expandafter\def\csname pgffltF@6\endcsname{\pgffltF@nonzerodigit6}%
2616 \expandafter\def\csname pgffltF@7\endcsname{\pgffltF@nonzerodigit7}%
2617 \expandafter\def\csname pgffltF@8\endcsname{\pgffltF@nonzerodigit8}%
2618 \expandafter\def\csname pgffltF@9\endcsname{\pgffltF@nonzerodigit9}%
2619 \def\pgffltF@e{\pgfflt@readexponent}%
2620 \let\pgffltF@E=\pgffltF@e
2621 \expandafter\def\csname pgffltF@\pgfflt@EOI\endcsname{}% NOP
2622 \def\pgffltF@nonzerodigit#1{%
2623 \ifpgfmathfloatparsenumberpendingperiod
2624 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}%
2625 \pgfmathfloatparsenumberpendingperiodfalse
2626 \fi
2627 \pgfmathfloat@a@Mtok=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfmathfloat@a@Mtok\the\pgfmathfloat@tmptoks}%
2628 \pgfmathfloat@tmptoks={}%
2629 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}%
2630 \pgfflt@finish@number@after@period}%
2631
2632
2633 \def\pgfflt@pendingzeros#1{%
2634 \expandafter\ifx\csname pgffltG@#1\endcsname\relax
2635 \expandafter\pgfflt@error\expandafter#1%
2636 \else
2637 \expandafter\expandafter\csname pgffltG@#1\endcsname
2638 \fi}
2639 % State transitions:
2640 \expandafter\def\csname pgffltG@0\endcsname{%
2641 \pgfmathfloat@tmptoks=\expandafter{\the\pgfmathfloat@tmptoks0}%
2642 \pgfflt@pendingzeros}%
2643 \expandafter\def\csname pgffltG@1\endcsname{\pgffltG@nonzerodigit1}%
2644 \expandafter\def\csname pgffltG@2\endcsname{\pgffltG@nonzerodigit2}%
2645 \expandafter\def\csname pgffltG@3\endcsname{\pgffltG@nonzerodigit3}%
2646 \expandafter\def\csname pgffltG@4\endcsname{\pgffltG@nonzerodigit4}%
2647 \expandafter\def\csname pgffltG@5\endcsname{\pgffltG@nonzerodigit5}%
2648 \expandafter\def\csname pgffltG@6\endcsname{\pgffltG@nonzerodigit6}%
2649 \expandafter\def\csname pgffltG@7\endcsname{\pgffltG@nonzerodigit7}%
2650 \expandafter\def\csname pgffltG@8\endcsname{\pgffltG@nonzerodigit8}%
2651 \expandafter\def\csname pgffltG@9\endcsname{\pgffltG@nonzerodigit9}%
2652 \def\pgffltG@e{\pgfflt@readexponent}% FIXME: inlining?
2653 \let\pgffltG@E=\pgffltG@e
2654 \expandafter\def\csname pgffltG@\pgfflt@EOI\endcsname{}% NOP
2655 \def\pgffltG@nonzerodigit#1{%
2656 \ifpgfmathfloatparsenumberpendingperiod
2657 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok.}%
2658 \pgfmathfloatparsenumberpendingperiodfalse
2659 \fi
2660 \pgfmathfloat@a@Mtok=\expandafter\expandafter\expandafter{\expandafter\the\expandafter\pgfmathfloat@a@Mtok\the\pgfmathfloat@tmptoks}%
2661 \pgfmathfloat@tmptoks={}%
2662 \pgfmathfloat@a@Mtok=\expandafter{\the\pgfmathfloat@a@Mtok#1}%
2663 \pgfflt@finish@number@after@period}%
2664
2665 \endinput