Home >>Java Math Methods >Java Math.signum() method

Java Math.signum() method

Java Math.signum() method

Java Math.signum() method in Java Math is used for finding the sign of a value given.

Syntax:

public static double signum(double x)  
public static float signum(float x)  

Parameter

x = This parameter is used for a floating-point value whose signum is to be returned

Return

It is used to returns the signum function of an argument

  1. This method will return Zero if the argument is positive or negative Zero.
  2. If the argument is positive the method returns Positive 1.
  3. If the statement is Negative value, it returns Negative 1.
  4. This method returns NaN if the argument is NaN.

Java Math.signum method Example 1


public class MyClass
{  
public static void main(String[] args)   
{  
double x= 23.5;  
System.out.println(Math.signum(x));  
}  
}  

Output:-
1.0

Java Math.signum method Example 2


public class MyClass
{  
public static void main(String[] args)   
{  
double x= -15.8;  
System.out.println(Math.signum(x));  
}  
}  

Output:-
-1.0