StrictMath signum() Method in Java

- 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.
// Java praogram to illustrate the// java.lang.StrictMath.signum(double)importjava.lang.*;ÂÂpublicclassGeeks {   Âpublicstaticvoidmain(String[] args)   Â{       Âdoublenum1 =46.82d, num2 =0.0d, num3 = -0.0d, num4 = -18.2d;       Â// It returns 1.0 since the argument is greater than zero       Âdoublesig_val = StrictMath.signum(num1);       ÂSystem.out.println("Signum Value = "+ sig_val);       Âsig_val = StrictMath.signum(num2);       ÂSystem.out.println("Signum Value = "+ sig_val);       Âsig_val = StrictMath.signum(num3);       ÂSystem.out.println("Signum Value = "+ sig_val);       Âsig_val = StrictMath.signum(num4);       ÂSystem.out.println("Signum Value = "+ sig_val);   Â}}Output:Signum Value = 1.0 Signum Value = 0.0 Signum Value = -0.0 Signum Value = -1.0
- 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:
// Java praogram to illustrate the// java.lang.StrictMath.signum(float)importjava.lang.*;ÂÂpublicclassGeeks {   Âpublicstaticvoidmain(String[] args)   Â{       Âfloatnum1 =7.22f, num2 =0.0f, num3 = -0.0f, num4 = -18.11f;       Â// It returns 1.0 since the argument is greater than zero       Âfloatsig_val = StrictMath.signum(num1);       ÂSystem.out.println("Signum Value = "+ sig_val);       Âsig_val = StrictMath.signum(num2);       ÂSystem.out.println("Signum Value = "+ sig_val);       Âsig_val = StrictMath.signum(num3);       ÂSystem.out.println("Signum Value = "+ sig_val);       Âsig_val = StrictMath.signum(num4);       ÂSystem.out.println("Signum Value = "+ sig_val);   Â}}Output:Signum Value = 1.0 Signum Value = 0.0 Signum Value = -0.0 Signum Value = -1.0



