Java.lang.Math Class in Java | Set 2 Last Updated : 13 Sep, 2023 Comments Improve Suggest changes Like Article Like Report Java.lang.Math Class in Java | Set 1 More Methods: cosh() : java.lang.Math.cosh() method returns the hyperbolic cosine of the argument passed. Special cases : Result is NaN, if argument is NaN. Result is 1.0, if the argument is zero. Result is +ve infinity, if argument is infinite. Syntax: public static double cosh(double arg) Parameters: arg - The number whose hyperbolic cosine is to be returned. Returns: the hyperbolic cosine of the argument arg. decrementExact() : java.lang.Math.decrementExact() method decrements the value of passed argument by one. Syntax: public static int decrementExact(int arg) or public static long decrementExact(long arg) Parameters: arg - argument passed. Returns: return argument decremented by one. Throws: Exception if the result overflows long or int datatype, according to the argumented data type. exp() : java.lang.Math.exp(double arg) method returns the Euler’s number raised to the power of double argument. Important cases: Result is NaN, if argument is NaN. Result is +ve infinity, if the argument is +ve infinity. Result is +ve zero, if argument is -ve infinity. Syntax: public static double exp(double arg) Parameters: arg - argument passed. Returns: Euler’s number raised to the power of passed argument Java code explaining exp(), decrementExact(), cosh() method in lang.Math class. Java // Java program explaining lang.Math class methods // exp(), decrementExact(), cosh() import java.math.*; public class NewClass { public static void main(String[] args) { // Use of cosh() method double value = 2; double coshValue = Math.cosh(value); System.out.println("Hyperbolic Cosine of " + coshValue); System.out.println(""); // Use of decrementExact() method int result = Math.decrementExact(3051); System.out.println("Use of decrementExact() : " + result); System.out.println(""); // Use of exp() method // declare the exponent to be used double exponent = 34; // raise e to exponent declared double expVal = Math.exp(exponent); System.out.println("Value of exp : "+ expVal); } } Output: Using addExact() : 9 acos value of Asini : NaN acos value of Asinj : 0.054858647341251204 cube root : 6.0 incrementExact() : java.lang.Math.incrementExact() method returns the argument by incrementing it's value. Syntax: public static int incrementExact(int arg) or public static long incrementExact(long arg) Parameters: arg - the argument Returns: incremented value of the argument log10() : java.lang.Math.log10() method returns the base10 logarithmic value of the passed argument. Syntax: public static double log(double arg) Parameters: arg - argument passed. Returns: base10 logarithmic value of the argument passed. pow() : java.lang.Math.pow(double b, double e) method returns the value as be Syntax: public static double pow(double b,double e) Parameters: b : base e : exponent Returns: value as baseexponent JAVA code explaining incrementExact(), log10(), pow() method in lang.Math class. Java // Java program explaining lang.MATH class methods // incrementExact(), log10(), pow() import java.lang.*; public class NewClass { public static void main(String[] args) { // Use of incrementExact() method int f1 = 30, f2 = -56; f1 =Math.incrementExact(f1); System.out.println("Incremented value of f1 : "+f1); f2 =Math.incrementExact(f2); System.out.println("Incremented value of f2 : "+f2); System.out.println(""); // Use of log10() method double value = 10; double logValue = Math.log10(value); System.out.println("Log10 value of 10 : "+logValue); System.out.println(""); // Use of pow() method double b = 10, e = 2; double power = Math.pow(b,e); System.out.println("Use of pow() : "+power); } } Output : Incremented value of f1 : 31 Incremented value of f2 : -55 Log10 value of 10 : 1.0 Use of pow() : 100.0 signum() : java.lang.Math.signum() method returns the signum value of the argument passed. -1 if x < 0 signum fun(x) = 0 if x = 0 1 if x > 0 Note: Result is NaN, if passed the argument is NaN.; Syntax: public static double signum(double x) or public static float signum(float x) Parameters: x - the argument whose signum value we need Returns: signum value of x round() : java.lang.Math.round() method round off the passed argument upto closest decimal places. Note: Result is 0, if the argument is NaN. Syntax: public static long round(long arg) or public static double round(double arg) Parameters: arg - argument needs to round off Returns: round off value of the argument max() : java.lang.Math.max(double v1, double v2) method returns the greater value out of the two passed argument values. This method just compares using magnitude without considering any sign. Syntax: public static double max(double v1, double v2) Parameters: v1 - first value v2 - second value Returns: v1 or v2 based on which number is greater. It can return either of the two if v1 = v2. Java code explaining signum(), round(), max() method in lang.Math class. Java // Java code explaining the lang.Math Class methods // signum(), round(), max() import java.lang.*; public class NewClass { public static void main(String args[]) { // Use of signum() method double x = 10.4556, y = -23.34789; double signm = Math.signum(x); System.out.println("Signum of 10.45 = "+signm); signm = Math.signum(y); System.out.println("Signum of -23.34 = "+signm); System.out.println(""); // Use of round() method double r1 = Math.round(x); System.out.println("Round off 10.4556 = "+r1); double r2 = Math.round(y); System.out.println("Round off 23.34789 = "+r2); System.out.println(""); // Use of max() method on r1 and r2 double m = Math.max(r1, r2); System.out.println("Max b/w r1 and r2 = "+r2); } } Output: Signum of 10.45 = 1.0 Signum of -23.34 = -1.0 Round off 10.4556 = 10.0 Round off 23.34789 = -23.0 Max b/w r1 and r2 = -23.0 log1p() : java.lang.Math.log1p() method returns natural log of (passed argument + 1). Syntax: public static double log1p(double arg) Parameters: arg - the argument Returns: log of (argument + 1). This result is within 1 unit in the last place of exact result. ulp() : java.lang.Math.ulp() method returns Unit of least precision(ulp) ie. the least distance between two floating point numbers. Here, it is the least distance b/w the argument and next larger value. Syntax: public static double ulp(double arg) or public static float ulp(float arg) Parameters: arg - argument passed. Returns: least distance b/w the argument and next larger value. Java code explaining ulp(), log1p() method in lang.Math class. Java // Java code explaining the lang.Math Class methods // ulp(), log1p() import java.lang.*; public class NewClass { public static void main(String args[]) { // Use of ulp() method double x = 34.652, y = -23.34789; double u = Math.ulp(x); System.out.println("ulp of 34.652 : "+u); u = Math.ulp(y); System.out.println("ulp of -23.34789 : "+u); System.out.println(""); // Use of log() method double l = 99; double l1 = Math.log1p(l); System.out.println("Log of (1 + 99) : "+l1); l1 = Math.log(100); System.out.println("Log of 100 : "+l1); } } Output: ulp of 34.652 : 7.105427357601002E-15 ulp of -23.34789 : 3.552713678800501E-15 Log of (1 + 99) : 4.605170185988092 Log of 100 : 4.605170185988092 . Comment More infoAdvertise with us Next Article Java.lang.Math Class in Java | Set 2 M Mohit Gupta_OMG Improve Article Tags : Java Java-lang package Practice Tags : Java Similar Reads Java.lang.Class class in Java | Set 1 Java provides a class with name Class in java.lang package. Instances of the class Class represent classes and interfaces in a running Java application. The primitive Java types (boolean, byte, char, short, int, long, float, and double), and the keyword void are also represented as Class objects. It 15+ min read Java.lang.Number Class in Java Most of the time, while working with numbers in java, we use primitive data types. But, Java also provides various numeric wrapper sub classes under the abstract class Number present in java.lang package. There are mainly six sub-classes under Number class.These sub-classes define some useful method 9 min read Java.lang.StrictMath class in Java | Set 2 Java.lang.StrictMath Class in Java | Set 1More methods of java.lang.StrictMath class 13. exp() : java.lang.StrictMath.exp(double arg) method returns the Eulerâs number raised to the power of double argument. Important cases: Result is NaN, if argument is NaN.Result is +ve infinity, if the argument i 6 min read Java.lang.StrictMath class in Java | Set 1 StrictMath Class methods helps to perform the numeric operations like square, square root, cube, cube root, exponential and trigonometric operations Declaration : public final class StrictMath extends Object NaN argument?A constant holding a Not-a-Number (NaN) value of type double. It is equivalent 8 min read Java.util.Locale Class in Java | Set 2 Java.util.Locale Class in Java | Set 1 More methods: getDisplayVariant() : java.util.Locale.getDisplayVariant() displays variant of the Locale Syntax : public final String getDisplayVariant() Parameters : ---- Return : ----------- getDisplayVariant(Locale in) : java.util.Locale.Locale in(Locale in) 3 min read Java.Lang.Double Class in Java Double class is a wrapper class for the primitive type double which contains several methods to effectively deal with a double value like converting it to a string representation, and vice-versa. An object of the Double class can hold a single double value. Double class is a wrapper class for the pr 4 min read Java.lang package in Java Java.lang package in JavaProvides classes that are fundamental to the design of the Java programming language. The most important classes are Object, which is the root of the class hierarchy, and Class, instances of which represent classes at run time. Following are the Important Classes in Java.lan 3 min read java.math class and its methods | Set 1 Math class provides mathematical functions to perform basic numeric operations such as exponential, logarithm, square root, and trigonometric functions. cosh, sin, tan, abs, bitLength, multiply and many more. Implementations of the functions of Math class do not return bit-for-bit same results. Henc 4 min read java.math class and its methods | Set 3 java.math class and its methods | Set 1 java.math class and its methods | Set 2 ceil() : java.math.ceil(double a) method returns the smallest possible value which is either greater or equal to the argument passed. The returned value is a mathematical integer.Special Case : Result is same, if the ret 5 min read Math class methods in Java with Examples | Set 2 java.math class and its methods | Set 1 java.math class methods discussed in this article : abs() : java.math.abs() method returns the absolute value of any type of argument passed. This method can handle all the data types. Special Case : Result is positive zero, if the argument is positive zero or 6 min read Like