Abstract
This chapter describes floating-point mathematics for real-time C++ using the built-in floating-point types such as float and double. The first sections of this chapter introduce floating-point arithmetic, mathematical constants, elementary transcendental functions and higher transcendental functions. The last sections of this chapter cover more advanced topics including complex-numbered mathematics, compile-time evaluation of floating-point functions and generic numeric programming.
Notes
- 1.
We primarily use float and double in this book.
- 2.
A similar polynomial expansion for Γ(x + 1) is given in Sect. 6.1.36 of [1]. This polynomial approximation originates from the work of C. Hastings [5]. In my book, I have increased the number of coefficients from Hastings’ original 8 up to 10 in order to reach precision better than the approximate 7 decimal digits of single-precision float.
- 3.
There is also a well-known alternate scheme for multiplication of complex numbers that requires only three real-valued multiplications, but five additions. In particular,
$$\left (a\, +\, ib\right )\, \times \,\left (c\, +\, id\right )\, =\, \left (\alpha \, -\, \beta \right )\, +\, i(\alpha \, +\, \gamma )\,\text{,}$$where
$$\begin{array}{rcl} & \alpha & \,=\, a\,\left (c\, +\, d\right ) \\ & \beta & \,=\, d\,\left (a\, +\, b\right ) \\ & \gamma & \,=\, c\,\left (b\, -\, a\right )\,.\end{array}$$This scheme for multiplication of complex numbers may or may not be faster than the original ON 2 scheme on a given CPU architecture.
- 4.
Note here, however, that the sometimes supported function sincos() may boost efficiency because both sinx as well as cosx are required. In addition, only one calculation of e y is needed because \(\cosh y\, =\, ({e}^{y}\, +\, {e}^{-y})/2\) and \(\sinh y\, =\, ({e}^{y}\, -\, {e}^{-y})/2\).
- 5.
This implementation uses solely range reduction, reflection and the polynomial approximation. To obtain the highest possible precision conserving characteristics, it may be better to use Taylor series approximations near the turning points at x = 0 and \(x\, =\, \pi \,/2\) after the range reduction. See [11] for further details on techniques for range reduction.
References
M. Abramowitz, I.A. Stegun, Handbook of Mathematical Functions, 9th Printing (Dover, New York, 1972)
B. Dawes, D. Abrahams, Boost C++ Libraries (2012), http://www.boost.org
A. Erdélyi, W. Magnus, F. Oberhettinger, F.G. Tricomi, Higher Transcendental Functions, vol. 1–3 (Krieger, New York, 1981)
A. Gil, J. Segura, N.M. Temme, Numerical Methods for Special Functions (Society for Industrial and Applied Mathematics, Philadelphia, 2007)
C. Hastings, Approximations for Digital Computers (Princeton University Press, Princeton, 1955)
IEEE Computer Society, IEEE Std 1003.1 – 2008, IEEE Standard 754-2008 (2008). Available at http://ieeexplore.ieee.org/servlet/opac?punumber=4610933
ISO/IEC, ISO/IEC 9899:1999: Programming Languages—C (International Organization for Standardization, Geneva, 1999)
ISO/IEC, ISO/IEC 29124:2010: Information Technology—Programming Languages, Their Environments and System Software Interfaces—Extensions to the C++ Library to Support Mathematical Special Functions (International Organization for Standardization, Geneva, 2010)
ISO/IEC, ISO/IEC 14882:2011: Information Technology—Programming Languages—C++ (International Organization for Standardization, Geneva, 2011)
D.E. Knuth, The Art of Computer Programming Volumes 1–3, 3rd edn. (Addison Wesley, Reading, 1998)
J.M. Muller, Elementary Functions: Algorithms and Implementation (Birkhäuser, Boston, 2006)
J.M. Muller, N. Brisebarre, F. de Dinechin, C.M. Jeannerod, V. Lefèvre, G. Melquiond, N. Revol, D. Stehlé, T. Torres, Handbook of Floating-Point Arithmetic (Birkhäuser, Boston, 2010)
S. Zhang, J. Jin, Computation of Special Functions (Wiley, New York, 1996)
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2013 Springer-Verlag Berlin Heidelberg
About this chapter
Cite this chapter
Kormanyos, C. (2013). Floating-Point Mathematics. In: Real-Time C++. Springer, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-34688-0_12
Download citation
DOI: https://doi.org/10.1007/978-3-642-34688-0_12
Published:
Publisher Name: Springer, Berlin, Heidelberg
Print ISBN: 978-3-642-34687-3
Online ISBN: 978-3-642-34688-0
eBook Packages: Computer ScienceComputer Science (R0)