Java - tutorial - 05/13 - math

revision:


math

The Math.max(x,y) method can be used to find the highest value of x and y

example:

      public class Main {
        public static void main(String[] args) {
          System.out.println(Math.max(5, 10));  // 10
        }
      }
    

The Math.min(x,y) method can be used to find the lowest value of x and y:

example:

      public class Main {
        public static void main(String[] args) {
          System.out.println(Math.min(5, 10));  // 5
        }
      }
    

The Math.sqrt(x) method returns the square root of x.

The Math.abs(x) method returns the absolute (positive) value of x.

The Math.random() method returns a random number between 0.0 (inclusive) and 1.0 (exclusive).

The Math.sqrt(x) method returns the square root of x.

All math methods

abs(x); Returns the absolute value of x; return type: double|float|int|long

acos(x); Returns the arccosine of x, in radians; return type: double

asin(x); Returns the arcsine of x, in radians; return type: double

atan(x); Returns the arctangent of x as a numeric value between -PI/2 and PI/2 radians; return type: double

atan2(y,x); Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).; return type: double

cbrt(x); Returns the cube root of x; return type: double

ceil(x); Returns the value of x rounded up to its nearest integer; return type: double

copySign(x, y); Returns the first floating point x with the sign of the second floating point y; return type: double

cos(x); Returns the cosine of x (x is in radians); return type: double

cosh(x); Returns the hyperbolic cosine of a double value; return type: double

cosh(x); Returns the hyperbolic cosine of a double value; return type: double

exp(x); Returns the value of Ex; return type: double

expm1(x); Returns ex -1; return type: double

floor(x); Returns the value of x rounded down to its nearest integer; return type: double

getExponent(x); Returns the unbiased exponent used in x; return type: int

hypot(x, y); Returns sqrt(x2 +y2) without intermediate overflow or underflow; return type: double

IEEEremainder(x, y); Computes the remainder operation on x and y as prescribed by the IEEE 754 standard; return type: double

log(x); Returns the natural logarithm (base E) of x; return type: double

log10(x); Returns the base 10 logarithm of x; return type: double

log1p(x); Returns the natural logarithm (base E) of the sum of x and 1; return type: double

max(x, y); Returns the number with the highest value; return type: double|float|int|long

min(x, y); Returns the number with the lowest value; return type: double|float|int|long

nextAfter(x, y); Returns the floating point number adjacent to x in the direction of y; return type: double|float

nextUp(x); Returns the floating point value adjacent to x in the direction of positive infinity; return type: double|float

pow(x, y); Returns the value of x to the power of y; return type: double

random(); Returns a random number between 0 and 1; return type: double

round(x); Returns the value of x rounded to its nearest integer; return type: int

rint(); Returns the double value that is closest to x and equal to a mathematical integer double

signum(x); Returns the sign of x; return type: double

sin(x); Returns the sine of x (x is in radians); return type: double

sinh(x); Returns the hyperbolic sine of a double value; return type: double

sqrt(x); Returns the square root of x; return type: double

tan(x); Returns the tangent of an angle; return type: double

tanh(x); Returns the hyperbolic tangent of a double value; return type: double

toDegrees(x); Converts an angle measured in radians to an approx. equivalent angle measured in degrees; return type: double

toRadians(x); Converts an angle measured in degrees to an approx. angle measured in radians; return type: double

ulp(x); Returns the size of the unit of least precision (ulp) of x; return type: double|float