Debian Codegraph @

texmf-dist/tex/generic/pgf/math/pgfmathfunctions.basic.code.tex

raw
1 % Copyright 2019 by Mark Wibrow
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 defines the mathematical functions and operators.
11 %
12 % Version 1.4142135 25/8/2008
13
14 % add function.
15 %
16 \pgfmathdeclarefunction{add}{2}{%
17 \begingroup%
18 \pgfmath@x=#1pt\relax%
19 \pgfmath@y=#2pt\relax%
20 \advance\pgfmath@x by\pgfmath@y%
21 \pgfmath@returnone\pgfmath@x%
22 \endgroup%
23 }
24
25
26 % subtract function.
27 %
28 \pgfmathdeclarefunction{subtract}{2}{%
29 \begingroup%
30 \pgfmath@x=#1pt\relax%
31 \pgfmath@y=#2pt\relax%
32 \advance\pgfmath@x by-\pgfmath@y%
33 \pgfmath@returnone\pgfmath@x%
34 \endgroup%
35 }
36
37 % neg function.
38 %
39 \pgfmathdeclarefunction{neg}{1}{%
40 \begingroup%
41 \pgfmath@x=-#1pt\relax%
42 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}%
43 \pgfmath@smuggleone\pgfmathresult%
44 \endgroup%
45 }
46 % change the precedence for neg.
47 % Otherwise, unary minus and exponentiation won't have the correct precedence
48 % (test '-2^2')
49 \def\pgfmath@operation@neg@precedence{500}
50
51 % multiply function.
52 %
53 \pgfmathdeclarefunction{multiply}{2}{%
54 \begingroup%
55 \pgfmath@x=#1pt\relax%
56 \pgfmath@y=#2pt\relax%
57 \pgfmath@x=\pgfmath@tonumber{\pgfmath@y}\pgfmath@x%
58 \pgfmath@returnone\pgfmath@x%
59 \endgroup%
60 }
61
62 % divide function.
63 %
64 \newif\ifpgfmath@divide@period
65
66 \pgfmathdeclarefunction{divide}{2}{%
67 \begingroup%
68 \pgfmath@x=#1pt\relax%
69 \pgfmath@y=#2pt\relax%
70 \let\pgfmath@sign=\pgfmath@empty%
71 \ifdim0pt=\pgfmath@y%
72 \pgfmath@error{You've asked me to divide `#1' by `#2', %
73 but I cannot divide any number by `#2'}{}%
74 \fi%
75 \afterassignment\pgfmath@xa%
76 \c@pgfmath@counta\the\pgfmath@y\relax%
77 \ifdim0pt=\pgfmath@xa%
78 \divide\pgfmath@x by\c@pgfmath@counta%
79 \else%
80 \ifdim0pt>\pgfmath@x%
81 \def\pgfmath@sign{-}%
82 \pgfmath@x=-\pgfmath@x%
83 \fi%
84 \ifdim0pt>\pgfmath@y%
85 \expandafter\def\expandafter\pgfmath@sign\expandafter{\pgfmath@sign-}%
86 \pgfmath@y=-\pgfmath@y%
87 \fi%
88 \ifdim1pt>\pgfmath@y%
89 \pgfmathreciprocal@{\pgfmath@tonumber{\pgfmath@y}}%
90 \pgfmath@x=\pgfmath@sign\pgfmathresult\pgfmath@x%
91 \else%
92 \def\pgfmathresult{0}%
93 \pgfmath@divide@periodtrue%
94 \c@pgfmath@counta=0\relax%
95 \pgfmathdivide@@%
96 \pgfmath@x=\pgfmath@sign\pgfmathresult pt\relax%
97 \fi%
98 \fi%
99 \pgfmath@returnone\pgfmath@x%
100 \endgroup%
101 }
102
103 \def\pgfmath@small@number{0.00002}
104
105 \def\pgfmathdivide@@{%
106 \let\pgfmath@next=\relax%
107 \ifdim\pgfmath@small@number pt<\pgfmath@x%
108 \ifdim\pgfmath@small@number pt<\pgfmath@y%
109 \ifdim\pgfmath@y>\pgfmath@x%
110 \ifpgfmath@divide@period%
111 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult.}%
112 \pgfmath@divide@periodfalse%
113 \fi%
114 \pgfmathdivide@dimenbyten\pgfmath@y%
115 \ifdim\pgfmath@y>\pgfmath@x%
116 \expandafter\def\expandafter\pgfmathresult\expandafter{\pgfmathresult0}%
117 \fi%
118 \else%
119 \c@pgfmath@counta=\pgfmath@x%
120 \c@pgfmath@countb=\pgfmath@y%
121 \divide\c@pgfmath@counta by\c@pgfmath@countb%
122 \pgfmath@ya=\c@pgfmath@counta\pgfmath@y%
123 \advance\pgfmath@x by-\pgfmath@ya%
124 \def\pgfmath@next{%
125 \toks0=\expandafter{\pgfmathresult}%
126 \edef\pgfmathresult{\the\toks0 \the\c@pgfmath@counta}%
127 }%
128 \ifpgfmath@divide@period
129 \else
130 % we are behind the period. It may happen that the
131 % result is more than one digit - in that case,
132 % introduce special handling:
133 \ifnum\c@pgfmath@counta>9 %
134 \expandafter\pgfmathdivide@advance@last@digit\pgfmathresult CCCCC\@@
135 \advance\c@pgfmath@counta by-10 %
136 \ifnum\c@pgfmath@counta=0
137 \let\pgfmath@next=\relax
138 \fi
139 \fi
140 \fi
141 \pgfmath@next
142 \fi%
143 \let\pgfmath@next=\pgfmathdivide@@%
144 \fi%
145 \fi%
146 \pgfmath@next%
147 }
148
149 % advances the last digit found in the number. Any missing digits are
150 % supposed to be filled with 'C'.
151 \def\pgfmathdivide@advance@last@digit#1.#2#3#4#5#6#7\@@{%
152 \pgfmath@ya=\pgfmathresult pt %
153 \if#2C%
154 \pgfmath@xa=1pt %
155 \else
156 \if#3C%
157 \pgfmath@xa=0.1pt %
158 \else
159 \if#4C%
160 \pgfmath@xa=0.01pt %
161 \else
162 \if#5C%
163 \pgfmath@xa=0.001pt %
164 \else
165 \if#6C%
166 \pgfmath@xa=0.0001pt %
167 \else
168 \pgfmath@xa=0.00001pt %
169 \fi
170 \fi
171 \fi
172 \fi
173 \fi
174 \advance\pgfmath@ya by\pgfmath@xa
175 \edef\pgfmathresult{\pgfmath@tonumber@notrailingzero\pgfmath@ya}%
176 }%
177
178 {
179 \catcode`\p=12
180 \catcode`\t=12
181 \gdef\Pgf@geT@NO@TRAILING@ZERO#1.#2pt{%
182 #1.%
183 \ifnum#2=0 \else #2\fi
184 }
185 }
186 \def\pgfmath@tonumber@notrailingzero#1{\expandafter\Pgf@geT@NO@TRAILING@ZERO\the#1}
187
188
189 \def\pgfmathdivide@dimenbyten#1{%
190 \edef\pgfmath@temp{\pgfmath@tonumber{#1}}%
191 \expandafter\pgfmathdivide@@dimenbyten\pgfmath@temp\@@#1\@@}
192 \def\pgfmathdivide@@dimenbyten#1.#2\@@#3\@@{%
193 \pgfmath@tempcnta=#1\relax%
194 \divide\pgfmath@tempcnta by10\relax%
195 \pgfmath@tempcntb=\pgfmath@tempcnta%
196 \multiply\pgfmath@tempcnta by-10\relax%
197 \advance\pgfmath@tempcnta by#1\relax%
198 #3=\the\pgfmath@tempcntb.\the\pgfmath@tempcnta#2pt\relax%
199 }
200
201
202 % reciprocal function.
203 %
204 \pgfmathdeclarefunction{reciprocal}{1}{%
205 \begingroup%
206 \expandafter\pgfmath@x#1pt\relax%
207 \ifdim\pgfmath@x=0pt\relax%
208 \pgfmath@error{You asked me to calculate `1/#1', but I cannot divide any number by zero}{}%
209 \fi%
210 \edef\pgfmath@reciprocaltemp{\pgfmath@tonumber{\pgfmath@x}}%
211 \expandafter\pgfmathreciprocal@@\pgfmath@reciprocaltemp0000000\pgfmath@}
212 \def\pgfmathreciprocal@@#1.#2#3#4#5#6#7\pgfmath@{%
213 \c@pgfmath@counta#2#3#4#5#6\relax%
214 % If the number is an integer, use TeX arithmetic.
215 \ifnum\c@pgfmath@counta=0\relax%
216 \pgfmath@x1pt\relax%
217 \divide\pgfmath@x#1\relax%
218 \else%
219 \ifnum#1>100\relax%
220 \c@pgfmath@counta#1#2#3#4\relax%
221 \c@pgfmath@countb1000000000\relax%
222 \divide\c@pgfmath@countb\c@pgfmath@counta%
223 \c@pgfmath@counta\c@pgfmath@countb%
224 \divide\c@pgfmath@counta10000\relax%
225 \pgfmath@x\c@pgfmath@counta pt\relax%
226 \multiply\c@pgfmath@counta-10000\relax%
227 \advance\c@pgfmath@countb\c@pgfmath@counta%
228 \pgfmath@y\c@pgfmath@countb pt\relax%
229 \divide\pgfmath@y1000000\relax%
230 \advance\pgfmath@x\pgfmath@y%
231 \else%
232 \c@pgfmath@counta#1#2#3#4#5#6\relax%
233 \c@pgfmath@countb1000000000\relax%
234 \divide\c@pgfmath@countb\c@pgfmath@counta%
235 \c@pgfmath@counta\c@pgfmath@countb%
236 \divide\c@pgfmath@counta10000\relax%
237 \pgfmath@x\c@pgfmath@counta pt\relax%
238 \multiply\c@pgfmath@counta-10000\relax%
239 \advance\c@pgfmath@countb\c@pgfmath@counta%
240 \pgfmath@y\c@pgfmath@countb pt\relax%
241 \[email protected]\pgfmath@y% Yes! This way is more accurate. Go figure...
242 \[email protected]\pgfmath@y%
243 \[email protected]\pgfmath@y%
244 \[email protected]\pgfmath@y%
245 \advance\pgfmath@x\pgfmath@y%
246 \fi%
247 \fi%
248 \pgfmath@returnone\pgfmath@x%
249 \endgroup%
250 }
251
252 % div function.
253 %
254 \pgfmathdeclarefunction{div}{2}{%
255 \begingroup%
256 \pgfmathdivide@{#1}{#2}%
257 \ifdim\pgfmathresult pt<0pt\relax%
258 \pgfmathceil@{\pgfmathresult}%
259 \else%
260 \pgfmathfloor@{\pgfmathresult}%
261 \fi%
262 \afterassignment\pgfmath@gobbletilpgfmath@%
263 \c@pgfmath@counta=\pgfmathresult\relax\pgfmath@%
264 \edef\pgfmathresult{\the\c@pgfmath@counta}%
265 \pgfmath@smuggleone\pgfmathresult%
266 \endgroup%
267 }
268
269 % mod function.
270 %
271 \pgfmathdeclarefunction{mod}{2}{%
272 \begingroup%
273 \pgfmath@xa#1pt%
274 \pgfmath@xb#2pt%
275 \pgfmath@x\pgfmath@xa%
276 \c@pgfmath@counta\pgfmath@xa%
277 \c@pgfmath@countb\pgfmath@xb%
278 \divide\c@pgfmath@counta\c@pgfmath@countb%
279 \multiply\pgfmath@xb\c@pgfmath@counta%
280 \advance\pgfmath@x-\pgfmath@xb%
281 \pgfmath@returnone\pgfmath@x%
282 \endgroup%
283 }
284
285 % Mod function (never negative).
286 %
287 \pgfmathdeclarefunction{Mod}{2}{%
288 \begingroup%
289 \pgfmathmod@{#1}{#2}%
290 \pgfmath@x=\pgfmathresult pt\relax%
291 \ifdim\pgfmath@x<0pt\relax%
292 \advance\pgfmath@x by#2pt\relax%
293 \fi%
294 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}%
295 \pgfmath@smuggleone\pgfmathresult%
296 \endgroup%
297 }
298
299 % abs function.
300 %
301 \pgfmathdeclarefunction{abs}{1}{%
302 \begingroup%
303 \expandafter\pgfmath@x#1pt\relax%
304 \ifdim\pgfmath@x<0pt\relax%
305 \pgfmath@x-\pgfmath@x%
306 \fi%
307 \pgfmath@returnone\pgfmath@x%
308 \endgroup%
309 }
310
311 % sign(x)
312 \pgfmathdeclarefunction{sign}{1}{%
313 \begingroup
314 \ifdim#1pt>0sp %
315 \def\pgfmathresult{1}%
316 \else
317 \ifdim#1pt=0sp %
318 \def\pgfmathresult{0}%
319 \else
320 \def\pgfmathresult{-1}%
321 \fi
322 \fi
323 \pgfmath@smuggleone\pgfmathresult
324 \endgroup
325 }
326
327 % e constant.
328 %
329 \pgfmathdeclarefunction{e}{0}{\def\pgfmathresult{2.718281828}}
330
331 % ln function.
332 %
333 % This is based on an algorithm due to Rouben Rostamian and
334 % uses coefficients contributed by Alain Matthes.
335 %
336 \pgfmathdeclarefunction{ln}{1}{%
337 \begingroup%
338 \expandafter\pgfmath@x#1pt\relax%
339 \ifdim\pgfmath@x>0pt\else%
340 \pgfmath@error{I cannot calculate the logarithm of `#1'}{}%
341 \fi%
342 \c@pgfmath@counta=0\relax%
343 \ifdim\pgfmath@x>2pt\relax%
344 \ifdim\pgfmath@x<128pt\relax%
345 \ifdim\pgfmath@x<8pt\relax%
346 \ifdim\pgfmath@x<4pt\relax%
347 \divide\pgfmath@x by2\relax%
348 \c@pgfmath@counta=1\relax%
349 \else%
350 \divide\pgfmath@x by4\relax%
351 \c@pgfmath@counta=2\relax%
352 \fi%
353 \else%
354 \ifdim\pgfmath@x<32pt\relax%
355 \ifdim\pgfmath@x<16pt\relax%
356 \divide\pgfmath@x by8\relax%
357 \c@pgfmath@counta=3\relax%
358 \else%
359 \divide\pgfmath@x by16\relax%
360 \c@pgfmath@counta=4\relax%
361 \fi%
362 \else%
363 \ifdim\pgfmath@x<64pt\relax%
364 \divide\pgfmath@x by32\relax%
365 \c@pgfmath@counta=5\relax%
366 \else%
367 \divide\pgfmath@x by64\relax%
368 \c@pgfmath@counta=6\relax%
369 \fi%
370 \fi%
371 \fi%
372 \else%
373 \ifdim\pgfmath@x<2048pt\relax%
374 \ifdim\pgfmath@x<512pt\relax%
375 \ifdim\pgfmath@x<256pt\relax%
376 \divide\pgfmath@x by128\relax%
377 \c@pgfmath@counta=7\relax%
378 \else%
379 \divide\pgfmath@x by256\relax%
380 \c@pgfmath@counta=8\relax%
381 \fi%
382 \else%
383 \ifdim\pgfmath@x<1024pt\relax%
384 \divide\pgfmath@x by512\relax%
385 \c@pgfmath@counta=9\relax%
386 \else%
387 \divide\pgfmath@x by1024\relax%
388 \c@pgfmath@counta=10\relax%
389 \fi%
390 \fi%
391 \else%
392 \ifdim\pgfmath@x<8192pt\relax%
393 \ifdim\pgfmath@x<4096pt\relax%
394 \divide\pgfmath@x by2048\relax%
395 \c@pgfmath@counta=11\relax%
396 \else%
397 \divide\pgfmath@x by4096\relax%
398 \c@pgfmath@counta =12\relax%
399 \fi%
400 \else%
401 \divide\pgfmath@x by8192\relax%
402 \c@pgfmath@counta=13\relax%
403 \fi%
404 \fi%
405 \fi%
406 \else%
407 \ifdim\pgfmath@x<1pt\relax%
408 \ifdim\pgfmath@x>0.0078125pt\relax% 2^-7
409 \ifdim\pgfmath@x>0.125pt\relax% 2^-3
410 \ifdim\pgfmath@x>0.5pt\relax% 2^-1
411 \multiply\pgfmath@x by2\relax%
412 \c@pgfmath@counta=-1\relax%
413 \else%
414 \multiply\pgfmath@x by4\relax%
415 \c@pgfmath@counta=-2\relax%
416 \fi%
417 \else%
418 \ifdim\pgfmath@x>0.03125pt\relax% 2^-5
419 \ifdim\pgfmath@x>0.0625pt\relax%
420 \multiply\pgfmath@x by8\relax%
421 \c@pgfmath@counta=-3\relax%
422 \else%
423 \multiply\pgfmath@x by16\relax%
424 \c@pgfmath@counta=-4\relax%
425 \fi%
426 \else%
427 \ifdim\pgfmath@x>0.015625pt\relax% 2^-6
428 \multiply\pgfmath@x by32\relax%
429 \c@pgfmath@counta=-5\relax%
430 \else%
431 \multiply\pgfmath@x by64\relax%
432 \c@pgfmath@counta=-6\relax%
433 \fi%
434 \fi%
435 \fi%
436 \else%
437 \ifdim\pgfmath@x>0.00048828125pt\relax% 2^-11
438 \ifdim\pgfmath@x>0.001953125pt\relax% 2^-9
439 \ifdim\pgfmath@x>0.00390625pt\relax% 2^-8
440 \multiply\pgfmath@x by128\relax%
441 \c@pgfmath@counta=-7\relax%
442 \else%
443 \multiply\pgfmath@x by256\relax%
444 \c@pgfmath@counta=-8\relax%
445 \fi%
446 \else%
447 \ifdim\pgfmath@x>0.0009765625pt\relax% 2^-10
448 \multiply\pgfmath@x by512\relax%
449 \c@pgfmath@counta=-9\relax%
450 \else%
451 \multiply\pgfmath@x by1024\relax%
452 \c@pgfmath@counta=-10\relax%
453 \fi%
454 \fi%
455 \else%
456 \ifdim\pgfmath@x>0.0001220703125pt\relax% 2^13
457 \ifdim\pgfmath@x>0.0002441406256pt\relax% 2^12
458 \multiply\pgfmath@x by2048\relax%
459 \c@pgfmath@counta=-11\relax%
460 \else%
461 \multiply\pgfmath@x by4096\relax%
462 \c@pgfmath@counta=-12\relax%
463 \fi%
464 \else%
465 \multiply\pgfmath@x by8192\relax%
466 \c@pgfmath@counta=-13\relax%
467 \fi%
468 \fi%
469 \fi%
470 \fi%
471 \fi%
472 %
473 % Use A+(B+(C+(D+(E+F*x)*x)*x)*x)*x
474 %
475 % where:
476 % A = -2.787927935
477 % B = 5.047861502
478 % C = -3.489886985
479 % D = 1.589480044
480 % E = -.4025153233
481 % F = 0.04300521312
482 %
483 \edef\pgfmath@temp{\pgfmath@tonumber{\pgfmath@x}}%
484 \pgfmath@x=0.04300521312\pgfmath@x%
485 \advance\pgfmath@x by-.4025153233pt\relax%
486 \pgfmath@x=\pgfmath@temp\pgfmath@x%
487 \advance\pgfmath@x by1.589480044pt\relax%
488 \pgfmath@x=\pgfmath@temp\pgfmath@x%
489 \advance\pgfmath@x by-3.489886985pt\relax%
490 \pgfmath@x=\pgfmath@temp\pgfmath@x%
491 \advance\pgfmath@x by5.047861502pt\relax%
492 \pgfmath@x=\pgfmath@temp\pgfmath@x%
493 \advance\pgfmath@x by-2.787927935pt\relax%
494 \advance\pgfmath@x by\c@pgfmath@counta pt\relax%
495 \pgfmath@x=0.6931471806\pgfmath@x%
496 \pgfmath@returnone\pgfmath@x%
497 \endgroup%
498 }
499
500 % log2 function.
501 %
502 \pgfmathdeclarefunction{log2}{1}{%
503 \begingroup%
504 \pgfmathln@{#1}%
505 \pgfmath@x=\pgfmathresult pt\relax%
506 \pgfmath@x=1.442695041\pgfmath@x% 1/ln(2).
507 \pgfmath@returnone\pgfmath@x%
508 \endgroup%
509 }
510
511 % log10 function
512 %
513 \pgfmathdeclarefunction{log10}{1}{%
514 \begingroup%
515 \pgfmathln@{#1}%
516 \pgfmath@x=\pgfmathresult pt\relax%
517 \pgfmath@x=0.43429441\pgfmath@x% 1/ln(10).
518 \pgfmath@returnone\pgfmath@x%
519 \endgroup%
520 }
521
522 % This is needed since \pgfmathlog2 and \pgfmathlog10 are not legal macro names
523 \expandafter\let\expandafter\pgfmathlogtwo\csname pgfmathlog2\endcsname
524 \expandafter\let\expandafter\pgfmathlogtwo@\csname pgfmathlog2@\endcsname
525 \expandafter\let\expandafter\pgfmathlogten\csname pgfmathlog10\endcsname
526 \expandafter\let\expandafter\pgfmathlogten@\csname pgfmathlog10@\endcsname
527
528 % exp function.
529 %
530 \pgfmathdeclarefunction{exp}{1}{%
531 \begingroup
532 \pgfmath@xc=#1pt\relax
533 \pgfmath@yc=#1pt\relax
534 \ifdim\pgfmath@xc<-9pt
535 \pgfmath@x=1sp\relax
536 \else
537 \ifdim\pgfmath@xc<0pt
538 \pgfmath@xc=-\pgfmath@xc
539 \fi
540 \pgfmath@x=1pt\relax
541 \pgfmath@xa=1pt\relax
542 \pgfmath@xb=\pgfmath@x
543 \pgfmathloop%
544 \divide\pgfmath@xa by\pgfmathcounter
545 \pgfmath@xa=\pgfmath@tonumber\pgfmath@xc\pgfmath@xa%
546 \advance\pgfmath@x by\pgfmath@xa
547 \ifdim\pgfmath@x=\pgfmath@xb
548 \else
549 \pgfmath@xb=\pgfmath@x
550 \repeatpgfmathloop%
551 \ifdim\pgfmath@yc<0pt
552 \pgfmathreciprocal@{\pgfmath@tonumber\pgfmath@x}%
553 \pgfmath@x=\pgfmathresult pt\relax
554 \fi
555 \fi
556 \pgfmath@returnone\pgfmath@x%
557 \endgroup
558 }
559
560 % sqrt function.
561 %
562 \pgfmathdeclarefunction{sqrt}{1}{%
563 \begingroup%
564 \expandafter\pgfmath@x#1pt\relax%
565 \ifdim\pgfmath@x<0pt\relax%
566 \pgfmath@error{I cannot calculate the square-root of the negative number `#1'}{}%
567 \else%
568 \ifdim\pgfmath@x<10pt\relax%
569 \def\pgfmath@zeros{0}%
570 \def\pgfmath@targetiterations{1}%
571 \else%
572 \ifdim\pgfmath@x<100pt\relax%
573 \def\pgfmath@zeros{}%
574 \def\pgfmath@targetiterations{1}%
575 \else%
576 \ifdim\pgfmath@x<1000pt\relax%
577 \def\pgfmath@zeros{0}%
578 \def\pgfmath@targetiterations{2}%
579 \else%
580 \ifdim\pgfmath@x<10000pt\relax%
581 \def\pgfmath@zeros{}%
582 \def\pgfmath@targetiterations{2}%
583 \else%
584 \def\pgfmath@zeros{0}%
585 \def\pgfmath@targetiterations{3}%
586 \fi\fi\fi\fi\fi%
587 \edef\pgfmath@temp{\pgfmath@zeros\pgfmath@tonumber{\pgfmath@x}}%
588 \expandafter\pgfmath@sqrt@\pgfmath@temp\pgfmath@%
589 }
590 \def\pgfmath@sqrt@#1.#2\pgfmath@{\pgfmath@@sqrt@#1#2\pgfmath@empty\pgfmath@empty\pgfmath@}
591
592 \def\pgfmath@@sqrt@#1#2{%
593 \c@pgfmath@countb=#1#2\relax%
594 \ifnum\c@pgfmath@countb>35\relax%
595 \ifnum\c@pgfmath@countb>63\relax%
596 \ifnum\c@pgfmath@countb>80\relax%
597 \c@pgfmath@counta=9\relax%
598 \else%
599 \c@pgfmath@counta=8\relax%
600 \fi%
601 \else%
602 \ifnum\c@pgfmath@countb>48\relax%
603 \c@pgfmath@counta=7\relax%
604 \else%
605 \c@pgfmath@counta=6\relax%
606 \fi%
607 \fi%
608 \else%
609 \ifnum\c@pgfmath@countb>15\relax%
610 \ifnum\c@pgfmath@countb>24\relax%
611 \c@pgfmath@counta5\relax%
612 \else%
613 \c@pgfmath@counta=4\relax%
614 \fi%
615 \else%
616 \ifnum\c@pgfmath@countb>3\relax%
617 \ifnum\c@pgfmath@countb>8\relax%
618 \c@pgfmath@counta=3\relax%
619 \else%
620 \c@pgfmath@counta=2\relax%
621 \fi%
622 \else%
623 \ifnum\c@pgfmath@countb>0\relax%
624 \c@pgfmath@counta=1\relax%
625 \else%
626 \c@pgfmath@counta=0\relax%
627 \fi%
628 \fi%
629 \fi%
630 \fi%
631 \edef\pgfmath@root{\the\c@pgfmath@counta}%
632 \edef\pgfmath@rootspecial{\the\c@pgfmath@counta}%
633 \multiply\c@pgfmath@counta by-\c@pgfmath@counta\relax%
634 \advance\c@pgfmath@counta by#1#2\relax%
635 \edef\pgfmath@remainder{\the\c@pgfmath@counta}%
636 \pgfmath@@@sqrt@%
637 }
638
639 \def\pgfmath@@@sqrt@#1#2{%
640 \ifx\pgfmath@empty#1%
641 \edef\pgfmath@remainder{\pgfmath@remainder00}%
642 \def\pgfmath@tokens{\pgfmath@empty\pgfmath@empty}%
643 \else%
644 \ifx\pgfmath@empty#2%
645 \edef\pgfmath@remainder{\pgfmath@remainder#10}%
646 \def\pgfmath@tokens{\pgfmath@empty\pgfmath@empty}%
647 \else%
648 \edef\pgfmath@remainder{\pgfmath@remainder#1#2}%
649 \def\pgfmath@tokens{}%
650 \fi\fi%
651 \c@pgfmath@counta=\pgfmath@rootspecial\relax%
652 \multiply\c@pgfmath@counta by20\relax%
653 \c@pgfmath@countb=\c@pgfmath@counta%
654 \multiply\c@pgfmath@countb by6\relax%
655 \advance\c@pgfmath@countb by36\relax%
656 \c@pgfmath@countc=\c@pgfmath@counta%
657 \multiply\c@pgfmath@countc by2\relax%
658 \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax%
659 \advance\c@pgfmath@countb by-\c@pgfmath@countc%
660 \advance\c@pgfmath@countb by-20\relax%
661 \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax%
662 \advance\c@pgfmath@countb by-\c@pgfmath@countc%
663 \advance\c@pgfmath@countb by-12\relax%
664 \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax%
665 \advance\c@pgfmath@countb by-\c@pgfmath@counta%
666 \advance\c@pgfmath@countb by-3\relax%
667 \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax%
668 \def\pgfmath@digit{0}%
669 \else%
670 \def\pgfmath@digit{1}%
671 \fi%
672 \else%
673 \advance\c@pgfmath@countb by\c@pgfmath@counta%
674 \advance\c@pgfmath@countb by5\relax%
675 \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax%
676 \def\pgfmath@digit{2}%
677 \else%
678 \def\pgfmath@digit{3}%
679 \fi%
680 \fi%
681 \else%
682 \advance\c@pgfmath@countb by\c@pgfmath@counta%
683 \advance\c@pgfmath@countb by9\relax%
684 \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax%
685 \def\pgfmath@digit{4}%
686 \else%
687 \def\pgfmath@digit{5}%
688 \fi%
689 \fi%
690 \else%
691 \advance\c@pgfmath@countb by\c@pgfmath@countc%
692 \advance\c@pgfmath@countb by28\relax%
693 \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax%
694 \advance\c@pgfmath@countb by-\c@pgfmath@counta%
695 \advance\c@pgfmath@countb by-15\relax%
696 \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax%
697 \def\pgfmath@digit{6}%
698 \else%
699 \def\pgfmath@digit{7}%
700 \fi%
701 \else%
702 \advance\c@pgfmath@countb by\c@pgfmath@counta%
703 \advance\c@pgfmath@countb by17\relax%
704 \ifnum\c@pgfmath@countb>\pgfmath@remainder\relax%
705 \def\pgfmath@digit{8}%
706 \else%
707 \def\pgfmath@digit{9}%
708 \fi%
709 \fi%
710 \fi%
711 \edef\pgfmath@rootspecial{\pgfmath@rootspecial\pgfmath@digit}%
712 \advance\c@pgfmath@counta by\pgfmath@digit\relax%
713 \multiply\c@pgfmath@counta by-\pgfmath@digit\relax%
714 \advance\c@pgfmath@counta by\pgfmath@remainder\relax%
715 \edef\pgfmath@remainder{\the\c@pgfmath@counta}%
716 \c@pgfmath@counta=\pgfmath@targetiterations\relax%
717 \advance\c@pgfmath@counta by-1\relax%
718 \edef\pgfmath@targetiterations{\the\c@pgfmath@counta}%
719 \ifnum\c@pgfmath@counta=0\relax%
720 \edef\pgfmath@root{\pgfmath@root.\pgfmath@digit}%
721 \else%
722 \edef\pgfmath@root{\pgfmath@root\pgfmath@digit}%
723 \fi%
724 \ifnum\c@pgfmath@counta=-4\relax% -n+1 digits of precision.
725 \let\pgfmath@next\pgfmath@sqrt@end%
726 \else%
727 \let\pgfmath@next\pgfmath@@@sqrt@%
728 \fi%
729 \expandafter\pgfmath@next\pgfmath@tokens%
730 }
731
732 \def\pgfmath@sqrt@end#1\pgfmath@{%
733 \edef\pgfmathresult{\pgfmath@root}%
734 \pgfmath@smuggleone\pgfmathresult%
735 \endgroup}
736
737 % \pgfmathpow
738 %
739 % Calculates #1 ^ #2
740 %
741 \pgfmathdeclarefunction{pow}{2}{%
742 \begingroup%
743 \pgfmath@xa=#1pt%
744 \pgfmath@xb=#2pt%
745 \ifdim\pgfmath@xa=0pt\relax%
746 \ifdim\pgfmath@xb=0pt\relax%
747 \pgfmath@x=1pt\relax%
748 \else%
749 \pgfmath@x=0pt\relax%
750 \fi%
751 \else%
752 \afterassignment\pgfmath@x%
753 \expandafter\c@pgfmath@counta\the\pgfmath@xb\relax%
754 \ifnum\c@pgfmath@counta<0\relax%
755 \c@pgfmath@counta=-\c@pgfmath@counta%
756 \pgfmathreciprocal@{#1}%
757 \pgfmath@xa=\pgfmathresult pt\relax%
758 \fi
759 \ifdim\pgfmath@x=0pt\relax%
760 \pgfmath@x=1pt\relax%
761 \pgfmathloop%
762 \ifnum\c@pgfmath@counta>0\relax%
763 \ifodd\c@pgfmath@counta%
764 \pgfmath@x=\pgfmath@tonumber{\pgfmath@x}\pgfmath@xa%
765 \fi
766 \ifnum\c@pgfmath@counta>1\relax%
767 \pgfmath@xa=\pgfmath@tonumber{\pgfmath@xa}\pgfmath@xa%
768 \fi%
769 \divide\c@pgfmath@counta by2\relax%
770 \repeatpgfmathloop%
771 \else%
772 \pgfmathln@{#1}%
773 \pgfmath@x=\pgfmathresult pt\relax%
774 \pgfmath@x=\pgfmath@tonumber{\pgfmath@xb}\pgfmath@x%
775 \pgfmathexp@{\pgfmath@tonumber{\pgfmath@x}}%
776 \pgfmath@x=\pgfmathresult pt\relax%
777 \fi%
778 \fi
779 \pgfmath@returnone\pgf@x%
780 \endgroup%
781 }
782
783 % factorial function.
784 %
785 \pgfmathdeclarefunction{factorial}{1}{%
786 \begingroup%
787 \afterassignment\pgfmath@gobbletilpgfmath@%
788 \c@pgfmath@counta=#1\relax\pgfmath@%
789 \pgfmath@x=1pt\relax%
790 \pgfmathloop%
791 \ifnum\c@pgfmath@counta<2\relax%
792 \else%
793 \multiply\pgfmath@x by\c@pgfmath@counta%
794 \advance\c@pgfmath@counta by-1\relax%
795 \repeatpgfmathloop%
796 \edef\pgfmathresult{\pgfmath@tonumber{\pgfmath@x}}%
797 \pgfmath@smuggleone\pgfmathresult%
798 \endgroup%
799 }
800
801 % Local Variables:
802 % coding: undecided-unix
803 % End: