Long signum() Method in Java Last Updated : 05 Dec, 2018 Comments Improve Suggest changes Like Article Like Report 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 respectively. Syntax : public static int signum(long num) Parameters: The method accepts one parameter num of long type on which the signum operation is to be performed. Return Value: The method returns the signum function of the specified long value. If the specified value is: Negative, the method returns -1. Zero, the method returns 0. Positive, the method returns 1. Examples: Input: (Long) 2731766 Output: 1 Input: (Long) -233611 Output: -1 Input: (Long) 0 Output: 0 Below programs illustrate the Java.lang.Long.signum() Method: Program 1: java // Java program to illustrate the // Java.lang.Long.signum() Method import java.lang.*; public class Geeks { public static void main(String[] args) { // It will return 1 as long value is greater than 1 System.out.println(Long.signum(36565531)); // It will return -1 as long value is less than 1 System.out.println(Long.signum(-628127)); // Returns 0 as long value is equal to 0 System.out.println(Long.signum(0)); } } Output: 1 -1 0 Program 2: For decimal value and string. java // Java program to illustrate the // Java.lang.Long.signum() Method import java.lang.*; public class Geeks { public static void main(String[] args) { // It will return compile time error System.out.println(Long.signum(36565.531)); // It will return compile time error System.out.println(Long.signum("628127")); } } Output: prog.java:10: error: incompatible types: possible lossy conversion from double to long System.out.println(Long.signum(36565.531)); ^ prog.java:13: error: incompatible types: String cannot be converted to long System.out.println(Long.signum("628127")); ^ Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 2 errors Comment More infoAdvertise with us Next Article Long signum() Method in Java A ankita_chowrasia Follow Improve Article Tags : Java Java-lang package Java-Functions java-Long Practice Tags : Java Similar Reads 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 Month length() method in Java The length() method is a built-in method of the Month ENUM which is used to get the number of days in this month instance. The number of days in a month can be 28, 30 or 31. Number of days in February in a leap year is 29. This method accepts a boolean flag variable which indicates whether this Year 1 min read LongStream sum() in Java LongStream sum() returns the sum of elements in this stream. This is a special case of a reduction. LongStream sum() is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect. Note : A reduction operation (also called a fold) takes a sequence of input elements and 2 min read Month maxLength() method in Java The maxLength() method is a built-in method of the Month ENUM which is used to get the maximum length of this month in number of days. For example, February can have both 28 days and 29 days depending on whether this year is a leap year or not. Therefore, this method will return 29 for February as m 1 min read Long longValue() Method in Java The java.lang.Long.longValue() is an inbuilt method of the Long class in Java which returns the value of this Long object as a long after the conversion.Syntax: public long longValue() Parameters: This method does not take any parameters.Return Value: This method will return the numeric value repres 2 min read Like