Name

Math

Synopsis

This class defines constants for the mathematical values e and π and defines static methods for floating-point trigonometry, exponentiation, and other operations. It is the equivalent of the C <math.h> functions. It also contains methods for computing minimum and maximum values and for generating pseudorandom numbers.

Most methods of Math operate on float and double floating-point values. Remember that these values are only approximations of actual real numbers. To allow implementations to take full advantage of the floating-point capabilities of a native platform, the methods of Math are not required to return exactly the same values on all platforms. In other words, the results returned by different implementations may differ slightly in the least-significant bits. As of Java 1.3, applications that require strict platform-independence of results should use StrictMath instead.

Java 5.0 adds several methods including log10( ) to compute the base-ten logarithm, cbrt( ) to compute the cube root of a number, and signum( ) to compute the sign of a number as well as sinh( ) , cosh( ), and tanh( ) hyperbolic trigonometric functions.

public final class Math {
// No Constructor
                  // Public Constants
     public static final double E;         =2.718281828459045
     public static final double PI;        =3.141592653589793
// Public Class Methods
     public static int abs(int a);  
     public static long abs(long a);  
     public static float abs(float a);  
     public static double abs(double a); public static ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.