-
Notifications
You must be signed in to change notification settings - Fork 0
/
524.f77
8260 lines (8256 loc) · 349 KB
/
524.f77
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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
C ABCDEFGHIJKLMNOPQRSTUVWXYZ$0123456789+-*/=(),. MP000011
C MP000021
C MP (VERSION 780802) MP000031
C ******************** MP000041
C MP000051
C $$ ****** COMMENTS ****** MP000061
C MP000071
C MP IS A MULTIPLE-PRECISION FLOATING-POINT ARITHMETIC PACKAGE. MP000081
C IT IS ALMOST COMPLETELY MACHINE-INDEPENDENT, AND SHOULD MP000091
C RUN ON ANY MACHINE WITH AN ANSI STANDARD FORTRAN COMPILER, MP000101
C SUFFICIENT MEMORY, AND A WORDLENGTH OF AT LEAST 16 BITS. MP000111
C MP000121
C FOR A GENERAL DESCRIPTION OF THE PHILOSOPHY AND DESIGN OF MP, MP000131
C SEE - R. P. BRENT, A FORTRAN MULTIPLE-PRECISION ARITHMETIC MP000141
C PACKAGE, ACM TRANS. MATH. SOFTWARE 4 (MARCH 1978), 57-70. MP000151
C SOME ADDITIONAL DETAILS ARE GIVEN IN THE SAME ISSUE, 71-81. MP000161
C FOR DETAILS OF THE IMPLEMENTATION, CALLING SEQUENCES ETC. SEE MP000171
C THE MP USERS GUIDE. MP000181
C MP000191
C MP IS NORMALLY DISTRIBUTED IN FIVE FILES. ALL HAVE 80 CHARACTER MP000201
C LOGICAL RECORDS AND USE ONLY THE (STANDARD FORTRAN) CHARACTERS MP000211
C APPEARING IN LINE MP000011. MP000221
C MP000231
C FILE 1 - THESE COMMENTS AND EXAMPLE PROGRAM. MP000241
C FILE 2 - MP SUBROUTINES (EXCLUDING EXAMPLE AND TEST PROGRAMS). MP000251
C FILE 3 - TEST PROGRAMS (NOT USING AUGMENT INTERFACE). MP000261
C FILE 4 - MP USERS GUIDE. MP000271
C FILE 5 - AUGMENT DESCRIPTION DECK AND JACOBI PROGRAM USING IT. MP000281
C (MP MAY BE USED WITH THE AUGMENT PREPROCESSOR. FOR MP000291
C DETAILS SEE SECTION 4 OF THE USERS GUIDE.) MP000301
C MP000311
C TO INSTALL MP, READ THESE FIVE FILES. PRINT FILE 4 (THE USERS GUIDE) MP000321
C USING THE FIRST CHARACTER (BLANK, 0 OR 1) AS STANDARD FORTRAN MP000331
C PRINTER CONTROL. THEN FOLLOW THE INSTRUCTIONS GIVEN IN SECTION 5 MP000341
C OF THE USERS GUIDE. MP000351
C MP000361
C MP000371
C MP000381
C $$ ****** EXAMPLE ****** MP005460
C MP005470
C THIS PROGRAM COMPUTES PI AND EXP(PI*SQRT(163/9)) TO 100 MP005480
C DECIMAL PLACES, AND EXP(PI*SQRT(163)) TO 90 DECIMAL PLACES, MP005490
C AND WRITES THEM ON LOGICAL UNIT 6. EXECUTION MP005500
C TIME ON A UNIVAC 1108 (WITH FORTRAN SE1D) IS 1.051 SECONDS. MP005510
C MP005520
C TO RUN EXAMPLE THE FOLLOWING MP ROUTINES ARE REQUIRED - MPABS, MP005530
C MPADD, MPADDI, MPADD2, MPADD3, MPART1, MPCHK, MPCIM, MPCLR, MPCMF, MP005540
C MPCMI, MPCMPR, MPCMR, MPCOMP, MPCQM, MPCRM, MPDIVI, MPERR, MP005550
C MPEXP, MPEXP1, MPGCD, MPLNI, MPL235, MPMAXR, MPMLP, MPMUL, MP005560
C MPMULI, MPMULQ, MPMUL2, MPNZR, MPOUT, MPOUT2, MPOVFL, MPPI, MP005570
C MPPWR, MPQPWR, MPREC, MPROOT, MPSET, MPSTR, MPSUB, MPUNFL. MP005580
C MP005590
C CORRECT OUTPUT (EXCLUDING HEADINGS) IS AS FOLLOWS MP005600
C MP005610
C 3.14159265358979323846264338327950288419716939937510 MP005620
C 58209749445923078164062862089986280348253421170680 MP005630
C 640320.00000000060486373504901603947174181881853947577148 MP005640
C 57603665918194652218258286942536340815822646477590 MP005650
C 262537412640768743.99999999999925007259719818568887935385633733699086 MP005660
C 2707537410378210647910118607312951181346 MP005670
C MP005680
C CERTAIN PARAMETERS AND WORKING SPACE IN COMMON. MP005690
COMMON B, T, M, LUN, MXR, R MP005700
C MP005710
C MPEXP REQUIRES 4T+10 WORDS AND WE HAVE T .LE. 62 IF WORDLENGTH MP005720
C AT LEAST 16 BITS, SO 4T+10 .LE. 258. DIMENSIONS CAN BE REDUCED MP005730
C IF WORDLENGTH IS GREATER THAN 16 BITS. MP005740
INTEGER B, T, R(258) MP005750
C MP005760
C VARIABLES NEED T+2 .LE. 64 WORDS AND ALLOW 110 CHARACTERS FOR MP005770
C DECIMAL OUTPUT MP005780
INTEGER PI(64), X(64), C(110) MP005790
C MP005800
C CALL MPSET TO SET OUTPUT LOGICAL UNIT = 6 AND EQUIVALENT MP005810
C NUMBER OF DECIMAL PLACES TO AT LEAST 110. THE LAST TWO MP005820
C PARAMETERS ARE THE DIMENSIONS OF PI (OR X) AND R. MP005830
CALL MPSET (6, 110, 64, 258) MP005840
C MP005850
C COMPUTE MULTIPLE-PRECISION PI MP005860
CALL MPPI(PI) MP005870
C MP005880
C CONVERT TO PRINTABLE FORMAT (F110.100) AND WRITE MP005890
CALL MPOUT (PI, C, 110, 100) MP005900
WRITE (LUN, 10) B, T, C MP005910
10 FORMAT (32H1EXAMPLE OF MP PACKAGE, BASE =, I9, MP005920
$ 12H, DIGITS =, I4 /// 11H PI TO 100D // MP005930
$ 11X, 60A1 / 21X, 50A1) MP005940
C MP005950
C SET X = SQRT(163/9), THEN MULTIPLY BY PI MP005960
CALL MPQPWR (163, 9, 1, 2, X) MP005970
CALL MPMUL (X, PI, X) MP005980
C MP005990
C SET X = EXP(X) MP006000
CALL MPEXP (X, X) MP006010
C MP006020
C CONVERT TO PRINTABLE FORMAT AND WRITE MP006030
CALL MPOUT (X, C, 110, 100) MP006040
WRITE (LUN, 20) C MP006050
20 FORMAT (/ 28H EXP(PI*SQRT(163/9)) TO 100D // MP006060
$ 11X, 60A1 / 21X, 50A1) MP006070
C MP006080
C SET X = X**3 = EXP(PI*SQRT(163)) MP006090
CALL MPPWR (X, 3, X) MP006100
C MP006110
C WRITE IN FORMAT F110.90 MP006120
CALL MPOUT (X, C, 110, 90) MP006130
WRITE (LUN, 30) C MP006140
30 FORMAT (/ 25H EXP(PI*SQRT(163)) TO 90D // MP006150
$ 1X, 70A1 / 21X, 40A1) MP006160
STOP MP006170
END MP006180
SUBROUTINE MPABS (X, Y) MP006200
C SETS Y = ABS(X) FOR MP NUMBERS X AND Y
INTEGER X(1), Y(1)
CALL MPSTR (X, Y)
Y(1) = IABS(Y(1))
RETURN
END
SUBROUTINE MPADD (X, Y, Z) MP006280
C ADDS X AND Y, FORMING RESULT IN Z, WHERE X, Y AND Z ARE MP
C NUMBERS. FOUR GUARD DIGITS ARE USED, AND THEN R*-ROUNDING.
INTEGER X(1), Y(1), Z(1)
CALL MPADD2 (X, Y, Z, Y, 0)
RETURN
END
SUBROUTINE MPADDI (X, IY, Z) MP006360
C ADDS MULTIPLE-PRECISION X TO INTEGER IY
C GIVING MULTIPLE-PRECISION Z.
C DIMENSION OF R IN CALLING PROGRAM MUST BE
C AT LEAST 2T+6 (BUT Z(1) MAY BE R(T+5)).
COMMON B, T, M, LUN, MXR, R
C DIMENSION R(6) BECAUSE RALPH COMPILER ON UNIVAC 1100 COMPUTERS
C OBJECTS TO DIMENSION R(1).
INTEGER B, T, R(6), X(1), Z(1)
C CHECK LEGALITY OF B, T, M, LUN AND MXR
CALL MPCHK (2, 6)
CALL MPCIM (IY, R(T+5))
CALL MPADD (X, R(T+5), Z)
RETURN
END
SUBROUTINE MPADDQ (X, I, J, Y) MP006520
C ADDS THE RATIONAL NUMBER I/J TO MP NUMBER X, MP RESULT IN Y
C DIMENSION OF R MUST BE AT LEAST 2T+6
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(6), X(1), Y(1)
C CHECK LEGALITY OF B, T, M, LUN AND MXR
CALL MPCHK (2, 6)
CALL MPCQM (I, J, R(T+5))
CALL MPADD (X, R(T+5), Y)
RETURN
END
SUBROUTINE MPADD2 (X, Y, Z, Y1, TRUNC) MP006640
C CALLED BY MPADD, MPSUB ETC.
C X, Y AND Z ARE MP NUMBERS, Y1 AND TRUNC ARE INTEGERS.
C TO FORCE CALL BY REFERENCE RATHER THAN VALUE/RESULT, Y1 IS
C DECLARED AS AN ARRAY, BUT ONLY Y1(1) IS EVER USED.
C SETS Z = X + Y1(1)*ABS(Y), WHERE Y1(1) = +- Y(1).
C IF TRUNC.EQ.0 R*-ROUNDING IS USED, OTHERWISE TRUNCATION.
C R*-ROUNDING IS DEFINED IN KUKI AND CODI, COMM. ACM
C 16(1973), 223. (SEE ALSO BRENT, IEEE TC-22(1973), 601.)
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(2), Y(2), Z(1), Y1(1), TRUNC
INTEGER S, ED, RS, RE
C CHECK FOR X OR Y ZERO
IF (X(1).NE.0) GO TO 20
C X = 0 OR NEGLIGIBLE, SO RESULT = +-Y
10 CALL MPSTR(Y, Z)
Z(1) = Y1(1)
RETURN
20 IF (Y1(1).NE.0) GO TO 40
C Y = 0 OR NEGLIGIBLE, SO RESULT = X
30 CALL MPSTR (X, Z)
RETURN
C COMPARE SIGNS
40 S = X(1)*Y1(1)
IF (IABS(S).LE.1) GO TO 60
CALL MPCHK (1, 4)
WRITE (LUN, 50)
50 FORMAT (44H *** SIGN NOT 0, +1 OR -1 IN CALL TO MPADD2,,
$ 33H POSSIBLE OVERWRITING PROBLEM ***)
CALL MPERR
Z(1) = 0
RETURN
C COMPARE EXPONENTS
60 ED = X(2) - Y(2)
MED = IABS(ED)
IF (ED) 90, 70, 120
C EXPONENTS EQUAL SO COMPARE SIGNS, THEN FRACTIONS IF NEC.
70 IF (S.GT.0) GO TO 100
DO 80 J = 1, T
IF (X(J+2) - Y(J+2)) 100, 80, 130
80 CONTINUE
C RESULT IS ZERO
Z(1) = 0
RETURN
C HERE EXPONENT(Y) .GE. EXPONENT(X)
90 IF (MED.GT.T) GO TO 10
100 RS = Y1(1)
RE = Y(2)
CALL MPADD3 (X, Y, S, MED, RE)
C NORMALIZE, ROUND OR TRUNCATE, AND RETURN
110 CALL MPNZR (RS, RE, Z, TRUNC)
RETURN
C ABS(X) .GT. ABS(Y)
120 IF (MED.GT.T) GO TO 30
130 RS = X(1)
RE = X(2)
CALL MPADD3 (Y, X, S, MED, RE)
GO TO 110
END
SUBROUTINE MPADD3 (X, Y, S, MED, RE) MP007240
C CALLED BY MPADD2, DOES INNER LOOPS OF ADDITION
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(1), Y(1), S, RE, C, TED
TED = T + MED
I2 = T + 4
I = I2
C = 0
C CLEAR GUARD DIGITS TO RIGHT OF X DIGITS
10 IF (I.LE.TED) GO TO 20
R(I) = 0
I = I - 1
GO TO 10
20 IF (S.LT.0) GO TO 130
C HERE DO ADDITION, EXPONENT(Y) .GE. EXPONENT(X)
IF (I.LE.T) GO TO 40
30 J = I - MED
R(I) = X(J+2)
I = I - 1
IF (I.GT.T) GO TO 30
40 IF (I.LE.MED) GO TO 60
J = I - MED
C = Y(I+2) + X(J+2) + C
IF (C.LT.B) GO TO 50
C CARRY GENERATED HERE
R(I) = C - B
C = 1
I = I - 1
GO TO 40
C NO CARRY GENERATED HERE
50 R(I) = C
C = 0
I = I - 1
GO TO 40
60 IF (I.LE.0) GO TO 90
C = Y(I+2) + C
IF (C.LT.B) GO TO 70
R(I) = 0
C = 1
I = I - 1
GO TO 60
70 R(I) = C
I = I - 1
C NO CARRY POSSIBLE HERE
80 IF (I.LE.0) RETURN
R(I) = Y(I+2)
I = I - 1
GO TO 80
90 IF (C.EQ.0) RETURN
C MUST SHIFT RIGHT HERE AS CARRY OFF END
I2P = I2 + 1
DO 100 J = 2, I2
I = I2P - J
100 R(I+1) = R(I)
R(1) = 1
RE = RE + 1
RETURN
C HERE DO SUBTRACTION, ABS(Y) .GT. ABS(X)
110 J = I - MED
R(I) = C - X(J+2)
C = 0
IF (R(I).GE.0) GO TO 120
C BORROW GENERATED HERE
C = -1
R(I) = R(I) + B
120 I = I - 1
130 IF (I.GT.T) GO TO 110
140 IF (I.LE.MED) GO TO 160
J = I - MED
C = Y(I+2) + C - X(J+2)
IF (C.GE.0) GO TO 150
C BORROW GENERATED HERE
R(I) = C + B
C = -1
I = I - 1
GO TO 140
C NO BORROW GENERATED HERE
150 R(I) = C
C = 0
I = I - 1
GO TO 140
160 IF (I.LE.0) RETURN
C = Y(I+2) + C
IF (C.GE.0) GO TO 70
R(I) = C + B
C = -1
I = I - 1
GO TO 160
END
SUBROUTINE MPART1 (N, Y) MP008140
C COMPUTES MP Y = ARCTAN(1/N), ASSUMING INTEGER N .GT. 1.
C USES SERIES ARCTAN(X) = X - X**3/3 + X**5/5 - ...
C DIMENSION OF R IN CALLING PROGRAM MUST BE
C AT LEAST 2T+6
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), Y(2), B2, TS
C CHECK LEGALITY OF B, T, M, MXR AND LUN
CALL MPCHK (2, 6)
IF (N.GT.1) GO TO 20
WRITE (LUN, 10)
10 FORMAT (35H *** N .LE. 1 IN CALL TO MPART1 ***)
CALL MPERR
Y(1) = 0
RETURN
20 I2 = T + 5
TS = T
C SET SUM TO X = 1/N
CALL MPCQM (1, N, Y)
C SET ADDITIVE TERM TO X
CALL MPSTR (Y, R(I2))
I = 1
ID = 0
C ASSUME AT LEAST 16-BIT WORD.
B2 = MAX0 (B, 64)
IF (N.LT.B2) ID = (7*B2*B2)/(N*N)
C MAIN LOOP. FIRST REDUCE T IF POSSIBLE
30 T = TS + 2 + R(I2+1) - Y(2)
IF (T.LT.2) GO TO 60
T = MIN0 (T, TS)
C IF (I+2)*N**2 IS NOT REPRESENTABLE AS AN INTEGER THE DIVISION
C FOLLOWING HAS TO BE PERFORMED IN SEVERAL STEPS.
IF (I.GE.ID) GO TO 40
CALL MPMULQ (R(I2), -I, (I+2)*N*N, R(I2))
GO TO 50
40 CALL MPMULQ (R(I2), -I, I+2, R(I2))
CALL MPDIVI (R(I2), N, R(I2))
CALL MPDIVI (R(I2), N, R(I2))
50 I = I + 2
C RESTORE T
T = TS
C ADD TO SUM, USING MPADD2 (FASTER THAN MPADD)
CALL MPADD2 (R(I2), Y, Y, Y, 0)
IF (R(I2).NE.0) GO TO 30
60 T = TS
RETURN
END
SUBROUTINE MPASIN (X, Y) MP008620
C RETURNS Y = ARCSIN(X), ASSUMING ABS(X) .LE. 1,
C FOR MP NUMBERS X AND Y.
C Y IS IN THE RANGE -PI/2 TO +PI/2.
C METHOD IS TO USE MPATAN, SO TIME IS O(M(T)T).
C DIMENSION OF R MUST BE AT LEAST 5T+12
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(2), Y(1)
C CHECK LEGALITY OF B, T, M, MXR AND LUN
CALL MPCHK (5, 12)
I3 = 4*T + 11
IF (X(1).EQ.0) GO TO 30
IF (X(2).LE.0) GO TO 40
C HERE ABS(X) .GE. 1. SEE IF X = +-1
CALL MPCIM (X(1), R(I3))
IF (MPCOMP(X, R(I3)).NE.0) GO TO 10
C X = +-1 SO RETURN +-PI/2
CALL MPPI (Y)
CALL MPDIVI (Y, 2*R(I3), Y)
RETURN
10 WRITE (LUN, 20)
20 FORMAT (40H *** ABS(X) .GT. 1 IN CALL TO MPASIN ***)
CALL MPERR
30 Y(1) = 0
RETURN
C HERE ABS(X) .LT. 1 SO USE ARCTAN(X/SQRT(1 - X**2))
40 I2 = I3 - (T+2)
CALL MPCIM (1, R(I2))
CALL MPSTR (R(I2), R(I3))
CALL MPSUB (R(I2), X, R(I2))
CALL MPADD (R(I3), X, R(I3))
CALL MPMUL (R(I2), R(I3), R(I3))
CALL MPROOT (R(I3), -2, R(I3))
CALL MPMUL (X, R(I3), Y)
CALL MPATAN (Y, Y)
RETURN
END
SUBROUTINE MPATAN (X, Y) MP008996
C RETURNS Y = ARCTAN(X) FOR MP X AND Y, USING AN O(T.M(T)) METHOD
C WHICH COULD EASILY BE MODIFIED TO AN O(SQRT(T)M(T))
C METHOD (AS IN MPEXP1). Y IS IN THE RANGE -PI/2 TO +PI/2.
C FOR AN ASYMPTOTICALLY FASTER METHOD, SEE - FAST MULTIPLE-
C PRECISION EVALUATION OF ELEMENTARY FUNCTIONS
C (BY R. P. BRENT), J. ACM 23 (1976), 242-251,
C AND THE COMMENTS IN MPPIGL.
C DIMENSION OF R IN CALLING PROGRAM MUST BE AT LEAST 5T+12
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(2), Y(1), Q, TS
C CHECK LEGALITY OF B, T, M, MXR AND LUN
CALL MPCHK (5, 12)
I2 = 3*T + 9
I3 = I2 + T + 2
IF (X(1).NE.0) GO TO 10
Y(1) = 0
RETURN
10 CALL MPSTR (X, R(I3))
IE = IABS(X(2))
IF (IE.LE.2) CALL MPCMR (X, RX)
Q = 1
C REDUCE ARGUMENT IF NECESSARY BEFORE USING SERIES
20 IF (R(I3+1).LT.0) GO TO 30
IF ((R(I3+1).EQ.0).AND.((2*(R(I3+2)+1)).LE.B)) GO TO 30
Q = 2*Q
CALL MPMUL (R(I3), R(I3), Y)
CALL MPADDI (Y, 1, Y)
CALL MPSQRT (Y, Y)
CALL MPADDI (Y, 1, Y)
CALL MPDIV (R(I3), Y, R(I3))
GO TO 20
C USE POWER SERIES NOW ARGUMENT IN (-0.5, 0.5)
30 CALL MPSTR (R(I3), Y)
CALL MPMUL (R(I3), R(I3), R(I2))
I = 1
TS = T
C SERIES LOOP. REDUCE T IF POSSIBLE.
40 T = TS + 2 + R(I3+1)
IF (T.LE.2) GO TO 50
T = MIN0 (T, TS)
CALL MPMUL (R(I3), R(I2), R(I3))
CALL MPMULQ (R(I3), -I, I+2, R(I3))
I = I + 2
T = TS
CALL MPADD (Y, R(I3), Y)
IF (R(I3).NE.0) GO TO 40
C RESTORE T, CORRECT FOR ARGUMENT REDUCTION, AND EXIT
50 T = TS
CALL MPMULI (Y, Q, Y)
C CHECK THAT RELATIVE ERROR LESS THAN 0.01 UNLESS EXPONENT
C OF X IS LARGE (WHEN ATAN MIGHT NOT WORK)
IF (IE.GT.2) RETURN
CALL MPCMR (Y, RY)
IF (ABS(RY - ATAN(RX)) .LT. (0.01*ABS(RY))) RETURN
WRITE (LUN, 60)
C THE FOLLOWING MESSAGE MAY INDICATE THAT B**(T-1) IS TOO SMALL.
60 FORMAT (51H *** ERROR OCCURRED IN MPATAN, RESULT INCORRECT ***)
CALL MPERR
RETURN
END
FUNCTION MPBASA (X) MP009553
C RETURNS THE MP BASE (FIRST WORD IN COMMON).
C X IS A DUMMY MP ARGUMENT.
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(1)
MPBASA = B
RETURN
END
SUBROUTINE MPBASB (I, X) MP009573
C SETS THE MP BASE (FIRST WORD OF COMMON) TO I.
C I SHOULD BE AN INTEGER SUCH THAT I .GE. 2
C AND (8*I*I-1) IS REPRESENTABLE AS A SINGLE-PRECISION INTEGER.
C X IS A DUMMY MP ARGUMENT (AUGMENT EXPECTS ONE).
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(1)
C SET BASE TO I, THEN CHECK VALIDITY
B = I
CALL MPCHK (1, 4)
RETURN
END
SUBROUTINE MPBERN (N, P, X) MP009620
C COMPUTES THE BERNOULLI NUMBERS B2 = 1/6, B4 = -1/30,
C B6 = 1/42, B8 = -1/30, B10 = 5/66, B12 = -691/2730, ETC.,
C DEFINED BY THE GENERATING FUNCTION Y/(EXP(Y)-1).
C N AND P ARE SINGLE-PRECISION INTEGERS, WITH 2*P .GE. T+2.
C X SHOULD BE A ONE-DIMENSIONAL INTEGER ARRAY OF DIMENSION AT
C LEAST P*N. THE BERNOULLI NUMBERS B2, B4, ... , B(2N) ARE
C RETURNED IN PACKED FORMAT IN X, WITH B(2J) IN LOCATIONS
C X((J-1)*P+1), ... , X(P*J). THUS, TO GET B(2J) IN USUAL
C MP FORMAT IN Y, ONE SHOULD CALL MPUNPK (X(IX), Y) AFTER
C CALLING MPBERN, WHERE IX = (J-1)*P+1.
C
C ALTERNATIVELY (SIMPLER BUT NONSTANDARD) -
C X MAY BE A TWO-DIMENSIONAL INTEGER ARRAY DECLARED WITH
C DIMENSION (P, N1), WHERE N1 .GE. N AND 2*P .GE. T+2.
C THEN B2, B4, ... , B(2N) ARE RETURNED IN PACKED FORMAT IN
C X, WITH B(2J) IN X(1,J), ... , X(P,J). THUS, TO GET
C B(2J) IN USUAL MP FORMAT IN Y ONE SHOULD
C CALL MPUNPK (X(1, J), Y) AFTER CALLING MPBERN.
C
C THE WELL-KNOWN RECURRENCE IS UNSTABLE (LOSING ABOUT 2J BITS
C OF RELATIVE ACCURACY IN THE COMPUTED B(2J)), SO WE USE A
C DIFFERENT RECURRENCE DERIVED BY EQUATING COEFFICIENTS IN
C (EXP(Y)+1)*(2Y/(EXP(2Y)-1)) = 2*(Y/(EXP(Y)-1)). THE RELATION
C B(2J) = -2*((-1)**J)*FACTORIAL(2J)*ZETA(2J)/((2PI)**(2J))
C IS USED IF ZETA(2J) IS EQUAL TO 1 TO WORKING ACCURACY.
C A DIFFERENT METHOD IS GIVEN BY KNUTH AND BUCKHOLTZ IN
C MATH. COMP. 21 (1967), 663-688.
C THE RELATIVE ERROR IN B(2J) IS O((J**2)*(B**(1-T))).
C TIME IS O(T*(MIN(N, T)**2) + N*M(T)), SPACE = 8T+18.
COMMON B, T, M, LUN, MXR, R
INTEGER B, B2, T, R(1), P, X(1)
IF (N.LE.0) RETURN
C CHECK LEGALITY OF B, T, M, LUN AND MXR
CALL MPCHK (8, 18)
IF ((2*P).GE.(T+2)) GO TO 20
WRITE (LUN, 10)
10 FORMAT (38H *** P TOO SMALL IN CALL TO MPBERN ***)
CALL MPERR
RETURN
20 I2 = 4*T + 11
I3 = I2 + T + 2
I4 = I3 + T + 2
I5 = I4 + T + 2
B2 = MAX0 (B/2, 32)
C COMPUTE UPPER LIMIT FOR RECURRENCE RELATION METHOD.
N2 = MIN0 (N, INT(0.5E0+ALOG(FLOAT(B))*FLOAT(T)/ALOG(4E0)))
C SET ALL RESULTS TO ZERO
DO 30 I = 1, N2
IX = (I-1)*P + 2
30 X(IX) = 0
CALL MPCQM (1, 8, R(I2))
CALL MPSTR (R(I2), R(I3))
CALL MPCIM (-1, R(I5))
C MAIN LOOP TO GENERATE SCALED BERNOULLI NUMBERS
DO 70 J = 1, N2
CALL MPDIVI (R(I3), 2, R(I3))
CALL MPDIVI (R(I5), 4, R(I5))
CALL MPADDI (R(I5), 1, R(I4))
CALL MPDIV (R(I3), R(I4), R(I3))
IX = (J-1)*P + 1
CALL MPPACK (R(I3), X(IX))
IF (J.GE.N2) GO TO 80
CALL MPDIVI (R(I2), 4*J-2, R(I2))
CALL MPDIVI (R(I2), 4*J+4, R(I2))
CALL MPSTR (R(I2), R(I3))
DO 60 I = 1, J
IX = (I-1)*P + 1
CALL MPUNPK (X(IX), R(I4))
IF ((J-I).GE.B2) GO TO 40
CALL MPDIVI (R(I4), 8*(2*(J-I)+1)*(J+1-I), R(I4))
GO TO 50
C HERE SPLIT UP IN CASE WOULD GET OVERFLOW IN ONE CALL TO MPDIVI
40 CALL MPDIVI (R(I4), 4*(J+1-I), R(I4))
CALL MPDIVI (R(I4), 4*(J-I)+2, R(I4))
50 CALL MPPACK (R(I4), X(IX))
60 CALL MPSUB (R(I3), R(I4), R(I3))
70 CONTINUE
C NOW UNSCALE RESULTS
80 CALL MPCIM (1, R(I2))
IF (N2.LE.1) GO TO 100
I = N2
90 CALL MPMULI (R(I2), (4*(N2-I)+4), R(I2))
CALL MPMULI (R(I2), (4*(N2-I)+2), R(I2))
I = I - 1
IX = (I-1)*P + 1
CALL MPUNPK (X(IX), R(I4))
CALL MPMUL (R(I2), R(I4), R(I4))
CALL MPPACK (R(I4), X(IX))
IF (I.GT.1) GO TO 90
C NOW HAVE B(2J)/FACTORIAL(2J) IN X
CALL MPCIM (1, R(I2))
100 DO 110 I = 1, N2
CALL MPMULI (R(I2), 2*I-1, R(I2))
CALL MPMULI (R(I2), 2*I, R(I2))
IX = (I-1)*P + 1
CALL MPUNPK (X(IX), R(I4))
CALL MPMUL (R(I2), R(I4), R(I4))
110 CALL MPPACK (R(I4), X(IX))
C RETURN IF FINISHED
IF (N.LE.N2) RETURN
C ELSE COMPUTE REMAINING NUMBERS
CALL MPPI (R(I3))
CALL MPPWR (R(I3), -2, R(I3))
CALL MPDIVI (R(I3), -4, R(I3))
N2 = N2 + 1
DO 120 I = N2, N
CALL MPMUL (R(I4), R(I3), R(I4))
CALL MPMULI (R(I4), 2*I-1, R(I4))
CALL MPMULI (R(I4), 2*I, R(I4))
IX = (I-1)*P + 1
120 CALL MPPACK (R(I4), X(IX))
RETURN
END
SUBROUTINE MPBESJ (X, NU, Y) MP010770
C RETURNS Y = J(NU,X), THE FIRST-KIND BESSEL FUNCTION OF ORDER NU,
C FOR SMALL INTEGER NU, MP X AND Y. ABS(NU) MUST BE
C .LE. MAX(B, 64). METHOD IS HANKELS ASYMPTOTIC EXPANSION IF
C ABS(X) LARGE, THE POWER SERIES IF ABS(X) SMALL, AND THE
C BACKWARD RECURRENCE METHOD OTHERWISE.
C RESULTS FOR NEGATIVE ARGUMENTS ARE DEFINED BY
C J(-NU,X) = J(NU,-X) = ((-1)**NU)*J(NU,X).
C ERROR COULD BE INDUCED BY O(B**(1-T)) PERTURBATIONS
C IN X AND Y. TIME IS O(T.M(T)) FOR FIXED X AND NU, INCREASES
C AS X AND NU INCREASE, UNLESS X LARGE ENOUGH FOR ASYMPTOTIC
C SERIES TO BE USED. SPACE = 14T+156
COMMON B, T, M, LUN, MXR, R
INTEGER B, B2, T, R(1), X(2), Y(1), TS, TS2, TM, ERROR
C CHECK LEGALITY OF B, T, M, LUN AND MXR
CALL MPCHK (14, 156)
TS = T
B2 = MAX0 (B, 64)
NUA = IABS(NU)
C CHECK THAT ABS(NU) IS .LE. MAX(B, 64). THIS RESTRICTION
C ENSURES THAT 4*(NU**2) IS REPRESENTABLE AS AN INTEGER.
IF (NUA.LE.B2) GO TO 20
WRITE (LUN, 10)
10 FORMAT (44H *** ABS(NU) TOO LARGE IN CALL TO MPBESJ ***)
GO TO 120
C CHECK FOR X ZERO
20 IF (X(1).NE.0) GO TO 30
C J(NU,0) = 0 IF NU .EQ. 0, 1 IF NU .NE. 0
Y(1) = 0
IF (NU.EQ.0) CALL MPCIM (1, Y)
RETURN
C SEE IF ABS(X) SO LARGE THAT NO ACCURACY POSSIBLE
30 IF (X(2).GE.T) GO TO 100
C X NONZERO SO TRY HANKEL ASYMPTOTIC SERIES WITH ONE GUARD DIGIT
I2 = 11*T + 36
CALL MPCLR (R(I2), T+1)
CALL MPSTR (X, R(I2))
T = T + 1
CALL MPHANK (R(I2), NUA, R(I2), ERROR)
T = TS
CALL MPSTR (R(I2), Y)
C RETURN IF ASYMPTOTIC SERIES WAS ACCURATE ENOUGH
IF (ERROR.EQ.0) GO TO 90
C ASYMPTOTIC SERIES INADEQUATE HERE, SO USE POWER SERIES
C MAY NEED TO INCREASE T LATER SO PREPARE FOR THIS
C MAX ALLOWABLE T IS APPROXIMATELY DOUBLE
TM = 2*T + 20
I2 = 4*TM + 11
I3 = I2 + TM + 2
I4 = I3 + TM + 2
C ZERO TRAILING DIGITS OF R(I2) AND R(I4)
CALL MPCLR (R(I2), TM)
CALL MPCLR (R(I4), TM)
TS2 = T
C NO APPRECIABLE CANCELLATION IN POWER SERIES IF ABS(X) .LT. 1
IF (X(2).LE.0) GO TO 40
C SHOULD BE OK TO CONVERT TO REAL HERE AS X NOT TOO LARGE OR SMALL.
CALL MPCMR (X, RX)
C ESTIMATE NUMBER OF DIGITS REQUIRED TO COMPENSATE FOR CANCELLATION
TS2 = MAX0 (TS, T + 1 + INT((ABS(RX)+(FLOAT(NUA)+0.5E0)*
$ ALOG(0.5E0*ABS(RX)))/ALOG(FLOAT(B))))
C IF NEED MORE DIGITS THAN SPACE ALLOWS FOR POWER SERIES THEN
C USE RECURRENCE METHOD INSTEAD
IF (TS2.GT.TM) GO TO 130
C PREPARE FOR POWER SERIES LOOP
40 CALL MPDIVI (X, 2, R(I4))
CALL MPPWR (R(I4), NUA, R(I4))
CALL MPGAMQ (NUA+1, 1, R(I3))
CALL MPDIV (R(I4), R(I3), R(I4))
CALL MPMUL (X, X, R(I2))
CALL MPDIVI (R(I2), -4, R(I2))
T = TS2
CALL MPSTR (R(I4), R(I3))
IE = R(I3+1)
K = 0
C POWER SERIES LOOP, REDUCE T IF POSSIBLE
50 T = MIN0 (TS2, TS2 + 2 + R(I4+1) - IE)
IF (T.LT.2) GO TO 80
CALL MPMUL (R(I2), R(I4), R(I4))
K = K + 1
C MAY NEED TO SPLIT UP CALL TO MPDIVI
IF (K.GT.B2) GO TO 60
CALL MPDIVI (R(I4), K*(K+NUA), R(I4))
GO TO 70
C HERE IT IS SPLIT UP TO AVOID OVERFLOW
60 CALL MPDIVI (R(I4), K, R(I4))
CALL MPDIVI (R(I4), K+NUA, R(I4))
C RESTORE T FOR ADDITION
70 T = TS2
CALL MPADD (R(I3), R(I4), R(I3))
IF ((R(I4).NE.0).AND.(R(I4+1).GE.(R(I3+1)-TS))) GO TO 50
C RESTORE T AND MOVE FINAL RESULT
80 T = TS
CALL MPSTR (R(I3), Y)
C CORRECT SIGN IF NU ODD AND NEGATIVE
90 IF ((NU.LT.0).AND.(MOD(NUA,2).NE.0)) Y(1) = -Y(1)
RETURN
C HERE ABS(X) SO LARGE THAT NO SIGNIFICANT DIGITS COULD BE
C GUARANTEED
100 WRITE (LUN, 110)
110 FORMAT (43H *** ABS(X) TOO LARGE IN CALL TO MPBESJ ***)
120 CALL MPERR
T = TS
Y(1) = 0
RETURN
C HERE USE BACKWARD RECURRENCE METHOD WITH TWO GUARD DIGITS
130 CALL MPABS (X, R(I4))
T = T + 2
CALL MPBES2 (R(I4), NUA, R(I3))
C CORRECT SIGN IF NUA ODD
IF (MOD (NUA,2) .NE. 0) R(I3) = X(1)*R(I3)
GO TO 80
END
SUBROUTINE MPBES2 (X, NU, Y) MP011906
C USES THE BACKWARD RECURRENCE METHOD TO EVALUATE Y = J(NU,X),
C WHERE X AND Y ARE MP NUMBERS, NU (THE INDEX) IS AN INTEGER,
C AND J IS THE BESSEL FUNCTION OF THE FIRST KIND. ASSUMES THAT
C 0 .LE. NU .LE. MAX(B,64) AND X .GT. 0. ALSO ASSUMED THAT X
C CAN BE CONVERTED TO REAL WITHOUT FLOATING-POINT OVERFLOW OR
C UNDERFLOW. FOR NORMALIZATION THE IDENTITY
C J(0,X) + 2*J(2,X) + 2*J(4,X) + ... = 1 IS USED.
C CALLED BY MPBESJ AND NOT RECOMMENDED FOR INDEPENDENT USE.
C SPACE = 8T+18
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(1), Y(1)
C CHECK LEGALITY OF B, T, M, LUN AND MXR
CALL MPCHK (8, 18)
C CHECK LEGALITY OF NU AND X
IF ((NU.GE.0).AND.(NU.LE.MAX0(B,64)).AND.(X(1).EQ.1)) GO TO 20
WRITE (LUN, 10)
10 FORMAT (50H *** NU .LT. 0 OR NU TOO LARGE OR X .LE. 0 IN CALL,
$ 14H TO MPBES2 ***)
CALL MPERR
Y(1) = 0
RETURN
C ASSUME CONVERSION TO REAL IS POSSIBLE WITHOUT OVERFLOW (TRUE
C WHEN CALLED BY MPBESJ ELSE MPHANK OR POWER SERIES WOULD BE USED).
20 CALL MPCMR (X, RX)
C COMPUTE STARTING POINT NU1 FOR BACKWARD RECURRENCE
FLNU = FLOAT (MAX0 (1, NU))
RY = AMAX1 (1E0, ALOG(2E0*FLNU/RX) - 1E0)
C 1.35914 IS E/2 ROUNDED DOWN, 1.35915 IS E/2 ROUNDED UP
RY = (FLNU*RY + 0.5E0*FLOAT(T)*ALOG(FLOAT(B)))/(1.35914E0*RX)
RY = AMAX1 (2E0, RY)
RT = RY
C ITERATE AN EVEN NUMBER OF TIMES TO OVERESTIMATE NU1
DO 30 I = 1, 4
30 RT = AMAX1 (2E0, RY/ALOG(RT))
NU1 = 2 + INT(1.35915E0*RX*RT)
I2 = 3*T + 9
I3 = I2 + T + 2
I4 = I3 + T + 2
I5 = I4 + T + 2
I6 = I5 + T + 2
CALL MPCIM (MOD(NU1+1,2), R(I6))
CALL MPREC (X, R(I2))
CALL MPMULI (R(I2), 2, R(I2))
R(I3) = 0
CALL MPCIM (1, R(I4))
C BACKWARD RECURRENCE LOOP
40 CALL MPMUL (R(I4), R(I2), R(I5))
CALL MPMULI (R(I5), NU1, R(I5))
CALL MPSUB (R(I5), R(I3), R(I5))
NU1 = NU1 - 1
C FASTER TO INTERCHANGE POINTERS THAN MP NUMBERS
I3S = I3
I3 = I4
I4 = I5
I5 = I3S
IF (MOD(NU1,2) .NE. 0) GO TO 50
C NU1 EVEN SO UPDATE NORMALIZING SUM
IF (NU1.EQ.0) CALL MPMULI (R(I6), 2, R(I6))
CALL MPADD (R(I6), R(I4), R(I6))
C SAVE UNNORMALIZED RESULT IF NU1 .EQ. NU
50 IF (NU1.EQ.NU) CALL MPSTR (R(I4), Y)
IF (NU1.GT.0) GO TO 40
C NORMALIZE RESULT AND RETURN
CALL MPDIV (Y, R(I6), Y)
RETURN
END
SUBROUTINE MPCAM (A, X) MP012493
C CONVERTS THE HOLLERITH STRING A TO AN MP NUMBER X.
C A CAN BE A STRING OF DIGITS ACCEPTABLE TO ROUTINE MPIN
C AND TERMINATED BY A DOLLAR ($), E.G. 7H-5.367$,
C OR ONE OF THE FOLLOWING SPECIAL STRINGS -
C EPS (MP MACHINE-PRECISION, SEE MPEPS),
C EUL (EULERS CONSTANT 0.5772..., SEE MPEUL),
C MAXR (LARGEST VALID MP NUMBER, SEE MPMAXR),
C MINR (SMALLEST POSTIVE MP NUMBER, SEE MPMINR),
C PI (PI = 3.14..., SEE MPPI).
C ONLY THE FIRST TWO CHARACTERS OF THESE STRINGS ARE CHECKED.
C SPACE REQUIRED IS NO MORE THAN 5*T+L+14, WHERE L IS THE
C NUMBER OF CHARACTERS IN THE STRING A (EXCLUDING $).
C IF SPACE IS LESS 3*T+L+11 THE STRING A WILL EFFECTIVELY BE TRUNCATED
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), A(1), X(1), ERROR, C(6), D(2)
DATA C(1) /1HA/, C(2) /1HE/, C(3) /1HI/
DATA C(4) /1HM/, C(5) /1HP/, C(6) /1HU/
C UNPACK FIRST 2 CHARACTERS OF A
CALL MPUPK (A, D, 2, N)
IF (N.NE.2) GO TO 10
C SET X TO ZERO AFTER SAVING A(1) IN CASE A AND X COINCIDE
I = A(1)
X(1) = 0
C CHECK FOR SPECIAL STRINGS
IF ((D(1).EQ.C(2)).AND.(D(2).EQ.C(5))) CALL MPEPS (X)
IF ((D(1).EQ.C(2)).AND.(D(2).EQ.C(6))) CALL MPEUL (X)
IF ((D(1).EQ.C(4)).AND.(D(2).EQ.C(1))) CALL MPMAXR (X)
IF ((D(1).EQ.C(4)).AND.(D(2).EQ.C(3))) CALL MPMINR (X)
IF ((D(1).EQ.C(5)).AND.(D(2).EQ.C(3))) CALL MPPI (X)
C RETURN IF X NONZERO (SO ONE OF ABOVE TESTS SUCCEEDED)
IF (X(1).NE.0) RETURN
C RESTORE A(1) AND UNPACK, THEN CALL MPIN TO DECODE.
A(1) = I
10 I2 = 3*T + 12
CALL MPUPK (A, R(I2), MXR+1-I2, N)
CALL MPIN (R(I2), X, N, ERROR)
IF (ERROR.EQ.0) RETURN
WRITE (LUN, 20)
20 FORMAT (53H *** ERROR IN HOLLERITH CONSTANT IN CALL TO MPCAM ***)
CALL MPERR
RETURN
END
SUBROUTINE MPCDM (DX, Z) MP012590
C CONVERTS DOUBLE-PRECISION NUMBER DX TO MULTIPLE-PRECISION Z.
C SOME NUMBERS WILL NOT CONVERT EXACTLY ON MACHINES
C WITH BASE OTHER THAN TWO, FOUR OR SIXTEEN.
C THIS ROUTINE IS NOT CALLED BY ANY OTHER ROUTINE IN MP,
C SO MAY BE OMITTED IF DOUBLE-PRECISION IS NOT AVAILABLE.
DOUBLE PRECISION DB, DJ, DX, DBLE
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), Z(1), RS, RE, TP
C CHECK LEGALITY OF B, T, M, MXR AND LUN
CALL MPCHK (1, 4)
I2 = T + 4
C CHECK SIGN
IF (DX) 20, 10, 30
C IF DX = 0D0 RETURN 0
10 Z(1) = 0
RETURN
C DX .LT. 0D0
20 RS = -1
DJ = -DX
GO TO 40
C DX .GT. 0D0
30 RS = 1
DJ = DX
40 IE = 0
50 IF (DJ.LT.1D0) GO TO 60
C INCREASE IE AND DIVIDE DJ BY 16.
IE = IE + 1
DJ = 0.0625D0*DJ
GO TO 50
60 IF (DJ.GE.0.0625D0) GO TO 70
IE = IE - 1
DJ = 16D0*DJ
GO TO 60
C NOW DJ IS DY DIVIDED BY SUITABLE POWER OF 16
C SET EXPONENT TO 0
70 RE = 0
C DB = DFLOAT(B) IS NOT ANSI STANDARD SO USE FLOAT AND DBLE
DB = DBLE(FLOAT(B))
C CONVERSION LOOP (ASSUME DOUBLE-PRECISION OPS. EXACT)
DO 80 I = 1, I2
DJ = DB*DJ
R(I) = IDINT(DJ)
80 DJ = DJ - DBLE(FLOAT(R(I)))
C NORMALIZE RESULT
CALL MPNZR (RS, RE, Z, 0)
IB = MAX0(7*B*B, 32767)/16
TP = 1
C NOW MULTIPLY BY 16**IE
IF (IE) 90, 130, 110
90 K = -IE
DO 100 I = 1, K
TP = 16*TP
IF ((TP.LE.IB).AND.(TP.NE.B).AND.(I.LT.K)) GO TO 100
CALL MPDIVI (Z, TP, Z)
TP = 1
100 CONTINUE
RETURN
110 DO 120 I = 1, IE
TP = 16*TP
IF ((TP.LE.IB).AND.(TP.NE.B).AND.(I.LT.IE)) GO TO 120
CALL MPMULI (Z, TP, Z)
TP = 1
120 CONTINUE
130 RETURN
END
SUBROUTINE MPCHK (I, J) MP013260
C CHECKS LEGALITY OF B, T, M, MXR AND LUN WHICH SHOULD BE SET
C IN COMMON.
C THE CONDITION ON MXR (THE DIMENSION OF R IN COMMON) IS THAT
C MXR .GE. (I*T + J)
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1)
C FIRST CHECK THAT LUN IN RANGE 1 TO 99, IF NOT PRINT ERROR
C MESSAGE ON LOGICAL UNIT 6.
IF ((0.LT.LUN).AND.(LUN.LT.100)) GO TO 20
WRITE (6, 10) LUN
10 FORMAT (10H *** LUN =, I10, 26H ILLEGAL IN CALL TO MPCHK,,
$ 49H PERHAPS NOT SET BEFORE CALL TO AN MP ROUTINE ***)
LUN = 6
CALL MPERR
C NOW CHECK LEGALITY OF B, T AND M
20 IF (B.GT.1) GO TO 40
WRITE (LUN, 30) B
30 FORMAT (8H *** B =, I10, 26H ILLEGAL IN CALL TO MPCHK,/
$ 49H PERHAPS NOT SET BEFORE CALL TO AN MP ROUTINE ***)
CALL MPERR
40 IF (T.GT.1) GO TO 60
WRITE (LUN, 50) T
50 FORMAT (8H *** T =, I10, 26H ILLEGAL IN CALL TO MPCHK,/
$ 49H PERHAPS NOT SET BEFORE CALL TO AN MP ROUTINE ***)
CALL MPERR
60 IF (M.GT.T) GO TO 80
WRITE (LUN, 70)
70 FORMAT (31H *** M .LE. T IN CALL TO MPCHK,/
$ 49H PERHAPS NOT SET BEFORE CALL TO AN MP ROUTINE ***)
CALL MPERR
C 8*B*B-1 SHOULD BE REPRESENTABLE, IF NOT WILL OVERFLOW
C AND MAY BECOME NEGATIVE, SO CHECK FOR THIS
80 IB = 4*B*B - 1
IF ((IB.GT.0).AND.((2*IB+1).GT.0)) GO TO 100
WRITE (LUN, 90)
90 FORMAT (37H *** B TOO LARGE IN CALL TO MPCHK ***)
CALL MPERR
C CHECK THAT SPACE IN COMMON IS SUFFICIENT
100 MX = I*T + J
IF (MXR.GE.MX) RETURN
C HERE COMMON IS TOO SMALL, SO GIVE ERROR MESSAGE.
WRITE (LUN, 110) I, J, MX, MXR, T
110 FORMAT (51H *** MXR TOO SMALL OR NOT SET TO DIM(R) BEFORE CALL,
$ 21H TO AN MP ROUTINE *** /
$ 27H *** MXR SHOULD BE AT LEAST, I3, 4H*T +, I4, 2H =, I6, 5H ***
$ / 19H *** ACTUALLY MXR =, I10, 9H, AND T =, I10, 5H ***)
CALL MPERR
RETURN
END
SUBROUTINE MPCIM (IX, Z) MP013770
C CONVERTS INTEGER IX TO MULTIPLE-PRECISION Z.
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), Z(2)
C CHECK LEGALITY OF B, T, M, MXR AND LUN
CALL MPCHK (1, 4)
N = IX
IF (N) 20, 10, 30
10 Z(1) = 0
RETURN
20 N = -N
Z(1) = -1
GO TO 40
30 Z(1) = 1
C SET EXPONENT TO T
40 Z(2) = T
C CLEAR FRACTION
DO 50 I = 2, T
50 Z(I+1) = 0
C INSERT N
Z(T+2) = N
C NORMALIZE BY CALLING MPMUL2
CALL MPMUL2 (Z, 1, Z, 1)
RETURN
END
SUBROUTINE MPCLR (X, N) MP014040
C SETS X(T+3), ... , X(N+2) TO ZERO, USEFUL
C IF PRECISION IS GOING TO BE INCREASED.
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(1)
IF (N.LE.T) RETURN
I2 = T + 3
I3 = N + 2
DO 10 I = I2, I3
10 X(I) = 0
RETURN
END
SUBROUTINE MPCMD (X, DZ) MP014170
C CONVERTS MULTIPLE-PRECISION X TO DOUBLE-PRECISION DZ.
C ASSUMES X IS IN ALLOWABLE RANGE FOR DOUBLE-PRECISION
C NUMBERS. THERE IS SOME LOSS OF ACCURACY IF THE
C EXPONENT IS LARGE.
DOUBLE PRECISION DB, DZ, DZ2, DBLE, DLOG, DABS
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(2), TM
C CHECK LEGALITY OF B, T, M, MXR AND LUN
CALL MPCHK (1, 4)
DZ = 0D0
IF (X(1).EQ.0) RETURN
C DB = DFLOAT(B) IS NOT ANSI STANDARD, SO USE FLOAT AND DBLE
DB = DBLE(FLOAT(B))
DO 10 I = 1, T
DZ = DB*DZ + DBLE(FLOAT(X(I+2)))
TM = I
C CHECK IF FULL DOUBLE-PRECISION ACCURACY ATTAINED
DZ2 = DZ + 1D0
C TEST BELOW NOT ALWAYS EQUIVALENT TO - IF (DZ2.LE.DZ) GO TO 20,
C FOR EXAMPLE ON CYBER 76.
IF ((DZ2-DZ).LE.0D0) GO TO 20
10 CONTINUE
C NOW ALLOW FOR EXPONENT
20 DZ = DZ*(DB**(X(2)-TM))
C CHECK REASONABLENESS OF RESULT.
IF (DZ.LE.0D0) GO TO 30
C LHS SHOULD BE .LE. 0.5 BUT ALLOW FOR SOME ERROR IN DLOG
IF (DABS(DBLE(FLOAT(X(2)))-(DLOG(DZ)/
$ DLOG(DBLE(FLOAT(B)))+0.5D0)).GT.0.6D0) GO TO 30
IF (X(1).LT.0) DZ = -DZ
RETURN
C FOLLOWING MESSAGE INDICATES THAT X IS TOO LARGE OR SMALL -
C TRY USING MPCMDE INSTEAD.
30 WRITE (LUN, 40)
40 FORMAT (48H *** FLOATING-POINT OVER/UNDER-FLOW IN MPCMD ***)
CALL MPERR
RETURN
END
SUBROUTINE MPCMDE (X, N, DX) MP014570
C RETURNS INTEGER N AND DOUBLE-PRECISION DX SUCH THAT MP
C X = DX*10**N (APPROXIMATELY), WHERE 1 .LE. ABS(DX) .LT. 10
C UNLESS DX = 0. SPACE = 6T+14
COMMON B, T, M, LUN, MXR, R
INTEGER B, T, R(1), X(1)
DOUBLE PRECISION DX, DBLE, DABS