Download java lang StrictMath Class in Formats
QR Code for this Page
java lang StrictMath Class

java lang StrictMath Class

java.lang.StrictMath Class

StrictMath Class in Java

The class StrictMath contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.

The Java math library is defined with respect to fdlibm version 5.3. Where fdlibm provides more than one definition for a function (such as acos), use the "IEEE 754 core function" version (residing in a file whose name begins with the letter e). The methods which require fdlibm semantics are sin, cos, tan, asin, acos, atan, exp, log, log10, cbrt, atan2, pow, sinh, cosh, tanh, hypot, expm1, and log1p.

In this Java StrictMath class tutorial you can learn how to use StrictMath class. You need not to create instance for StrictMath class. Because all the methods in StrictMath class are static methods. All the static methods are called with the class name.

What is java.lang.StrictMath in Java ?

The java.lang.StrictMath is a class in Java . This java.lang.StrictMath class is available in java.lang package . The java.lang.StrictMath class contains methods for performing basic numeric operations such as the elementary exponential , logarithm , square root , and trigonometric functions .

What is the package name which contains StrictMath class ?

The Java package that contains the StrictMath class is java.lang.StrictMath . This class is used to perform almost all basic numeric operations . It is defined as public final class StictMath .

Do I need to import StrictMath in Java ?

Since StrictMath class is in the java.lang package , the StrictMath class does not need to be imported . However , in programs extensively utilizing these functions , a static import can be used . There is no need to explicitly import java.lang.StrictMath as its imported implicitly . All its methods are static . This explanation also useful for how to import java.lang.StrictMath ? .

What are the StrictMath class methods in Java ?

java.lang.StrictMath Class methods helps to perform the numeric operations like square, square root, cube, cube root, exponential and trigonometric operations . Following are the List of java.lang.StrictMath Class Methods or functions .

