Related Articles

# StrictMath signum() Method in Java

• Last Updated : 03 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.

 `// Java praogram to illustrate the``// java.lang.StrictMath.signum(double)``import` `java.lang.*;`` ` `public` `class` `Geeks {`` ` `    ``public` `static` `void` `main(String[] args)``    ``{`` ` `        ``double` `num1 = ``46``.82d, num2 = ``0``.0d, num3 = -``0``.0d, num4 = -``18``.2d;`` ` `        ``// It returns 1.0 since the argument is greater than zero``        ``double` `sig_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
```
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:

 `// Java praogram to illustrate the``// java.lang.StrictMath.signum(float)``import` `java.lang.*;`` ` `public` `class` `Geeks {`` ` `    ``public` `static` `void` `main(String[] args)``    ``{`` ` `        ``float` `num1 = ``7``.22f, num2 = ``0``.0f, num3 = -``0``.0f, num4 = -``18``.11f;`` ` `        ``// It returns 1.0 since the argument is greater than zero``        ``float` `sig_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
```

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

My Personal Notes arrow_drop_up