home *** CD-ROM | disk | FTP | other *** search
-
- *****************************************************************************
-
-
- An Ada Implementation of the
- Cody-Waite "Software Manual for the Elementary Functions"
-
-
- W. A. Whitaker, Air Force Armament Lab
- T. C. Eicholtz, Air Force Academy
-
-
-
-
-
- During the early days of developing Ada compilers and systems, those most
- involved are concerned chiefly with the definition of the language
- and the robustness and efficiency of their compilers. They often are forced
- to delay some of the amenities which the user associates with a mature system.
- Such facilities like a set of the elementary mathematical functions have in
- the past been the product of very specialized practitioners
- who have strived for very high efficiency for these often used routines.
- Such efficiency goals have lead to much black art and hardware dependent
- methods. These are often obscure and usually undocumented. The next artist
- therefore must start from scratch and seldom even has a good
- measure of his product.
-
- The increase in hardware capabilities has done much to relieve the
- pressure for efficiencies down to the last clock or the last memory location,
- which was sometimes used to justify routines which were fast and right "almost
- everywhere". There has been much work in recent years
- in the methods of constructing these routines. The publication
- of "Software Manual for the Elementary Functions" by William. J. Cody, Jr.
- and William Waite (Prentice-Hall, 1980) makes available a "cookbook" of
- routines, tests, and comparisons with other systems.
-
- The advent of Ada as a machine insensitive high order language
- presents an opportunity to provide these functions
- to a number of machines in a single package in a way that has not been
- possible before. Further, the users of Ada, even of primitive compilers
- and systems, have an immediate need for the capability, and a reasonable
- expectation that the facilities intrinsic to FORTRAN be available with
- the more powerful Ada.
-
- This report gives the programs of Cody-Waite transliterated
- into Ada. The reader is referred to that book for all mathematical details.
- Even the same variable names and mostly the same order of the code are
- preserved so that one familiar with the book should be able to follow the
- code with a very cursory knowledge of Ada.
-
- In the full implemetation, these functions must be generics.
- The present programs were started that way, but there were difficulties
- in early compilers that precluded the use of the full generality of Ada
- on the wide choice of partial systems that were first available.
- Further, it may be that the most common usage will be for the STANDARD
- supported types or those derived from them and that systems implementors
- will want to provide special packages for these types, without any further
- generality.
-
- Early versions of the core functions were tested against user defined types,
- even to the extent that the representation of the mantissa as either a
- fixed or floating number was hidden, but this purity has been abandoned.
-
- The present system is designed for generic digits up to 18.
- This is done using two different sets of approximations, selecting
- the one for about 32 bits and another for about 64. Of course the details
- of the implementation are hidden in the body, and the spec could be used with
- more efficient specific code. This implementation is not fast the way it
- stands, but provides a common set of functions that have been used in
- one version or another for more than 4 years on a dozen different
- compilers and machines.
-
-
-
- The following results are typical of tests of the math routines.
- The tests are recodes in Ada of the Cody_Waite tests (with the cube root test
- being an appropiately modified copy of the square root).
- The results might be termed typical rather than exact since the precise values
- depend somewhat on the random numbers generated in a test. Differences
- are to be expected unless very large numbers of tests are conducted.
- Even with 2000 points, the number taken in the present series, there is
- a good chance of missing the occasional bad point, or hitting it
- with another choice of random numbers. A 1.3 bit maximum error might become
- 1.7 bits on another run. Nevertheless the tests give a very good picture
- of the overall quality of the functions and are very useful in debugging.
-
- It might also occur to the reader that the precision in bits of the
- maximum relative error (MRE) appears excessive; one might be off by
- one bit, but not 0.97 bits. There is information about the location of
- the maximum error also in this number, but for most purposes the value might
- be rounded, and 0.97 is no better than 1.03, both being one bit. The
- definition of MRE is to be taken from the test programs themselves, as is the
- definition of root mean square error (RMS). RMS is truncated in this
- definition such that average errors less than 1.0/2.0**IT are zero
- (where there are IT significant bits in the mantissa).
- The purpose of the table is to demonstrate that the Ada routines
- have the expected accuracy, indeed, that they even have errors of
- the same magnitude as the origional FORTRAN routines, and that they are
- reasonably good in this regard in comparison with commericial systems
- offerings. (Note that the IBM/370 results quoted refer to loss of
- hexidecimal digits of accuracy, the others to binary digits.)
-
- Some results from the book and from the Ada version:
- (for FLOAT except for a VAX/DEC LONG_FLOAT)
- HT$
-
-
- MAXIMUM RELATIVE ERROR & ROOT MEAN SQUARE ERROR
-
-
- SQRT TEST 1 TEST 2
-
- FTN 4.6 CDC 7600 0.50 0.00 0.99 0.00
- CW-FORTRAN CDC 6400 0.50 0.26 2.00 1.31
- CW-FORTRAN IBM/370 0.75 1.00 1.00 0.81
- CW_Ada DEC-10 0.50 0.00 1.00 0.00
- CW_Ada VAX/TEL 0.49 0.00 1.00 0.00
- CW_Ada VAX/DEC 0.49 0.00 1.00 0.00
- CW_Ada VAX/DEC L_F 0.50 0.00 0.00 0.00
- CW_Ada R1000 0.50 0.26 1.00 0.76
-
-
-
- CBRT TEST 1 TEST 2 TEST 3
-
- CW_Ada DEC-10 0.33 0.00 1.00 0.00
- CW_Ada VAX/TEL 0.33 0.00 1.00 0.20
- CW_Ada VAX/DEC 0.33 0.00 1.00 0.23
- CW_Ada VAX/DEC L_F 0.33 0.00 0.89 0.00 0.65 0.00
- CW_Ada R1000 0.33 0.01 1.00 0.77 0.67 0.41
-
-
- LOG TEST 1 TEST 2 TEST 3 TEST 4
-
- FTN 4.7 CDC 7600 2.00 0.09 1.74 0.02 2.53 0.56
- CW-FORTRAN CDC 6400 1.00 0.00 1.67 0.00 3.28 1.29 0.97 0.00
- CW-FORTRAN IBM/370 1.00 0.19 0.99 0.57 1.07 0.59 0.53 0.10
- CW_Ada DEC-10 1.81 0.00 1.61 0.00 2.58 0.67 0.98 0.00
- CW_Ada VAX/TEL 1.66 0.00 1.95 0.00 2.43 0.52 0.98 0.00
- CW_Ada VAX/DEC 1.65 0.00 1.97 0.00 2.41 0.55 0.98 0.00
- CW_Ada VAX/DEC L_F 1.52 0.00 1.87 0.00 2.68 0.67 0.93 0.00
- CW_Ada VAX/DEC 1.95 0.00 1.58 0.00 3.52 1.57 0.97 0.00
-
-
-
- EXP TEST 1 TEST 2 TEST 3
-
- FTN 4.7 CDC 7600 1.63 0.06 1.37 0.00 1.31 0.00
- CW-FORTRAN CDC 7600 1.50 0.00 1.55 0.00 1.55 0.05
- CW-FORTRAN IBM/370 1.00 0.67 1.00 0.55 1.00 0.56
- CW_Ada DEC-10 1.58 0.00 1.56 0.00 1.55 0.00
- CW_Ada VAX/TEL 1.55 0.00 1.41 0.00 1.46 0.00
- CW_Ada VAX/DEC 1.60 0.00 1.54 0.00 1.28 0.00
- CW_Ada VAX/DEC L_F 1.46 0.00 1.52 0.00 1.53 0.00
- CW_Ada R1000 1.74 0.00 1.67 0.00 1.57 0.00
-
-
- POWER TEST 1 TEST 2 TEST 3 TEST 4
-
- FTN 4.6 CDC 7600 1.00 0.00 2.23 0.18 9.92 8.58 10.00 6.69
- CW-FORTRAN CDC 6400 0.37 0.00 0.99 0.00 1.00 0.00 4.21 1.59
- CW-FORTRAN IBM/370 0.99 0.43 1.00 0.21 1.00 0.20 0.99 0.45
- CW_Ada DEC-10 0.87 0.00 1.00 0.00 1.44 0.00 1.06 0.00
- CW_Ada VAX/TEL 0.94 0.00 1.73 0.00 1.69 0.00 4.34 2.58
- CW_Ada VAX/DEC 0.94 0.00 1.73 0.00 1.73 0.00 4.33 2.57
- CW_Ada VAX/DEC L_F 0.94 0.00 1.00 0.00 1.00 0.00 3.55 1.14
- CW_Ada R1000 1.00 0.12 0.99 0.00 1.00 0.00 4.73 2.43
-
-
-
- SIN/COS TEST 1 TEST 2 TEST 3
-
- DOS 8.02 PDP/11 1.99 0.10 1.74 0.09 12.63 7.66
- CW-FORTRAN CDC 6400 2.00 0.73 2.20 0.80 2.39 0.68
- CW-FORTRAN IBM/370 1.08 0.71 1.16 0.72 1.11 0.70
- CW_Ada DEC-10 1.27 0.00 1.64 0.00 1.40 0.00
- CW_Ada VAX/TEL 1.24 0.00 3.39 0.00 5.91 0.72
- CW_Ada VAX/DEC 1.59 0.00 3.48 0.00 4.10 0.00
- CW_Ada VAX/DEC L_F 1.33 0.00 1.53 0.00 1.95 0.00
- CW_Ada R1000 2.32 0.89 2.32 0.87 2.32 0.91
-
-
- TAN/COT TEST 1 TEST 2 TEST 3 TEST 4
-
- FTN 4.6 CDC 6400 2.70 1.06 2.52 0.87 15.93 10.53
- CW-FORTRAN CDC 6600 2.48 0.69 2.39 0.62 2.48 0.69 2.49 0.67
- CW-FORTRAN IBM/370 1.17 0.62 1.30 0.88 1.38 0.74 1.29 0.82
- CW_Ada DEC-10 2.33 0.66 1.98 0.28 2.44 0 60 2.35 0.44
- CW_Ada VAX/TEL 2.53 0.68 2.06 0.31 2.44 0 66 2.41 0.48
- CW_Ada VAX/DEC 2.50 0.68 2.02 0.29 2.36 0 60 2.52 0.42
- CW_Ada VAX/DEC L_F 2.52 0.66 2.02 0.33 2.39 6 60 2.58 0.45
- CW_Ada R1000 2.36 0.74 2.35 0.55 2.41 0 71 2.90 1.14
-
-
- ASIN/ACOS TEST 1 TEST 2 TEST 3
-
- FTN 4.7 CDC 6400 1.00 0.00 0.47 0.00 1.24 0.00
- CW-FORTRAN CDC 6400 0.99 0.00 0.47 0.00 1.24 0.03
- CW-FORTRAN IBM/370 1.00 0.64 0.87 0.69 1.00 0.72
- CW_Ada DEC-10 0.20 0.00 0.47 0.00 0.99 0.00
- CW_Ada VAX/TEL 0.00 0.00 0.47 0.00 1.24 0.44
- CW_Ada VAX/DEC 0.73 0.00 0.47 0.02 1.00 0.08
- CW_Ada VAX/DEC L_F 0.45 0.00 0.45 0.00 1.00 0.00
- CW_Ada R1000 1.00 0.00 0.47 0.02 1.00 0.25
-
-
- TEST 4 TEST 5
-
- FTN 4.7 CDC 6400 1.90 0.00 0.72 0.00
- CW-FORTRAN CDC 6400 1.00 0.00 0.66 0.00
- CW-FORTRAN IBM/370 1.90 0.00 0.93 0.71
- CW_Ada DEC-10 0.93 0.00 0.73 0.00
- CW_Ada VAX/TEL 0.90 0.00 0.73 0.11
- CW_Ada VAX/DEC 0.92 0.00 0.72 0.13
- CW_Ada VAX/DEC L_F 0.92 0.00 0.73 0.00
- CW_Ada R1000 1.00 0.12 0.73 0.31
-
-
- ATAN/ATAN2 TEST 1 TEST 2 TEST 3 TEST 4
-
- FTN 4.8 CDC 7600 0.84 0.00 1.00 0.00 1.86 0.39 1.95 0.02
- CW-FORTRAN CDC 6400 0.84 0.00 1.00 0.00 2.50 0.75 2.34 0.05
- CW-FORTRAN IBM/370 1.00 0.38 1.00 0.69 0.76 0.33 1.00 0.67
- CW_Ada DEC-10 0.24 0.00 1.00 0.00 1.93 0.03 1.33 0.00
- CW_Ada VAX/TEL 0.09 0.00 1.00 0.00 1.93 0.11 1.34 0.00
- CW_Ada VAX/DEC 0.00 0.00 1.00 0.00 1.92 0.13 1.32 0.00
- CW_Ada VAX/DEC L_F 0.10 0.00 1.00 0.00 2.47 0.39 1.26 0.00
- CW_Ada R1000 1.00 0.00 1.41 0.07 2.40 0.49 1.99 0.47
-
- SINH/COSH TEST 1 TEST 2 TEST 3 TEST 4
-
- FTN 4.6 CDC 6400 1.48 0.08 1.00 0.41 2.50 1.00 2.19 0.99
- CW-FORTRAN CDC 6400 1.00 0.00 1.00 0.00 2.36 0.98 2.04 0.98
- CW-FORTRAN IBM/370 1.00 0.48 1.00 0.85 1.26 0.77 1.25 0.77
- CW_Ada DEC-10 1.00 0.00 1.00 0.00 1.61 0.01 1.92 0.01
- CW_Ada VAX/TEL 0.96 0.00 1.00 0.00 1.97 0.28 1.98 0.30
- CW_Ada VAX/DEC 1.00 0.00 1.00 0.00 1.90 0.34 1.93 0.32
- CW_Ada VAX/DEC L_F 0.96 0.00 1.00 0.00 1.62 0.13 1.65 0.13
- CW_Ada R1000 1.00 0.07 1.00 0.45 2.47 1.24 2.44 1.26
-
-
- TANH TEST 1 TEST 2
-
- FTN 4.6 CDC 6400 2.25 1.81 2.25 0.00
- CW-FORTRAN CDC 6400 1.75 0.03 1.73 0.00
- CW-FORTRAN IBM/370 1.05 0.72 1.00 0.61
- CW_Ada DEC-10 1.65 0.00 1.31 0.00
- CW_Ada VAX/TEL 1.94 0.11 1.50 0.00
- CW_Ada VAX/DEC 1.44 0.00 1.15 0.00
- CW_Ada VAX/DEC L_F 1.41 0.00 1.20 0.00
- CW_Ada R1000 1.96 0.09 1.60 0.00
-