Java signum() method with Examples
The java.lang.Math.signum() returns the Sign function of a value passed to it as argument. The signum() function returns the following values depending on the argument passed to it:
- If the argument passed is greater than zero, then the signum() function will return 1.0.
- If the argument passed is equal to zero, then the signum() function will return 0.
- If the argument passed is less than zero, then the signum() function will return -1.0.
Note: If the argument passed is NaN, then the result is NaN. If the argument passed is positive zero or negative zero then the result will be same as that of the argument.
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
public static double signum(double d) Parameter : a : the value whose signum function is to be returned. Return : This method returns the signum function value of the argument passed to it.
Example 1 : To show working of java.lang.Math.signum() method.
1.0 0 -1.0
Example 2 : To show working of java.lang.Math.signum() method when argument is NaN.
NaN 0.0 0.0