Modifier and Type Method Description
static double java.lang.StrictMath.abs(double a) Returns the absolute value of a double value.
static float java.lang.StrictMath.abs(float a) Returns the absolute value of a float value.
static int java.lang.StrictMath.abs(int a) Returns the absolute value of an int value.
static long java.lang.StrictMath.abs(long a) Returns the absolute value of a long value.
static double java.lang.StrictMath.acos(double a) Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.
static int java.lang.StrictMath.addExact(int x, int y) Returns the sum of its arguments, throwing an exception if the result overflows an int.
static long java.lang.StrictMath.addExact(long x, long y) Returns the sum of its arguments, throwing an exception if the result overflows a long.
static double java.lang.StrictMath.asin(double a) Returns the arc sine of a value; the returned angle is in the range -pi/2 through pi/2.
static double java.lang.StrictMath.atan(double a) Returns the arc tangent of a value; the returned angle is in the range -pi/2 through pi/2.
static double java.lang.StrictMath.atan2(double y, double x) Returns the angle theta from the conversion of rectangular coordinates (xy) to polar coordinates (r, theta).
static double java.lang.StrictMath.cbrt(double a) Returns the cube root of a double value.
static double java.lang.StrictMath.ceil(double a) Returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.
static double java.lang.StrictMath.copySign(double magnitude, double sign) Returns the first floating-point argument with the sign of the second floating-point argument.
static float java.lang.StrictMath.copySign(float magnitude, float sign) Returns the first floating-point argument with the sign of the second floating-point argument.
static double java.lang.StrictMath.cos(double a) Returns the trigonometric cosine of an angle.
static double java.lang.StrictMath.cosh(double x) Returns the hyperbolic cosine of a double value.
static double java.lang.StrictMath.exp(double a) Returns Euler's number e raised to the power of a double value.
static double java.lang.StrictMath.expm1(double x) Returns ex -1.
static double java.lang.StrictMath.floor(double a) Returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.
static int java.lang.StrictMath.floorDiv(int x, int y) Returns the largest (closest to positive infinity) int value that is less than or equal to the algebraic quotient.
static long java.lang.StrictMath.floorDiv(long x, long y) Returns the largest (closest to positive infinity) long value that is less than or equal to the algebraic quotient.
static int java.lang.StrictMath.floorMod(int x, int y) Returns the floor modulus of the int arguments.
static long java.lang.StrictMath.floorMod(long x, long y) Returns the floor modulus of the long arguments.
static int java.lang.StrictMath.getExponent(double d) Returns the unbiased exponent used in the representation of a double.
static int java.lang.StrictMath.getExponent(float f) java.lang.StrictMath.Returns the unbiased exponent used in the representation of a float.
static double java.lang.StrictMath.hypot(double x, double y) Returns sqrt(x2 +y2) without intermediate overflow or underflow.
static double java.lang.StrictMath.IEEEremainder(double f1, double f2) Computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.
static double java.lang.StrictMath.log(double a) Returns the natural logarithm (base e) of a double value.
static double java.lang.StrictMath.log10(double a) Returns the base 10 logarithm of a double value.
static double java.lang.StrictMath.log1p(double x) Returns the natural logarithm of the sum of the argument and 1.
static double java.lang.StrictMath.max(double a, double b) Returns the greater of two double values.
static float java.lang.StrictMath.max(float a, float b) Returns the greater of two float values.
static int java.lang.StrictMath.max(int a, int b) Returns the greater of two int values.
static long java.lang.StrictMath.max(long a, long b) Returns the greater of two long values.
static double java.lang.StrictMath.min(double a, double b) Returns the smaller of two double values.
static float java.lang.StrictMath.min(float a, float b) Returns the smaller of two float values.
static int java.lang.StrictMath.min(int a, int b) Returns the smaller of two int values.
static long java.lang.StrictMath.min(long a, long b) Returns the smaller of two long values.
static int java.lang.StrictMath.multiplyExact(int x, int y) Returns the product of the arguments, throwing an exception if the result overflows an int.
static long java.lang.StrictMath.multiplyExact(long x, long y) Returns the product of the arguments, throwing an exception if the result overflows a long.
static double java.lang.StrictMath.nextAfter(double start, double direction) Returns the floating-point number adjacent to the first argument in the direction of the second argument.
static float java.lang.StrictMath.nextAfter(float start, double direction) Returns the floating-point number adjacent to the first argument in the direction of the second argument.
static double java.lang.StrictMath.nextDown(double d) Returns the floating-point value adjacent to d in the direction of negative infinity.
static float java.lang.StrictMath.nextDown(float f) Returns the floating-point value adjacent to f in the direction of negative infinity.
static double java.lang.StrictMath.nextUp(double d) Returns the floating-point value adjacent to d in the direction of positive infinity.
static float java.lang.StrictMath.nextUp(float f) Returns the floating-point value adjacent to f in the direction of positive infinity.
static double java.lang.StrictMath.pow(double a, double b) Returns the value of the first argument raised to the power of the second argument.
static double java.lang.StrictMath.random() Returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.
static double java.lang.StrictMath.rint(double a) Returns the double value that is closest in value to the argument and is equal to a mathematical integer.
static long java.lang.StrictMath.round(double a) Returns the closest long to the argument, with ties rounding to positive infinity.
static int java.lang.StrictMath.round(float a) Returns the closest int to the argument, with ties rounding to positive infinity.
static double java.lang.StrictMath.scalb(double d, int scaleFactor) Returns d ×2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the double value set.
static float java.lang.StrictMath.scalb(float f, int scaleFactor) Returns f ×2scaleFactor rounded as if performed by a single correctly rounded floating-point multiply to a member of the float value set.
static double java.lang.StrictMath.signum(double d) Returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.
static float java.lang.StrictMath.signum(float f) Returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.
static double java.lang.StrictMath.sin(double a) Returns the trigonometric sine of an angle.
static double java.lang.StrictMath.sinh(double x) Returns the hyperbolic sine of a double value.
static double java.lang.StrictMath.sqrt(double a) Returns the correctly rounded positive square root of a double value.
static int java.lang.StrictMath.subtractExact(int x, int y) Returns the difference of the arguments, throwing an exception if the result overflows an int.
static long java.lang.StrictMath.subtractExact(long x, long y) Returns the difference of the arguments, throwing an exception if the result overflows a long.
static double java.lang.StrictMath.tan(double a) Returns the trigonometric tangent of an angle.
static double java.lang.StrictMath.tanh(double x) Returns the hyperbolic tangent of a double value.
static double java.lang.StrictMath.toDegrees(double angrad) Converts an angle measured in radians to an approximately equivalent angle measured in degrees.
static int java.lang.StrictMath.toIntExact(long value) Returns the value of the long argument; throwing an exception if the value overflows an int.
static double java.lang.StrictMath.toRadians(double angdeg) Converts an angle measured in degrees to an approximately equivalent angle measured in radians.
static double java.lang.StrictMath.ulp(double d) Returns the size of an ulp of the argument.
static float java.lang.StrictMath.ulp(float f) Returns the size of an ulp of the argument.

java.lang.StrictMath Class Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*  Java StrictMath Class Example
    Save with file name StrictMathExample.java  */
  
public class StrictMathExample
{
  public static void main(String args[])
  {
    //IF THE VALUE IS NEGITIVE IT RETURNS POSITIVE VALUE
    System.out.println("Absolute : " + StrictMath.abs(-100.50));
    //IT INCREASE THE VALUE TO NEAREST INTEGER
    System.out.println("ceil : " + StrictMath.ceil(100.55));
    //IT DECREASE THE VALUE TO NEAREST INTEGER
    System.out.println("floor : " + StrictMath.floor(100.55));
    //IT RETURNS MAX NUMBER WITH IN THE GIVEN NUMBERS
    System.out.println("max : " + StrictMath.max(100,200));
    //IT RETURNS MIN NUMBER WITH IN THE GIVEN NUMBERS
    System.out.println("min : " + StrictMath.min(100,200));
    //IT RETURNS RANDOM NUMBER
    System.out.println("random : " + StrictMath.random());
    //IT RETURNS WITHOUT FLOATING POINT
    System.out.println("round : " + StrictMath.round(100.75));
    //IT RETURNS SQUARE ROOT
    System.out.println("sqrt : " + StrictMath.sqrt(2));
    //IT RETURNS PI VALUE (22/7)
    System.out.println("PI : " + StrictMath.PI);
    //RETURNS NATURAL LOGARITHM
    System.out.println("log : " + StrictMath.log(10.55));
    //RETURNS BASE 10 LOGARITHM
    System.out.println("log10 : " + StrictMath.log10(10.55));
    //RETURNS NATURAL LOGARITHM OF SUM OF THE ARGUMENT AND 1
    System.out.println("log1p : " + StrictMath.log1p(10.55));
  }
}

Following Java StrictMath class example you can learn how to use trigonometric functions in java.

java.lang.StrictMath Class Example 2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*  Java StrictMath Class Example
    Save with file name StrictMathExample2.java */
  
public class StrictMathExample2
{
  public static void main(String args[])
  {
    //RETURNS ARC COSINE
    System.out.println("acos : " + StrictMath.acos(0.4));
    //RETURNS ARC SINE
    System.out.println("asin : " + StrictMath.asin(0.4));
    //RETURNS ARC TANGENT VALUE
    System.out.println("atan : " + StrictMath.atan(45));
    //RETURNS COSINE OF AN ANGLE
    System.out.println("cos : " + StrictMath.cos(45));
    //RETURNS HYPERBOLIC COSINE
    System.out.println("cosh : " + StrictMath.cosh(45));
    //RETURNS SINE OF AN ANGLE
    System.out.println("sin : " + StrictMath.sin(45));
    //RETURNS HYPERBOLIC SINE
    System.out.println("sinh : " + StrictMath.sinh(45));
    //RETURNS TANGENT OF AN ANGLE
    System.out.println("tan : " + StrictMath.tan(45));
    //RETURNS HYPERBOLIC TANGENT
    System.out.println("tanh : " + StrictMath.tanh(45));
    //RETURNS DEGREES
    System.out.println("toDegrees : " + StrictMath.toDegrees(45));
    //RETURNS RADIANS
    System.out.println("toRadians : " + StrictMath.toRadians(45));
  }
}
Download java lang StrictMath Class in Formats