Debian Codegraph @

texmf-dist/tex/generic/pstricks/pst-fp.tex

raw
1 %% $Id: pst-fp.tex 276 2021-09-27 11:28:22Z herbert $
2 %%
3 %%
4 %% This is file `pst-fp.tex',
5 %%
6 %% IMPORTANT NOTICE:
7 %%
8 %% Package `pst-fp.tex'
9 %%
10 %% Herbert Voss <[email protected]>
11 %% "stolen" from the fp package by Michael Mehlich
12 %%
13 %% This program can be redistributed and/or modified under the terms
14 %% of the LaTeX Project Public License Distributed from CTAN archives
15 %% in directory macros/latex/base/lppl.txt.
16 %%
17 %% DESCRIPTION:
18 %% `pst-fp' is a PSTricks related package for a division,
19 %% multiplication and addition
20 %%
21 %
22 \def\fileversion{0.06}
23 \def\filedate{2020/11/20}
24 \message{`pst-fp' v\fileversion, \filedate\space (hv)}
25
26 \csname PSTFPloaded\endcsname
27 \let\PSTFPloaded\endinput
28 % Requires some packages
29 \ifx\PSTricksLoaded\endinput\else\input pstricks \fi
30 %
31 \edef\PstAtCode{\the\catcode`\@} \catcode`\@=11\relax
32
33 %fixed point arithmetic with values between (including)
34 % -999999999999999999.999999999999999999
35 % and +999999999999999999.999999999999999999
36
37 \def\pstFPadd#1#2#3{\pstFP@callc\pstFP@add#1{#2}{#3}+\relax} % #1 := #2+#3
38 \def\pstFPsub#1#2#3{\pstFP@callc\pstFP@add#1{#2}{-#3}-\relax}% #1 := #2-#3
39 \def\pstFPmul#1#2#3{\pstFP@callc\pstFP@mul#1{#2}{#3}} % #1 := #2*#3
40 \def\pstFPdiv#1#2#3{\pstFP@callc\pstFP@div#1{#2}{#3}} % #1 := #2/#3
41
42 \def\pst@int#1{\expandafter\pst@@int#1..\@nil}
43 \def\pst@@int#1.#2.\@nil{#1}
44 \def\pst@Int#1{%
45 \@tempdima=#1\relax%
46 \expandafter\pst@@Int\the\@tempdima\@nil}
47 \def\pst@@Int#1.#2\@nil{#1}
48
49 %
50 \def\pstFPMul#1#2#3{\pstFP@callc\pstFP@mul#1{#2}{#3}% % #1 := int(#2*#3)
51 \edef#1{\pst@int{#1}}}%
52 \def\pstFPDiv#1#2#3{\pstFP@callc\pstFP@div#1{#2}{#3}% % #1 := int(#2/#3)
53 \edef#1{\pst@int{#1}}}%
54 \def\pstFPstripZeros#1#2{\pst@dimm=#1pt\relax \edef#2{\strip@pt\pst@dimm}}
55 %
56 \countdef\pstFP@actcounter=10 % register 0 for counter
57 \ifnum\pstFP@actcounter<60\relax \pstFP@actcounter=60\fi
58
59 \newcount\pstFP@xs %sign of 1st value
60 \newcount\pstFP@xia%integer part of 1st value
61 \newcount\pstFP@xib%integer part of 1st value
62 \newcount\pstFP@xfa%fractional part of 1st value
63 \newcount\pstFP@xfb%fractional part of 1st value
64
65 \countdef\pstFP@ys=5 %sign of 2nd value
66 \countdef\pstFP@yia=6%integer part of 2nd value
67 \countdef\pstFP@yib=7%integer part of 2nd value
68 \countdef\pstFP@yfa=8%fractional part of 2nd value
69 \countdef\pstFP@yfb=9%fractional part of 2nd value
70
71 \countdef\pstFP@xk=10 %registers for splitting 1st value
72 \countdef\pstFP@xl=11
73 \countdef\pstFP@xm=12
74 \countdef\pstFP@xn=13
75 \countdef\pstFP@xo=14
76 \countdef\pstFP@xp=15
77 \countdef\pstFP@xq=16
78 \countdef\pstFP@xr=17
79 \countdef\pstFP@xz=18
80 \countdef\pstFP@xt=19
81 \countdef\pstFP@xu=20
82 \countdef\pstFP@xv=21
83
84 \countdef\pstFP@yk=22 %registers for splitting 2nd value
85 \countdef\pstFP@yl=23
86 \countdef\pstFP@ym=24
87 \countdef\pstFP@yn=25
88 \countdef\pstFP@yo=26
89 \countdef\pstFP@yp=27
90 \countdef\pstFP@yq=28
91 \countdef\pstFP@yr=29
92 \countdef\pstFP@yz=30
93 \countdef\pstFP@yt=31
94 \countdef\pstFP@yu=32
95 \countdef\pstFP@yv=33
96
97 \newcount\pstFP@rega %auxiliary registers
98 \newcount\pstFP@regb
99 \countdef\pstFP@regc=36
100 \countdef\pstFP@regd=37
101 \countdef\pstFP@rege=38
102
103 \countdef\pstFP@rs=39 %result registers
104 \countdef\pstFP@ria=40
105 \countdef\pstFP@rib=41
106 \countdef\pstFP@rfa=42
107 \countdef\pstFP@rfb=43
108
109 \newcount\pstFP@regs %local auxiliary registers
110 \countdef\pstFP@count=45
111 \countdef\pstFP@res=46
112 \countdef\pstFP@shift=47
113 \newcount\pstFP@times
114 \countdef\pstFP@prod=49
115
116 %auxiliary macros which may be used in all of the following macros
117 \newif\ifpstFP@test
118
119 \def\pstFP@ignorenext#1{}
120 \def\pstFP@first#1#2\relax{#1}
121 \def\pstFP@swallow#1\relax{}
122 %
123 \def\ifpstFP@zero#1{%
124 \ifnum
125 \expandafter\ifnum\csname pstFP@#1ia\endcsname=0 0\else1\fi
126 \expandafter\ifnum\csname pstFP@#1ib\endcsname=0 0\else1\fi
127 \expandafter\ifnum\csname pstFP@#1fa\endcsname=0 0\else1\fi
128 \expandafter\ifnum\csname pstFP@#1fb\endcsname=0 0\else1\fi%
129 =0\relax
130 }
131 %
132 %read value
133 %
134 \def\pstFP@correctintcounter#1\relax{%
135 {\edef\pstFP@tmp{#1}%
136 \pstFP@count=0\relax%
137 \loop%
138 \edef\pstFP@tmpa{\expandafter\pstFP@first\pstFP@tmp\noexpand\relax}%
139 \expandafter\ifx\pstFP@tmpa0\relax%
140 \advance\pstFP@count1\relax%
141 \edef\pstFP@tmp{\expandafter\pstFP@ignorenext\pstFP@tmp}%
142 \repeat%
143 \ifnum\pstFP@count>18\relax \typeout{>>>> Overflow}\fi%
144 \expandafter\if!\pstFP@tmp!%
145 \advance\pstFP@count-18\relax%
146 \pstFP@count=-\pstFP@count%
147 \loop%
148 \ifnum\pstFP@count>0\relax%
149 \pstFP@regc=\pstFP@rega%
150 \divide\pstFP@rega10\relax\multiply\pstFP@rega10\relax%
151 \advance\pstFP@regc-\pstFP@rega\multiply\pstFP@regc100000000\relax%
152 \divide\pstFP@rega10\relax%
153 \divide\pstFP@regb10\relax\advance\pstFP@regb\pstFP@regc%
154 \advance\pstFP@count-1\relax%
155 \repeat%
156 \global\pstFP@rega=\pstFP@rega%
157 \global\pstFP@regb=\pstFP@regb%
158 \else%
159 \typeout{>>>>Number too big}%
160 \fi%
161 }%
162 }
163 \def\pstFP@@setintcounter#1#2#3#4#5#6#7#8#9{%
164 \pstFP@regb=#1#2#3#4#5#6#7#8#9\relax%
165 \pstFP@correctintcounter%
166 }
167 \def\pstFP@setintcounter#1#2#3#4#5#6#7#8#9{%
168 \pstFP@rega=#1#2#3#4#5#6#7#8#9\relax%
169 \pstFP@@setintcounter%
170 }
171
172 \def\pstFP@@setfractcounter#1#2#3#4#5#6#7#8#9{%
173 \pstFP@regb=#1#2#3#4#5#6#7#8#9\relax%
174 \pstFP@swallow%
175 }
176 \def\pstFP@setfractcounter#1#2#3#4#5#6#7#8#9{%
177 \pstFP@rega=#1#2#3#4#5#6#7#8#9\relax%
178 \pstFP@@setfractcounter%
179 }
180
181 \def\pstFP@getsign#1\relax{%
182 {\pstFP@regs=1\relax%
183 \edef\pstFP@tmp{#1}%
184 \loop%
185 \edef\pstFP@tmpa{\expandafter\pstFP@first\pstFP@tmp\noexpand\relax}%
186 \expandafter\ifx\pstFP@tmpa-\relax%
187 \multiply\pstFP@regs-1\relax%
188 \fi%
189 \ifnum\expandafter\ifx\pstFP@tmpa-1\else0\fi\expandafter\ifx\pstFP@tmpa+1\else0\fi>0%
190 \edef\pstFP@tmp{\expandafter\pstFP@ignorenext\pstFP@tmp}%
191 \repeat%
192 \global\let\pstFP@tmp\pstFP@tmp%
193 \global\pstFP@regs=\pstFP@regs%
194 }%
195 }
196
197 \def\pstFP@removeleadingzeros#1\relax{%
198 {\edef\pstFP@tmp{#1}%
199 \loop%
200 \edef\pstFP@tmpa{\expandafter\pstFP@first\pstFP@tmp\noexpand\relax}%
201 \expandafter\ifx\pstFP@tmpa0\relax%
202 \edef\pstFP@tmp{\expandafter\pstFP@ignorenext\pstFP@tmp}%
203 \repeat%
204 \global\let\pstFP@tmp\pstFP@tmp%
205 }%
206 }
207
208 \newif\ifpstFP@nonstop
209 \def\pstFP@strip#1{%
210 {\edef\pstFP@tmp{#1}%
211 \edef\pstFP@tmpb{}%
212 \ifx\pstFP@tmp\@empty\else%
213 \pstFP@nonstoptrue%
214 \loop%
215 \edef\pstFP@tmpa{\expandafter\pstFP@first\pstFP@tmp\noexpand\relax}%
216 \expandafter\ifx\pstFP@tmpa-\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
217 \expandafter\ifx\pstFP@tmpa+\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
218 \expandafter\ifx\pstFP@tmpa0\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
219 \expandafter\ifx\pstFP@tmpa1\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
220 \expandafter\ifx\pstFP@tmpa2\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
221 \expandafter\ifx\pstFP@tmpa3\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
222 \expandafter\ifx\pstFP@tmpa4\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
223 \expandafter\ifx\pstFP@tmpa5\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
224 \expandafter\ifx\pstFP@tmpa6\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
225 \expandafter\ifx\pstFP@tmpa7\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
226 \expandafter\ifx\pstFP@tmpa8\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
227 \expandafter\ifx\pstFP@tmpa9\relax\edef\pstFP@tmpb{\pstFP@tmpb\pstFP@tmpa}\else%
228 \ifx\pstFP@tmpa\@empty\pstFP@nonstopfalse\else%
229 \ifx\pstFP@tmpa\space\pstFP@nonstopfalse\else%
230 \typeout{>>> Illegal character \pstFP@tmpa\space found in float number}%
231 \fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi\fi%
232 \edef\pstFP@tmp{\expandafter\pstFP@ignorenext\pstFP@tmp}%
233 \ifx\pstFP@tmp\@empty\pstFP@nonstopfalse\fi%
234 \ifpstFP@nonstop%
235 \repeat%
236 \fi%
237 \global\let\pstFP@tmp\pstFP@tmpb%
238 }%
239 }
240
241 \def\pstFP@readvalue#1#2#3{%
242 % #1 macro family to catch the value
243 % #2.#3 value
244 %
245 % regular expression [+|-]*[d]_0^18.[d]*
246 %
247 \pstFP@strip{#2}%
248 %sign
249 \expandafter\pstFP@getsign\pstFP@tmp\relax%
250 \csname pstFP@#1s\endcsname=\pstFP@regs%
251 %
252 %integer part
253 \pstFP@removeleadingzeros\pstFP@tmp\relax%
254 \expandafter\pstFP@setintcounter\pstFP@tmp000000000000000000\relax%
255 \csname pstFP@#1ia\endcsname=\pstFP@rega%
256 \csname pstFP@#1ib\endcsname=\pstFP@regb%
257 %
258 %fractional part
259 \pstFP@strip{#3}%
260 \expandafter\pstFP@setfractcounter\pstFP@tmp000000000000000000\relax%
261 \csname pstFP@#1fa\endcsname=\pstFP@rega%
262 \csname pstFP@#1fb\endcsname=\pstFP@regb%
263 %
264 %correct sign
265 \ifnum\pstFP@rega=0\relax%
266 \ifnum\pstFP@regb=0\relax%
267 \expandafter\ifnum\csname pstFP@#1ib\endcsname=0\relax%
268 \expandafter\ifnum\csname pstFP@#1ia\endcsname=0\relax%
269 \csname pstFP@#1s\endcsname=1\relax%
270 \fi%
271 \fi%
272 \fi%
273 \fi%
274 }
275 %
276 %store value in macro
277 %
278 \def\pstFP@store#1#2{%
279 % #1 macro
280 % #2 macro family (value) to store
281 %
282 \ifpstFP@zero{#2}%
283 \csname pstFP@#2s\endcsname=1\relax%
284 \fi%
285 \expandafter\ifnum\csname pstFP@#2s\endcsname<0\relax%
286 \edef#1{-}%
287 \else%
288 \edef#1{}%
289 \fi%
290 \expandafter\ifnum\csname pstFP@#2ia\endcsname=0\relax%
291 \expandafter\ifnum\csname pstFP@#2ib\endcsname=0\relax%
292 \edef#1{#10}%
293 \else%
294 \edef#1{#1\expandafter\the\csname pstFP@#2ib\endcsname}%
295 \fi%
296 \else%
297 \expandafter\advance\csname pstFP@#2ib\endcsname1000000000\relax%
298 \edef#1{#1\expandafter\the\csname pstFP@#2ia\endcsname\expandafter\pstFP@ignorenext\the\csname pstFP@#2ib\endcsname}%
299 \fi%
300 \expandafter\advance\csname pstFP@#2fa\endcsname1000000000\relax%
301 \expandafter\advance\csname pstFP@#2fb\endcsname1000000000\relax%
302 \edef#1{#1\noexpand.\expandafter\pstFP@ignorenext\the\csname pstFP@#2fa\endcsname\expandafter\pstFP@ignorenext\the\csname pstFP@#2fb\endcsname}%
303 }
304 %macros to expand some arguments
305 %
306 \def\pstFP@callc#1#2#3#4{%
307 % #1 macro to call
308 % #2 macro, which gets the result
309 % #3 1st value
310 % #4 2nd value
311 % expand the values and split them into the integer and the fractional parts
312 \edef\next{\noexpand#1\noexpand#2#3..\noexpand\relax#4..\noexpand\relax}%
313 \next%
314 }
315 %
316 \def\pstFP@divten#1{%
317 \expandafter\pstFP@regc\csname pstFP@#1ia\endcsname%
318 \expandafter\divide\csname pstFP@#1ia\endcsname10\relax%
319 \expandafter\pstFP@regb\csname pstFP@#1ia\endcsname%
320 \multiply\pstFP@regb10\relax%
321 \advance\pstFP@regc-\pstFP@regb%
322 \multiply\pstFP@regc100000000\relax%
323 %
324 \expandafter\pstFP@rega\csname pstFP@#1ib\endcsname%
325 \expandafter\divide\csname pstFP@#1ib\endcsname10\relax%
326 \expandafter\pstFP@regb\csname pstFP@#1ib\endcsname%
327 \multiply\pstFP@regb10\relax%
328 \advance\pstFP@rega-\pstFP@regb%
329 \multiply\pstFP@rega100000000\relax%
330 \expandafter\advance\csname pstFP@#1ib\endcsname\pstFP@regc%
331 %
332 \expandafter\pstFP@regc\csname pstFP@#1fa\endcsname%
333 \expandafter\divide\csname pstFP@#1fa\endcsname10\relax%
334 \expandafter\pstFP@regb\csname pstFP@#1fa\endcsname%
335 \multiply\pstFP@regb10\relax%
336 \advance\pstFP@regc-\pstFP@regb%
337 \multiply\pstFP@regc100000000\relax%
338 \expandafter\advance\csname pstFP@#1fa\endcsname\pstFP@rega%
339 %
340 \expandafter\divide\csname pstFP@#1fb\endcsname10\relax%
341 \expandafter\advance\csname pstFP@#1fb\endcsname\pstFP@regc%
342 }
343 %
344 \def\pstFP@multen#1{%
345 \expandafter\multiply\csname pstFP@#1ia\endcsname10\relax%
346 \expandafter\ifnum\csname pstFP@#1ib\endcsname<100000000\relax%
347 \else%
348 \expandafter\pstFP@regc\csname pstFP@#1ib\endcsname%
349 \divide\pstFP@regc100000000%
350 \expandafter\advance\csname pstFP@#1ia\endcsname\pstFP@regc%
351 \multiply\pstFP@regc100000000%
352 \expandafter\advance\csname pstFP@#1ib\endcsname-\pstFP@regc%
353 \fi%
354 \expandafter\multiply\csname pstFP@#1ib\endcsname10\relax%
355 \expandafter\ifnum\csname pstFP@#1fa\endcsname<100000000\relax%
356 \else%
357 \expandafter\pstFP@regc\csname pstFP@#1fa\endcsname%
358 \divide\pstFP@regc100000000%
359 \expandafter\advance\csname pstFP@#1ib\endcsname\pstFP@regc%
360 \multiply\pstFP@regc100000000%
361 \expandafter\advance\csname pstFP@#1fa\endcsname-\pstFP@regc%
362 \fi%
363 \expandafter\multiply\csname pstFP@#1fa\endcsname10\relax%
364 \expandafter\ifnum\csname pstFP@#1fb\endcsname<100000000\relax%
365 \else%
366 \expandafter\pstFP@regc\csname pstFP@#1fb\endcsname%
367 \divide\pstFP@regc100000000%
368 \expandafter\advance\csname pstFP@#1fa\endcsname\pstFP@regc%
369 \multiply\pstFP@regc100000000%
370 \expandafter\advance\csname pstFP@#1fb\endcsname-\pstFP@regc%
371 \fi%
372 \expandafter\multiply\csname pstFP@#1fb\endcsname10\relax%
373 }
374 %
375 \def\pstFP@counttimes{%
376 {\global\pstFP@times=0\relax%
377 \loop%
378 \ifnum%
379 \ifnum\pstFP@xia>\pstFP@yia1%
380 \else\ifnum\pstFP@xia<\pstFP@yia0%
381 \else%
382 \ifnum\pstFP@xib>\pstFP@yib1%
383 \else\ifnum\pstFP@xib<\pstFP@yib0%
384 \else%
385 \ifnum\pstFP@xfa>\pstFP@yfa1%
386 \else\ifnum\pstFP@xfa<\pstFP@yfa0%
387 \else%
388 \ifnum\pstFP@xfb>\pstFP@yfb1%
389 \else\ifnum\pstFP@xfb<\pstFP@yfb0%
390 \else%
391 1%
392 \fi\fi%
393 \fi\fi%
394 \fi\fi%
395 \fi\fi%
396 =1\relax%
397 \global\advance\pstFP@times1\relax%
398 \global\advance\pstFP@xfb-\pstFP@yfb%
399 \ifnum\pstFP@xfb<0\relax%
400 \global\advance\pstFP@xfb1000000000\relax%
401 \global\advance\pstFP@xfa-1\relax%
402 \fi%
403 \global\advance\pstFP@xfa-\pstFP@yfa%
404 \ifnum\pstFP@xfa<0\relax%
405 \global\advance\pstFP@xfa1000000000\relax%
406 \global\advance\pstFP@xib-1\relax%
407 \fi%
408 \global\advance\pstFP@xib-\pstFP@yib%
409 \ifnum\pstFP@xib<0\relax%
410 \global\advance\pstFP@xib1000000000\relax%
411 \global\advance\pstFP@xia-1\relax%
412 \fi%
413 \global\advance\pstFP@xia-\pstFP@yia%
414 \repeat%
415 }%
416 }
417 %
418 \def\pstFP@add#1#2.#3.#4\relax#5.#6.#7\relax#8\relax{%
419 % #1 macro, which gets the result
420 % #2 integer part of 1st value
421 % #3 fractional part of 1st value
422 % #4 dummy to swallow everthing after the 2nd '.'
423 % #5 integer part of 2nd value
424 % #6 fractional part of 2nd value
425 % #7 dummy to swallow everthing after the 2nd '.'
426 %
427 {\pstFP@readvalue{x}{#2}{#3}%
428 \pstFP@readvalue{y}{#5}{#6}%
429 %
430 \ifnum\pstFP@xs=\pstFP@ys%
431 \advance\pstFP@xfb\pstFP@yfb%
432 \advance\pstFP@xfa\pstFP@yfa%
433 \ifnum\pstFP@xfb<1000000000\relax\else%
434 \advance\pstFP@xfb-1000000000\relax%
435 \advance\pstFP@xfa1\relax%
436 \fi%
437 \advance\pstFP@xib\pstFP@yib%
438 \ifnum\pstFP@xfa<1000000000\relax\else%
439 \advance\pstFP@xfa-1000000000\relax%
440 \advance\pstFP@xib1\relax%
441 \fi%
442 \advance\pstFP@xia\pstFP@yia%
443 \ifnum\pstFP@xib<1000000000\relax\else%
444 \advance\pstFP@xib-1000000000\relax%
445 \advance\pstFP@xia1\relax%
446 \fi%
447 \ifnum\pstFP@xia<1000000000\relax\else%
448 \pstFP@errmessage{Overflow}%
449 \fi%
450 \pstFP@store\pstFP@tmp{x}%
451 \else%
452 \advance\pstFP@xfb-\pstFP@yfb%
453 \ifnum\pstFP@xfb<0\relax%
454 \advance\pstFP@yfa1\relax%
455 \advance\pstFP@xfb1000000000\relax%
456 \fi%
457 \advance\pstFP@xfa-\pstFP@yfa%
458 \ifnum\pstFP@xfa<0\relax%
459 \advance\pstFP@yib1\relax%
460 \advance\pstFP@xfa1000000000\relax%
461 \fi%
462 \advance\pstFP@xib-\pstFP@yib%
463 \ifnum\pstFP@xib<0\relax%
464 \advance\pstFP@yia1\relax%
465 \advance\pstFP@xib1000000000\relax%
466 \fi%
467 \advance\pstFP@xia-\pstFP@yia%
468 \ifnum\pstFP@xia<0\relax%
469 \pstFP@xs=-\pstFP@xs%
470 \ifnum\pstFP@xfb=0\relax\else%
471 \advance\pstFP@xfb-1000000000\relax\pstFP@xfb=-\pstFP@xfb%
472 \advance\pstFP@xfa1\relax%
473 \fi%
474 \ifnum\pstFP@xfa=0\relax\else%
475 \advance\pstFP@xfa-1000000000\relax\pstFP@xfa=-\pstFP@xfa%
476 \advance\pstFP@xib1\relax%
477 \fi%
478 \ifnum\pstFP@xib=0\relax\else%
479 \advance\pstFP@xib-1000000000\relax\pstFP@xib=-\pstFP@xib%
480 \advance\pstFP@xia1\relax%
481 \fi%
482 \relax\pstFP@xia=-\pstFP@xia%
483 \fi%
484 \pstFP@store\pstFP@tmp{x}%
485 \fi%
486 \global\let\pstFP@tmp\pstFP@tmp%
487 }%
488 % \pstFPstripZeros\pstFP@tmp{#1}%
489 \let#1\pstFP@tmp
490 }
491
492
493 \def\pstFP@div#1#2.#3.#4\relax#5.#6.#7\relax{%
494 % #1 macro, which gets the result
495 % #2 integer part of 1st value
496 % #3 fractional part of 1st value
497 % #4 dummy to swallow everthing after the 2nd '.'
498 % #5 integer part of 2nd value
499 % #6 fractional part of 2nd value
500 % #7 dummy to swallow everthing after the 2nd '.'
501 %
502 % algorithmic idea (for x>0, y>0)
503 % - %determine \pstFP@shift such that y*10^\pstFP@shift <100000000<=y*10^(\pstFP@shift+1)
504 % - %determine \pstFP@shift' such that x*10^\pstFP@shift'<100000000<=x*10^(\pstFP@shift+1)
505 % - x=x*\pstFP@shift'
506 % - y=y*\pstFP@shift
507 % - \pstFP@shift=\pstFP@shift-\pstFP@shift'
508 % - res=0
509 % - while y>0 %fixed-point representation!
510 % - \pstFP@times=0
511 % - while x>y
512 % - \pstFP@times=\pstFP@times+1
513 % - x=x-y
514 % - end
515 % - y=y/10
516 % - res=10*res+\pstFP@times/1000000000
517 % - end
518 % - %shift the result according to \pstFP@shift
519 %
520 {\pstFP@readvalue{x}{#2}{#3}%
521 \pstFP@readvalue{y}{#5}{#6}%
522 %
523 %sign
524 \multiply\pstFP@xs\pstFP@ys%
525 \pstFP@rs=\pstFP@xs%
526 %
527 %compute division
528 \ifpstFP@zero{y}%
529 \typeout{>>>>Division by zero}%
530 \else%
531 \ifpstFP@zero{x}\def\next##1{\edef\pstFP@tmp{0}}\else\def\next##1{##1}\fi%
532 \next%
533 {\pstFP@shift=0\relax%
534 \loop%
535 \ifnum\pstFP@yia<100000000\relax%
536 \pstFP@multen{y}%
537 \advance\pstFP@shift1\relax%
538 \repeat%
539 \loop%
540 \ifnum\pstFP@xia<100000000\relax%
541 \pstFP@multen{x}%
542 \advance\pstFP@shift-1\relax%
543 \repeat%
544 \pstFP@ria=0\pstFP@rib=0\pstFP@rfa=0\pstFP@rfb=0\relax%
545 \loop%
546 \ifpstFP@zero{y}\else%
547 \pstFP@counttimes%divides x by \pstFP@times*y
548 \pstFP@divten{y}%
549 \pstFP@multen{r}%
550 \advance\pstFP@rfb\pstFP@times%
551 \ifnum\pstFP@rfb<1000000000\relax\else%
552 \advance\pstFP@rfa1\advance\pstFP@rfb-1000000000\relax%
553 \ifnum\pstFP@rfa<1000000000\relax\else%
554 \advance\pstFP@rib1\advance\pstFP@rfa-1000000000\relax%
555 \ifnum\pstFP@rib<1000000000\relax\else%
556 \advance\pstFP@ria1\advance\pstFP@rib-1000000000\relax%
557 \fi%
558 \fi%
559 \fi%
560 \repeat%
561 \loop%
562 \ifnum\pstFP@shift>17%
563 \advance\pstFP@shift-1\relax%
564 \ifnum\pstFP@ria<100000000\else\pstFP@ria=-1\fi%
565 \ifnum\pstFP@ria<0\pstFP@ria=-1\fi%
566 \pstFP@multen{r}%
567 \repeat%
568 \ifnum\pstFP@ria<1000000000\else\pstFP@ria=-1\fi%
569 \loop%
570 \ifnum\pstFP@shift<17%
571 \advance\pstFP@shift1\relax%
572 \pstFP@divten{r}%
573 \repeat%
574 \ifnum\pstFP@ria<0\relax%
575 \typeout{>>>>Overflow}%
576 \else%
577 \pstFP@store\pstFP@tmp{r}%
578 \fi%
579 }%
580 \fi%
581 %
582 \global\let\pstFP@tmp=\pstFP@tmp%
583 %
584 }%
585 % \pstFPstripZeros\pstFP@tmp{#1}%
586 \let#1\pstFP@tmp
587 }
588 %multiply two values
589
590 \def\pstFP@firstnine#1#2#3#4#5#6#7#8#9{%
591 \pstFP@res=#1#2#3#4#5#6#7#8#9\relax%
592 }
593 \def\pstFP@@ninesplit#1\relax#2\end#3{%
594 #1%
595 \edef#3{#2}%
596 }
597 \def\pstFP@ninesplit#1{%
598 \edef#1{\expandafter\pstFP@firstnine\pstFP@rd}%
599 \expandafter\pstFP@@ninesplit#1\end#1\relax%
600 }
601
602 \def\pstFP@split#1#2#3#4{%
603 % #1 highest three digits
604 % #2 medium three digits
605 % #3 least three digits
606 % #4 counter
607 \pstFP@regc=#4%
608 \divide\pstFP@regc1000000\relax%
609 #1=\pstFP@regc%
610 \multiply\pstFP@regc-1000000\relax\advance\pstFP@regc#4%
611 #3=\pstFP@regc%
612 \divide\pstFP@regc1000\relax%
613 #2=\pstFP@regc%
614 \multiply\pstFP@regc-1000\relax\advance\pstFP@regc#3%
615 #3=\pstFP@regc%
616 }
617
618 \def\pstFP@@mul#1#2#3{%
619 \pstFP@regc=\csname pstFP@x#1\endcsname%
620 \multiply\pstFP@regc\csname pstFP@y#2\endcsname%
621 \advance\pstFP@prod\pstFP@regc%
622 %
623 \ifx#3\relax%
624 \let\next=\relax%
625 \else%
626 \let\next=\pstFP@@mul%
627 \fi%
628 \next#3%
629 }
630
631 \def\pstFP@saveshift{%
632 % save rightmost three digits
633 \pstFP@regc=\pstFP@prod%
634 \divide\pstFP@prod1000\relax%
635 \multiply\pstFP@prod1000\relax%
636 \advance\pstFP@regc-\pstFP@prod%
637 \advance\pstFP@regc1000\relax%
638 \edef\pstFP@rd{\expandafter\pstFP@ignorenext\the\pstFP@regc\pstFP@rd}%
639 %
640 \divide\pstFP@prod1000\relax%
641 }
642
643 \def\pstFP@mul#1#2.#3.#4\relax#5.#6.#7\relax{%
644 % #1 macro, which gets the result
645 % #2 integer part of 1st value
646 % #3 fractional part of 1st value
647 % #4 dummy to swallow everthing after the 2nd '.'
648 % #5 integer part of 2nd value
649 % #6 fractional part of 2nd value
650 % #7 dummy to swallow everthing after the 2nd '.'
651 %
652 % split value in various parts
653 % x y = 123 456 789 123 456 789 . 123 456 789 123 456 789
654 % -> xk xl xm xn xo xp xq xr xs xt xu xv
655 % -> yk yl ym yn yo yp yq yr ys yt yu yv
656 % multiply these parts and save the result wrt the necessary shifts
657 %
658 {\pstFP@readvalue{x}{#2}{#3}%
659 \pstFP@readvalue{y}{#5}{#6}%
660 %
661 %sign
662 \multiply\pstFP@xs\pstFP@ys%
663 \pstFP@rs=\pstFP@xs%
664 %
665 % split parts
666 \pstFP@split\pstFP@xk\pstFP@xl\pstFP@xm\pstFP@xia\pstFP@split\pstFP@xn\pstFP@xo\pstFP@xp\pstFP@xib%
667 \pstFP@split\pstFP@xq\pstFP@xr\pstFP@xz\pstFP@xfa\pstFP@split\pstFP@xt\pstFP@xu\pstFP@xv\pstFP@xfb%
668 \pstFP@split\pstFP@yk\pstFP@yl\pstFP@ym\pstFP@yia\pstFP@split\pstFP@yn\pstFP@yo\pstFP@yp\pstFP@yib%
669 \pstFP@split\pstFP@yq\pstFP@yr\pstFP@yz\pstFP@yfa\pstFP@split\pstFP@yt\pstFP@yu\pstFP@yv\pstFP@yfb%
670 %
671 \pstFP@prod=0\relax%
672 \edef\pstFP@rd{}%
673 %
674 %compute result
675 \pstFP@@mul vv \relax\pstFP@saveshift%
676 \pstFP@@mul vu uv \relax\pstFP@saveshift%
677 \pstFP@@mul uu vt tv \relax\pstFP@saveshift%
678 \pstFP@@mul ut tu vz zv \relax\pstFP@saveshift%
679 \pstFP@@mul tt zu uz rv vr \relax\pstFP@saveshift%
680 \pstFP@@mul zt tz ur ru vq qv \relax\pstFP@saveshift%
681 \pstFP@@mul zz rt tr uq qu vp pv \relax\pstFP@saveshift%
682 \pstFP@@mul zr rz tq qt up pu vo ov \relax\pstFP@saveshift%
683 \pstFP@@mul rr qz zq tp pt uo ou vn nv \relax\pstFP@saveshift%
684 \pstFP@@mul rq qr zp pz to ot un nu vm mv \relax\pstFP@saveshift%
685 \pstFP@@mul qq rp pr zo oz tn nt um mu vl lv \relax\pstFP@saveshift%
686 \pstFP@@mul qp pq ro or zn nz tm mt ul lu kv vk \relax\pstFP@saveshift%
687 \pstFP@@mul pp oq qo rn nr zm mz tl lt ku uk \relax\pstFP@saveshift%
688 \pstFP@@mul op po nq qn rm mr zl lz tk kt \relax\pstFP@saveshift%
689 \pstFP@@mul oo pn np mq qm rl lr kz zk \relax\pstFP@saveshift%
690 \pstFP@@mul no on mp pm lq ql kr rk \relax\pstFP@saveshift%
691 \pstFP@@mul nn mo om pl lp qk kq \relax\pstFP@saveshift%
692 \pstFP@@mul mn nm lo ok pk kp \relax\pstFP@saveshift%
693 \pstFP@@mul mm ln nl ko ok \relax\pstFP@saveshift%
694 \pstFP@@mul lm ml kn nk \relax\pstFP@saveshift%
695 \pstFP@@mul ll km mk \relax\pstFP@saveshift%
696 \pstFP@@mul kl lk \relax\pstFP@saveshift%
697 \pstFP@@mul kk \relax\pstFP@saveshift\pstFP@saveshift%
698 \pstFP@ninesplit\pstFP@rd%
699 \ifnum\pstFP@res=0\relax%
700 \pstFP@ninesplit\pstFP@rd%
701 \ifnum\pstFP@res=0\relax%
702 \pstFP@ninesplit\pstFP@rd\pstFP@ria=\pstFP@res%
703 \pstFP@ninesplit\pstFP@rd\pstFP@rib=\pstFP@res%
704 \pstFP@ninesplit\pstFP@rd\pstFP@rfa=\pstFP@res%
705 \pstFP@ninesplit\pstFP@rd\pstFP@rfb=\pstFP@res%
706 \pstFP@store\pstFP@tmp{r}%
707 \else\typeout{pstFPmul: Overflow}\fi%
708 \else\typeout{pstFPmul: Overflow}\fi%
709 \global\let\pstFP@tmp\pstFP@tmp}%
710 % \pstFPstripZeros\pstFP@tmp{#1}%
711 \let#1\pstFP@tmp
712 }
713 %
714 \catcode`\@=\PstAtCode\relax
715 %
716 %% END: pst-fp.tex
717 \endinput