In this tutorial, we're going to describe the Math class that provides helpful static methods for performing numeric operations such as exponential, logarithm, etc.
The first set of methods we'll cover are the basic math functions such as the absolute value, the square root, the maximum or the minimum between two values.
The abs() method returns the absolute value of a given value:
Math.abs(-5); // returns 5
Likewise, of others that we'll see next, abs() accepts as a parameter an int, long, float or double and returns the relative one.
Calculates and returns the value of the first argument raised to the power of the second one:
Math.pow(5,2); // returns 25
We discuss this method in more detail in here.
Returns the rounded positive square root of a double:
Math.sqrt(25); // returns 5
Similarly, cbrt() returns the cube root of a double:
Math.cbrt(125); // returns 5
As the method's name suggests, it returns the maximum between two values: