home *** CD-ROM | disk | FTP | other *** search
/ Programmer's ROM - The Computer Language Library / programmersrom.iso / ada / math / cwaite.doc < prev    next >
Encoding:
Text File  |  1988-05-03  |  12.8 KB  |  252 lines

  1.  
  2. *****************************************************************************
  3.  
  4.  
  5.                          An Ada Implementation of the 
  6.            Cody-Waite "Software Manual for the Elementary Functions"
  7.  
  8.  
  9.                      W. A. Whitaker, Air Force Armament Lab
  10.                        T. C. Eicholtz, Air Force Academy
  11.  
  12.  
  13.  
  14.  
  15.  
  16. During the early days of developing Ada compilers and systems, those most
  17. involved are concerned chiefly with the definition of the language
  18. and the robustness and efficiency of their compilers.  They often are forced 
  19. to delay some of the amenities which the user associates with a mature system.
  20. Such facilities like a set of the elementary mathematical functions have in 
  21. the past been the product of very specialized practitioners
  22. who have strived for very high efficiency for these often used routines.
  23. Such efficiency goals have lead to much black art and hardware dependent
  24. methods.  These are often obscure and usually undocumented.  The next artist
  25. therefore must start from scratch and seldom even has a good
  26. measure of his product.  
  27.  
  28. The increase in hardware capabilities has done much to relieve the 
  29. pressure for efficiencies down to the last clock or the last memory location,
  30. which was sometimes used to justify routines which were fast and right "almost
  31. everywhere".  There has been much work in recent years 
  32. in the methods of constructing these routines.  The publication
  33. of "Software Manual for the Elementary Functions" by William. J. Cody, Jr.
  34. and William Waite (Prentice-Hall, 1980) makes available a "cookbook" of
  35. routines, tests, and comparisons with other systems.  
  36.  
  37. The advent of Ada as a machine insensitive high order language 
  38. presents an opportunity to provide these functions
  39. to a number of machines in a single package in a way that has not been
  40. possible before.  Further, the users of Ada, even of primitive compilers
  41. and systems, have an immediate need for the capability, and a reasonable
  42. expectation that the facilities intrinsic to FORTRAN be available with
  43. the more powerful Ada.
  44.  
  45. This report gives the programs of Cody-Waite transliterated 
  46. into Ada.  The reader is referred to that book for all mathematical details.
  47. Even the same variable names and mostly the same order of the code are
  48. preserved so that one familiar with the book should be able to follow the
  49. code with a very cursory knowledge of Ada.
  50.  
  51. In the full implemetation, these functions must be generics.
  52. The present programs were started that way, but there were difficulties
  53. in early compilers that precluded the use of the full generality of Ada
  54. on the wide choice of partial systems that were first available.
  55. Further, it may be that the most common usage will be for the STANDARD
  56. supported types or those derived from them and that systems implementors
  57. will want to provide special packages for these types, without any further
  58. generality.
  59.  
  60. Early versions of the core functions were tested against user defined types,
  61. even to the extent that the representation of the mantissa as either a 
  62. fixed or floating number was hidden, but this purity has been abandoned.
  63.  
  64. The present system is designed for generic digits up to 18.
  65. This is done using two different sets of approximations, selecting
  66. the one for about 32 bits and another for about 64.  Of course the details
  67. of the implementation are hidden in the body, and the spec could be used with
  68. more efficient specific code.  This implementation is not fast the way it
  69. stands, but provides a common set of functions that have been used in
  70. one version or another for more than 4 years on a dozen different
  71. compilers and machines.
  72.  
  73.  
  74.  
  75. The following results are typical of tests of the math routines.
  76. The tests are recodes in Ada of the Cody_Waite tests (with the cube root test 
  77. being an appropiately modified copy of the square root).
  78. The results might be termed typical rather than exact since the precise values
  79. depend somewhat on the random numbers generated in a test.  Differences
  80. are to be expected unless very large numbers of tests are conducted.
  81. Even with 2000 points, the number taken in the present series, there is
  82. a good chance of missing the occasional bad point, or hitting it
  83. with another choice of random numbers.  A 1.3 bit maximum error might become
  84. 1.7 bits on another run.  Nevertheless the tests give a very good picture
  85. of the overall quality of the functions and are very useful in debugging.
  86.  
  87. It might also occur to the reader that the precision in bits of the 
  88. maximum relative error (MRE) appears excessive; one might be off by
  89. one bit, but not 0.97 bits.  There is information about the location of
  90. the maximum error also in this number, but for most purposes the value might
  91. be rounded, and 0.97 is no better than 1.03, both being one bit.  The 
  92. definition of MRE is to be taken from the test programs themselves, as is the 
  93. definition of root mean square error (RMS).  RMS is truncated in this 
  94. definition such that average errors less than 1.0/2.0**IT are zero 
  95. (where there are IT significant bits in the mantissa).
  96. The purpose of the table is to demonstrate that the Ada routines
  97. have the expected accuracy, indeed, that they even have errors of
  98. the same magnitude as the origional FORTRAN routines, and that they are 
  99. reasonably good in this regard in comparison with commericial systems 
  100. offerings.  (Note that the IBM/370 results quoted refer to loss of
  101. hexidecimal digits of accuracy, the others to binary digits.)
  102.  
  103. Some results from the book and from the Ada version:
  104. (for FLOAT except for a VAX/DEC LONG_FLOAT)
  105. HT$
  106.  
  107.  
  108.      MAXIMUM RELATIVE ERROR     &     ROOT MEAN SQUARE ERROR
  109.  
  110.  
  111.  SQRT                        TEST 1        TEST 2
  112.  
  113.  FTN 4.6      CDC 7600     0.50  0.00    0.99  0.00
  114.  CW-FORTRAN   CDC 6400     0.50  0.26    2.00  1.31
  115.  CW-FORTRAN   IBM/370      0.75  1.00    1.00  0.81
  116.  CW_Ada       DEC-10       0.50  0.00    1.00  0.00
  117.  CW_Ada       VAX/TEL      0.49  0.00    1.00  0.00
  118.  CW_Ada       VAX/DEC      0.49  0.00    1.00  0.00
  119.  CW_Ada       VAX/DEC L_F  0.50  0.00    0.00  0.00
  120.  CW_Ada       R1000        0.50  0.26    1.00  0.76
  121.  
  122.  
  123.  
  124.  CBRT                        TEST 1        TEST 2        TEST 3
  125.  
  126.  CW_Ada       DEC-10       0.33  0.00    1.00  0.00
  127.  CW_Ada       VAX/TEL      0.33  0.00    1.00  0.20
  128.  CW_Ada       VAX/DEC      0.33  0.00    1.00  0.23
  129.  CW_Ada       VAX/DEC L_F  0.33  0.00    0.89  0.00    0.65  0.00
  130.  CW_Ada       R1000        0.33  0.01    1.00  0.77    0.67  0.41
  131.  
  132.  
  133.  LOG                         TEST 1        TEST 2        TEST 3        TEST 4
  134.  
  135.  FTN 4.7      CDC 7600     2.00  0.09    1.74  0.02    2.53  0.56
  136.  CW-FORTRAN   CDC 6400     1.00  0.00    1.67  0.00    3.28  1.29    0.97  0.00
  137.  CW-FORTRAN   IBM/370      1.00  0.19    0.99  0.57    1.07  0.59    0.53  0.10
  138.  CW_Ada       DEC-10       1.81  0.00    1.61  0.00    2.58  0.67    0.98  0.00
  139.  CW_Ada       VAX/TEL      1.66  0.00    1.95  0.00    2.43  0.52    0.98  0.00
  140.  CW_Ada       VAX/DEC      1.65  0.00    1.97  0.00    2.41  0.55    0.98  0.00
  141.  CW_Ada       VAX/DEC L_F  1.52  0.00    1.87  0.00    2.68  0.67    0.93  0.00
  142.  CW_Ada       VAX/DEC      1.95  0.00    1.58  0.00    3.52  1.57    0.97  0.00
  143.  
  144.  
  145.  
  146.  EXP                         TEST 1        TEST 2        TEST 3
  147.  
  148.  FTN 4.7      CDC 7600     1.63  0.06    1.37  0.00    1.31  0.00
  149.  CW-FORTRAN   CDC 7600     1.50  0.00    1.55  0.00    1.55  0.05
  150.  CW-FORTRAN   IBM/370      1.00  0.67    1.00  0.55    1.00  0.56
  151.  CW_Ada       DEC-10       1.58  0.00    1.56  0.00    1.55  0.00
  152.  CW_Ada       VAX/TEL      1.55  0.00    1.41  0.00    1.46  0.00
  153.  CW_Ada       VAX/DEC      1.60  0.00    1.54  0.00    1.28  0.00
  154.  CW_Ada       VAX/DEC L_F  1.46  0.00    1.52  0.00    1.53  0.00
  155.  CW_Ada       R1000        1.74  0.00    1.67  0.00    1.57  0.00
  156.  
  157.  
  158.  POWER                       TEST 1        TEST 2        TEST 3        TEST 4
  159.  
  160.  FTN 4.6      CDC 7600     1.00  0.00    2.23  0.18    9.92  8.58   10.00  6.69
  161.  CW-FORTRAN   CDC 6400     0.37  0.00    0.99  0.00    1.00  0.00    4.21  1.59
  162.  CW-FORTRAN   IBM/370      0.99  0.43    1.00  0.21    1.00  0.20    0.99  0.45
  163.  CW_Ada       DEC-10       0.87  0.00    1.00  0.00    1.44  0.00    1.06  0.00
  164.  CW_Ada       VAX/TEL      0.94  0.00    1.73  0.00    1.69  0.00    4.34  2.58
  165.  CW_Ada       VAX/DEC      0.94  0.00    1.73  0.00    1.73  0.00    4.33  2.57
  166.  CW_Ada       VAX/DEC L_F  0.94  0.00    1.00  0.00    1.00  0.00    3.55  1.14
  167.  CW_Ada       R1000        1.00  0.12    0.99  0.00    1.00  0.00    4.73  2.43
  168.  
  169.  
  170.  
  171.  SIN/COS                     TEST 1        TEST 2        TEST 3
  172.  
  173.  DOS 8.02     PDP/11       1.99  0.10    1.74  0.09   12.63  7.66
  174.  CW-FORTRAN   CDC 6400     2.00  0.73    2.20  0.80    2.39  0.68
  175.  CW-FORTRAN   IBM/370      1.08  0.71    1.16  0.72    1.11  0.70
  176.  CW_Ada       DEC-10       1.27  0.00    1.64  0.00    1.40  0.00
  177.  CW_Ada       VAX/TEL      1.24  0.00    3.39  0.00    5.91  0.72
  178.  CW_Ada       VAX/DEC      1.59  0.00    3.48  0.00    4.10  0.00
  179.  CW_Ada       VAX/DEC L_F  1.33  0.00    1.53  0.00    1.95  0.00
  180.  CW_Ada       R1000        2.32  0.89    2.32  0.87    2.32  0.91
  181.  
  182.  
  183.  TAN/COT                     TEST 1        TEST 2        TEST 3        TEST 4
  184.  
  185.  FTN 4.6      CDC 6400     2.70  1.06    2.52  0.87   15.93 10.53
  186.  CW-FORTRAN   CDC 6600     2.48  0.69    2.39  0.62    2.48  0.69    2.49  0.67
  187.  CW-FORTRAN   IBM/370      1.17  0.62    1.30  0.88    1.38  0.74    1.29  0.82
  188.  CW_Ada       DEC-10       2.33  0.66    1.98  0.28    2.44  0 60    2.35  0.44
  189.  CW_Ada       VAX/TEL      2.53  0.68    2.06  0.31    2.44  0 66    2.41  0.48
  190.  CW_Ada       VAX/DEC      2.50  0.68    2.02  0.29    2.36  0 60    2.52  0.42
  191.  CW_Ada       VAX/DEC L_F  2.52  0.66    2.02  0.33    2.39  6 60    2.58  0.45
  192.  CW_Ada       R1000       2.36  0.74    2.35  0.55    2.41  0 71    2.90  1.14
  193.  
  194.  
  195.  ASIN/ACOS                   TEST 1        TEST 2        TEST 3
  196.  
  197.  FTN 4.7      CDC 6400     1.00  0.00    0.47  0.00    1.24  0.00
  198.  CW-FORTRAN   CDC 6400     0.99  0.00    0.47  0.00    1.24  0.03
  199.  CW-FORTRAN   IBM/370      1.00  0.64    0.87  0.69    1.00  0.72
  200.  CW_Ada       DEC-10       0.20  0.00    0.47  0.00    0.99  0.00
  201.  CW_Ada       VAX/TEL      0.00  0.00    0.47  0.00    1.24  0.44
  202.  CW_Ada       VAX/DEC      0.73  0.00    0.47  0.02    1.00  0.08
  203.  CW_Ada       VAX/DEC L_F  0.45  0.00    0.45  0.00    1.00  0.00
  204.  CW_Ada       R1000        1.00  0.00    0.47  0.02    1.00  0.25
  205.  
  206.  
  207.                                            TEST 4        TEST 5
  208.  
  209.  FTN 4.7      CDC 6400                   1.90  0.00    0.72  0.00
  210.  CW-FORTRAN   CDC 6400                   1.00  0.00    0.66  0.00
  211.  CW-FORTRAN   IBM/370                    1.90  0.00    0.93  0.71
  212.  CW_Ada       DEC-10                     0.93  0.00    0.73  0.00
  213.  CW_Ada       VAX/TEL                    0.90  0.00    0.73  0.11
  214.  CW_Ada       VAX/DEC                    0.92  0.00    0.72  0.13
  215.  CW_Ada       VAX/DEC L_F                0.92  0.00    0.73  0.00
  216.  CW_Ada       R1000                      1.00  0.12    0.73  0.31
  217.  
  218.  
  219.  ATAN/ATAN2                  TEST 1        TEST 2        TEST 3        TEST 4
  220.  
  221.  FTN 4.8      CDC 7600     0.84  0.00    1.00  0.00    1.86  0.39    1.95  0.02
  222.  CW-FORTRAN   CDC 6400     0.84  0.00    1.00  0.00    2.50  0.75    2.34  0.05
  223.  CW-FORTRAN   IBM/370      1.00  0.38    1.00  0.69    0.76  0.33    1.00  0.67
  224.  CW_Ada       DEC-10       0.24  0.00    1.00  0.00    1.93  0.03    1.33  0.00
  225.  CW_Ada       VAX/TEL      0.09  0.00    1.00  0.00    1.93  0.11    1.34  0.00
  226.  CW_Ada       VAX/DEC      0.00  0.00    1.00  0.00    1.92  0.13    1.32  0.00
  227.  CW_Ada       VAX/DEC L_F  0.10  0.00    1.00  0.00    2.47  0.39    1.26  0.00
  228.  CW_Ada       R1000        1.00  0.00    1.41  0.07    2.40  0.49    1.99  0.47
  229.  
  230.  SINH/COSH                   TEST 1        TEST 2        TEST 3        TEST 4
  231.  
  232.  FTN 4.6      CDC 6400     1.48  0.08    1.00  0.41    2.50  1.00    2.19  0.99
  233.  CW-FORTRAN   CDC 6400     1.00  0.00    1.00  0.00    2.36  0.98    2.04  0.98
  234.  CW-FORTRAN   IBM/370      1.00  0.48    1.00  0.85    1.26  0.77    1.25  0.77
  235.  CW_Ada       DEC-10       1.00  0.00    1.00  0.00    1.61  0.01    1.92  0.01
  236.  CW_Ada       VAX/TEL      0.96  0.00    1.00  0.00    1.97  0.28    1.98  0.30
  237.  CW_Ada       VAX/DEC      1.00  0.00    1.00  0.00    1.90  0.34    1.93  0.32
  238.  CW_Ada       VAX/DEC L_F  0.96  0.00    1.00  0.00    1.62  0.13    1.65  0.13
  239.  CW_Ada       R1000        1.00  0.07    1.00  0.45    2.47  1.24    2.44  1.26
  240.  
  241.  
  242.  TANH                        TEST 1        TEST 2
  243.  
  244.  FTN 4.6      CDC 6400     2.25  1.81    2.25  0.00
  245.  CW-FORTRAN   CDC 6400     1.75  0.03    1.73  0.00
  246.  CW-FORTRAN   IBM/370      1.05  0.72    1.00  0.61
  247.  CW_Ada       DEC-10       1.65  0.00    1.31  0.00
  248.  CW_Ada       VAX/TEL      1.94  0.11    1.50  0.00
  249.  CW_Ada       VAX/DEC      1.44  0.00    1.15  0.00
  250.  CW_Ada       VAX/DEC L_F  1.41  0.00    1.20  0.00
  251.  CW_Ada       R1000        1.96  0.09    1.60  0.00
  252.