Java Math signum() Method Last Updated : 13 May, 2025 Comments Improve Suggest changes Like Article Like Report The Math.signum() method is a part of the java.lang.Math package. This method returns the sign function of a value passed to it as an argument. In this article, we are going to discuss how this method works for regular values and for special cases such as infinity and NaN.Special Cases:If the argument is greater than zero, the result will be 1.0.If the argument is equal to zero, the result will be 0.If the argument is less than zero, the result will be -1.0.If the argument is NaN, the result will be NaN.If the argument passed is positive zero or negative zero, then the result will be the same as that of the argument. These special cases make sure that the signum() methods work correctly.Syntax of signum() Methodpublic static double signum(double d)Parameter: This method takes a single parameter d of type double, it is the values whose signum function needs to be calculated.Return Type: This method returns the signum function value of the argument passed to it.Now, we are going to discuss some examples for better understanding.Examples of Java Math signum() MethodExample 1: In this example, we will see the basic usage of signum() method. Java // Java program to demonstrate the // working of Math.signum() method import java.lang.Math; class Geeks { public static void main(String args[]) { // when the argument is greater than zero double a = 30; System.out.println(Math.signum(a)); // when the argument is equals to zero a = 0.0; System.out.println(Math.signum(a)); // when the argument is less than zero a = -30; System.out.println(Math.signum(a)); } } Output1.0 0.0 -1.0 Explanation: Here, for a positive number we will get 1.0 and for zero we will get zero and for negative number we will get -1.0 as an output.Example 2: In this example, we will see how signum() method handles special cases like NaN, positive zero and negative zero. Java // Java program to demonstrate handling // NaN, positive zero or negative zero import java.lang.Math; public class Geeks { public static void main(String[] args) { double nan = Double.NaN; double res; // Here the argument is NaN res = Math.signum(nan); System.out.println(res); // Here the argument is positive zero res = Math.signum(0.0); System.out.println(res); // Here the argument is negative zero res = Math.signum(-0.0); System.out.println(res); } } OutputNaN 0.0 -0.0 Explanation: Here, we are handling the special cases, for NaN we will get NaN and for positive zero we will get 0.0 and for negative zero we will get -0.0 Comment More infoAdvertise with us Next Article StrictMath signum() Method in Java B barykrg Follow Improve Article Tags : Java Java-lang package java-math Practice Tags : Java Similar Reads Long signum() Method in Java The signum function also known as sign function is an odd mathematical function that extracts the sign of a real number. The java.lang.Long.signum() method is used to get the signum function of the specified long value. For a positive value, a negative value and zero, the method returns 1, -1 and 0 2 min read Java Math negateExact() method The java.lang.Math.negateExact() is a built-in function in Java that returns the negation of the argument, throwing an exception if the result overflows the specified datatype, either long or int, depending on which data type has been used on the method argument. Why does it Overflow?It throws an er 2 min read Integer signum() Method in Java The signum function is an odd mathematical function that extracts the sign of a real number. The signum function is also known as sign function. The Integer.signum() method of java.lang returns the signum function of the specified integer value. For a positive value, a negative value and zero the me 3 min read BigDecimal signum() Method in Java The java.math.BigDecimal.signum() is an inbuilt method in Java that returns the signum function of this BigDecimal. The sign function or signum function is an odd mathematical function that extracts the sign of a real number. In mathematical expressions, the sign function is often represented as sgn 2 min read Java signum() method with Examples The Math.signum() method is a part of the java.lang.Math package. This method returns the sign function of a value passed to it as an argument. In this article, we are going to discuss how this method works for regular values and for special cases such as infinity and NaN.Special Cases:If the argume 2 min read StrictMath signum() Method in Java The signum(double num) is an inbuilt method of StrictMath class in Java which is used to get the signum method of the argument which means: The result is zero if the argument is zero. The result 1.0 when the argument is greater than zero. The result is -1.0 if the argument is less than zero. Syntax 3 min read BigInteger signum() Method in Java prerequisite : BigInteger Basics The java.math.BigInteger.signum() method helps us to identify whether a BigInteger is positive or zero or negative. It returns one of the following values depending on the following conditions: returns -1 when number is negativereturns 0 when number is zeroreturns +1 2 min read Month minus() method in Java The minus() method is a built-in method of the Month ENUM which is used to get a month before the current month by a specific number of months. That is, this method returns the month before the specified number of months from this month. Syntax: public Month minus(long months) Parameters: This metho 1 min read Java Math abs() method with Examples Absolute value refers to the positive value corresponding to the number passed as in arguments. Now geek you must be wondering what exactly it means so by this it is referred no matter what be it positive or negative number been passed for computation, the computation will occur over the positive co 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 Like