VOOZH about

URL: https://www.geeksforgeeks.org/java/strictmath-signum-method-in-java/

⇱ StrictMath signum() Method in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

StrictMath signum() Method in Java

Last Updated : 3 Aug, 2018
  1. 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 :
    public static double signum(double num)
    Parameters : The method accepts a single parameter num of double type representing the parameter whose signum is to be returned. Return Value : The method returns signum function of the argument num. It also gives rise to two different results:
    • The result is NaN when the first argument is NaN .
    • The result is the same as the argument num when num is positive zero or negative zero.
    Examples:
    Input: num = 72.88d
    Output: 1.0
    
    Input: num = -72.88d
    Output: -1.0
    
    Input: num = 0.0d
    Output: 0.0
    
    Below program illustrates the working of java.lang.StrictMath.signum(double) method.
    Output:
    Signum Value = 1.0
    Signum Value = 0.0
    Signum Value = -0.0
    Signum Value = -1.0
    
  2. The signum(float 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 :
    public static float signum(float num)
    Parameters : The method accepts a single parameter num of float type representing the parameter whose signum is to be returned. Return Value : The method returns signum function of the argument num. It also gives rise to two different results:
    • The result is NaN when the first argument is NaN .
    • The result is the same as the argument num when num is positive zero or negative zero.
    Examples:
    Input: num = 11.8f
    Output: 1.0
    
    Input: num = -55.88f
    Output: -1.0
    
    Input: num = 0.0f
    Output: 0.0
    
    Below program illustrates the working of java.lang.StrictMath.signum(float) method:
Output:
Signum Value = 1.0
Signum Value = 0.0
Signum Value = -0.0
Signum Value = -1.0
Comment