Debian Codegraph @

texmf-dist/tex/generic/pgf/math/pgfmathfloat.code.tex

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