Java signum() method with Examples Read Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report 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. Syntax: 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. // Java program to demonstrate working // of java.lang.Math.signum() method import java.lang.Math; class Gfg { // driver code 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; System.out.println(Math.signum(a)); // when the argument is less than zero a = -30; System.out.println(Math.signum(a)); } } Output: 1.0 0 -1.0 Example 2 : To show working of java.lang.Math.signum() method when argument is NaN. // Java program to demonstrate working // of java.lang.Math.signum() method import java.lang.Math; // importing java.lang package public class GFG { public static void main(String[] args) { double nan = Double.NaN; double result; // Here argument is NaN, output will be NaN result = Math.signum(nan); System.out.println(result); // Here argument is positive zero result = Math.signum(0); System.out.println(result); // Here argument is negative zero result = Math.signum(-0); System.out.println(result); } } Output: NaN 0.0 0.0 Feeling lost in the vast world of Backend Development? It's time for a change! Join our Java Backend Development - Live Course and embark on an exciting journey to master backend development efficiently and on schedule. What We Offer: Comprehensive Course Expert Guidance for Efficient Learning Hands-on Experience with Real-world Projects Proven Track Record with 100,000+ Successful Geeks Last Updated : 09 Apr, 2018 Like Article Save Article Previous Java Math IEEEremainder() method with Examples Next Java Math getExponent() method with Example Share your thoughts in the comments Add Your Comment Please Login to comment...