Commonly Used Methods of the Math Class

The operators +, -, *, /, and % give us a way to add, subtract, multiply, divide, and "mod" values together in java, but having to implement some of the more sophisticated functions of mathematics (like the square root or sine functions) with only these operators would be challenging indeed!

As such, the java.lang.Math class provides us access to many of these functions. The table below lists some of the more common among these. (There are more than just these in java.lang.Math, however -- one should consult the java API for the whole list.)

Method Returns
Math.sqrt(x) $\sqrt{x}$
Math.pow(x,y) $x^y$
Math.sin(x) $\sin x$
Math.cos(x) $\cos x$
Math.tan(x) $\tan x$
Math.asin(x) $\sin^{-1} x$
Math.acos(x) $\cos^{-1} x$
Math.atan(x) $\tan^{-1} x$
Math.exp(x) $e^x$
Math.log(x) $\ln x$
Math.log10(x) $\log x$
Math.round(x) $\textrm{the closest integer to } x\textrm{, as a}$ long
Math.abs(x) $|x|$
Math.max(x,y) $\textrm{The maximum of the two values}$
Math.min(x,y) $\textrm{The minimum of the two values}$

Additionally, the java.lang.Math class provides two very frequently used constants that you might recognize:

Constant Type Value
Math.PI double 3.14159265358979323846
Math.E double 2.7182818284590452354