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