3DSoftware.com > Programming > Floating Point > Page 9
Floating Point Numbers  Page 9
 
Wide Floating Point
 
Elementary Functions
 
For some of the elementary functions we use arithmetic geometric mean (AGM). [ 1 ]  AGM is the convergence of arithmetic mean and geometric mean. [ 2–4 ]  It is used to calculate the perimeter of an ellipse. [ 5 ]  The irrational number pi (3.14159…) is derived from calculating the circumference of a circle that is an ellipse with semi-major and semi-minor axes equal. To do that, we use the AGM variation reported in Muller (with k=6), which is attributed to Brent and Salamin. [ 6 ]  A similar method is reported in Press, et.al., which is credited to Borwein and Borwein. [ 7 ]
 
To calculate the natural logarithm of 2 with AGM, we use eq. 5.6 in Muller, which is derived from an elliptic integral. Other natural logarithms are computed with AGM (Muller § 5.5.2). That is used with Newton-Raphson (NR) iteration to compute exponentials (§ 5.5.3).
 
For computation of trigonometric functions, we use power series. Trigonometric power series formulas and identities are listed in math reference books [ 8–12 ]:
 
sin(x) = x – x3 / 3! + x5 / 5! – x7 / 7! ...
 
cos(x) = 1 – x2 / 2! + x4 / 4! – x6 / 6! ...
 
Cosine and sine are both computed, for efficiency purposes and also because they are usually both needed. The numerator of each term is a power of x. The denominator is a factorial that can be precomputed. Since the denominators are constant, the series converges faster with smaller values of x.  Range reduction is used to reduce the value of of x.  For example, using the identity
 
cos2x = 2cos²x – 1
 
the value of x is halved several times before computing the series, then the cosine series sum is plugged into this identity that many times (multiple squaring). The following works for sine:
 
sin(2x) = 2sin(x)cos(x)
 
If you need to compute only sin(x) without cos(x), calculate it as a cosine with this trigonometric identity:
 
sin(x) = cos( pi/2 – x )
 
There is another algorithm, which we have not implemented, that is an extension of these algorithms we have implemented. It is used in the cssn.cpp source code file of Bailey's ARPREC. That method converts (splits) x into the sum of a smaller value and a larger (or perhaps zero) value which has its sines and cosines precomputed and saved to a table for later retrieval. The variable (smaller) value has leading fractional zeros and therefore needs to compute less series terms. That method may be suitable for numbers with larger significands than we need.
 
For inverse trigonometry (arctangent) we go back to using AGM, as reported in Muller § 5.5.4, which he attributes to Brent. A different method we have not tried yet is implemented in ARPREC ang.c which uses NR iteration to estimate the angle of a hypotenuse.
 

 
References:
 
1.   Muller, J.M., 2006, Elementary Functions: Algorithms and Implementation 2nd ed., p. 95.
 
2.   Abramowitz, M., and Stegun, I.A., 1972, Handbook of Mathematical Functions, p. 10, eqs. 3.1.11, 3.1.12.
 
3.   Polyanin, A.D., and Manzhirov, A.V., 2007, Handbook of Mathematics for Engineers and Scientists, p. 13.
 
4.   Rade, L., and Westergren, B., 2004, Mathematics Handbook for Science and Engineering 5th ed., p. 46.
 
5.   Milne-Thomson, L.M., 1972, Elliptic Integrals, § 17.6.1-4, in Abramowitz, M., and Stegun, I.A., Handbook of Mathematical Functions, p. 598-599 (cited in Snyder, Map Projections — A Working Manual, p. 17).
 
6.   Muller, p. 97.
 
7.   Press, W.H., Teukolsky, S.A., Vetterling, W.T., and Flannery, B.P., 2002, Numerical Recipes in C++ 2nd ed., p. 917.
 
8.   Gradshteyn, I.S. and Ryzhik, I.M., 2007, Table of Integrals, Series, and Products 7th ed. (Jeffrey and Zwillinger, eds.), 1.321.1, 1.323.1, 1.411.1, 1.411.3.
 
9.   Polyanin and Manzhirov, 2.2.3-8, 2.2.3-12.
 
10.   Rade and Westergren, p. 127, 197, 198.
 
11.   Zucker, R., 1972, Elementary Transcendental Functions, Ch. 4 in Abramowitz, M., and Stegun, I.A., Handbook of Mathematical Functions, p. 74.
 
12.   Bronshtein, I.N., Semendyayev, K.A., Musiol, G., and Muehlig, H., 2007, Handbook of Mathematics 5th ed., p. 1016.
 
—  Page 9  —
 « Page 8 Contents Page 10 » 
 
Copyright © 2008 by 3D Software. All rights reserved.
3D Software, P.O. Box 221190, Sacramento CA 95822 USA
www.3DSoftware.com     Contact us
Thursday, 20-Nov-2008 13:51:32 GMT