ABSTRACT

In this chapter we look at basic mathematical calculations in Java. You can think of these operations as those typically found in scientific or engineering calculator. For the purpose of this chapter we classify the fundamental operations into the following groups:

1. Basic arithmetic: the calculation of absolute value, maximum and minimum, IEEE-style remainder, rounding operations, and obtaining the constants π and e

2. Exponential functions: the calculation of powers and roots

3. Trigonometric functions: the calculation of trigonometric functions and arc-functions, conversions of radians to degrees and degrees to radians, and calculation of hyperbolic functions and arc-functions

4. Logarithms: the calculation of common and natural logarithms and the corresponding antilogarithms

5. Generation of random numbers

Most engineering calculations require decimal numbers. For this reason our emphasis in this chapter is on floating-point operations. These operations are located in several classes in the java.lang and java.math packages. Some of these classes have been discussed in previous chapters. In particular the classes Double and Float of java.lang, which were mentioned in Chapter 21, and the clases BigDecimal and BigInteger, whichwere the topic of Chapter 22. Here we are mainly concerned with the classes Math and StrictMath of java.math.