mpadd2.f 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. *DECK MPADD2
  2. SUBROUTINE MPADD2 (X, Y, Z, Y1, TRUNC)
  3. C***BEGIN PROLOGUE MPADD2
  4. C***SUBSIDIARY
  5. C***PURPOSE Subsidiary to DQDOTA and DQDOTI
  6. C***LIBRARY SLATEC
  7. C***TYPE ALL (MPADD2-A)
  8. C***AUTHOR (UNKNOWN)
  9. C***DESCRIPTION
  10. C
  11. C Called by MPADD, MPSUB etc.
  12. C X, Y and Z are MP numbers, Y1 and TRUNC are integers.
  13. C To force call by reference rather than value/result, Y1 is
  14. C declared as an array, but only Y1(1) is ever used.
  15. C Sets Z = X + Y1(1)*ABS(Y), where Y1(1) = +- Y(1).
  16. C If TRUNC .EQ. 0, R*-rounding is used; otherwise, truncation.
  17. C R*-rounding is defined in the Kuki and Cody reference.
  18. C
  19. C The arguments X(*), Y(*), and Z(*) are all INTEGER arrays of size
  20. C 30. See the comments in the routine MPBLAS for the reason for this
  21. C choice.
  22. C
  23. C***SEE ALSO DQDOTA, DQDOTI, MPBLAS
  24. C***REFERENCES H. Kuki and W. J. Cody, A statistical study of floating
  25. C point number systems, Communications of the ACM 16, 4
  26. C (April 1973), pp. 223-230.
  27. C R. P. Brent, On the precision attainable with various
  28. C floating-point number systems, IEEE Transactions on
  29. C Computers C-22, 6 (June 1973), pp. 601-607.
  30. C R. P. Brent, A Fortran multiple-precision arithmetic
  31. C package, ACM Transactions on Mathematical Software 4,
  32. C 1 (March 1978), pp. 57-70.
  33. C R. P. Brent, MP, a Fortran multiple-precision arithmetic
  34. C package, Algorithm 524, ACM Transactions on Mathema-
  35. C tical Software 4, 1 (March 1978), pp. 71-81.
  36. C***ROUTINES CALLED MPADD3, MPCHK, MPERR, MPNZR, MPSTR
  37. C***COMMON BLOCKS MPCOM
  38. C***REVISION HISTORY (YYMMDD)
  39. C 791001 DATE WRITTEN
  40. C ?????? Modified for use with BLAS. Blank COMMON changed to named
  41. C COMMON. R given dimension 12.
  42. C 890531 Changed all specific intrinsics to generic. (WRB)
  43. C 891214 Prologue converted to Version 4.0 format. (BAB)
  44. C 900402 Added TYPE section. (WRB)
  45. C 920528 Added a REFERENCES section revised. (WRB)
  46. C 930124 Increased Array size in MPCON for SUN -r8. (RWC)
  47. C***END PROLOGUE MPADD2
  48. COMMON /MPCOM/ B, T, M, LUN, MXR, R(30)
  49. INTEGER B, T, R, X(*), Y(*), Z(*), Y1(*), TRUNC
  50. INTEGER S, ED, RS, RE
  51. C***FIRST EXECUTABLE STATEMENT MPADD2
  52. IF (X(1).NE.0) GO TO 20
  53. 10 CALL MPSTR(Y, Z)
  54. Z(1) = Y1(1)
  55. RETURN
  56. 20 IF (Y1(1).NE.0) GO TO 40
  57. 30 CALL MPSTR (X, Z)
  58. RETURN
  59. C COMPARE SIGNS
  60. 40 S = X(1)*Y1(1)
  61. IF (ABS(S).LE.1) GO TO 60
  62. CALL MPCHK (1, 4)
  63. WRITE (LUN, 50)
  64. 50 FORMAT (' *** SIGN NOT 0, +1 OR -1 IN CALL TO MPADD2,',
  65. 1 ' POSSIBLE OVERWRITING PROBLEM ***')
  66. CALL MPERR
  67. Z(1) = 0
  68. RETURN
  69. C COMPARE EXPONENTS
  70. 60 ED = X(2) - Y(2)
  71. MED = ABS(ED)
  72. IF (ED) 90, 70, 120
  73. C EXPONENTS EQUAL SO COMPARE SIGNS, THEN FRACTIONS IF NEC.
  74. 70 IF (S.GT.0) GO TO 100
  75. DO 80 J = 1, T
  76. IF (X(J+2) - Y(J+2)) 100, 80, 130
  77. 80 CONTINUE
  78. C RESULT IS ZERO
  79. Z(1) = 0
  80. RETURN
  81. C HERE EXPONENT(Y) .GE. EXPONENT(X)
  82. 90 IF (MED.GT.T) GO TO 10
  83. 100 RS = Y1(1)
  84. RE = Y(2)
  85. CALL MPADD3 (X, Y, S, MED, RE)
  86. C NORMALIZE, ROUND OR TRUNCATE, AND RETURN
  87. 110 CALL MPNZR (RS, RE, Z, TRUNC)
  88. RETURN
  89. C ABS(X) .GT. ABS(Y)
  90. 120 IF (MED.GT.T) GO TO 30
  91. 130 RS = X(1)
  92. RE = X(2)
  93. CALL MPADD3 (Y, X, S, MED, RE)
  94. GO TO 110
  95. END