The code below show you how to get the signum function of a number using the `Math.signum()`

static method call. This method extracts the sign of a real number. If you have a number of `x`

the signum function of `x`

is `-1`

if `x < 0`

; `0`

if `x = 0`

and `1`

if `x > 0`

.

```
package org.kodejava.example.math;
public class SignumExample {
public static void main(String[] args) {
Double zero = 0.0D;
Double negative = -25.0D;
Double positive = 15.0D;
// Get the signum function of value of a number.
// It returns:
// * 0 if the value is zero.
// * 1.0 if value is greater than zero.
// * -1.0 if value is less than zero.
double sign1 = Math.signum(zero);
double sign2 = Math.signum(negative);
double sign3 = Math.signum(positive);
// For floating-point value
float sign4 = Math.signum(zero.floatValue());
float sign5 = Math.signum(negative.floatValue());
float sign6 = Math.signum(positive.floatValue());
System.out.println("In double:");
System.out.println("Signum of " + zero + " is " + sign1);
System.out.println("Signum of " + negative + " is " + sign2);
System.out.println("Signum of " + positive + " is " + sign3);
System.out.println("In float:");
System.out.println("Signum of " + zero + " is " + sign4);
System.out.println("Signum of " + negative + " is " + sign5);
System.out.println("Signum of " + positive + " is " + sign6);
}
}
```

Here is the output of the program:

In double: Signum of 0.0 is 0.0 Signum of -25.0 is -1.0 Signum of 15.0 is 1.0 In float: Signum of 0.0 is 0.0 Signum of -25.0 is -1.0 Signum of 15.0 is 1.0

### Wayan Saryada

Founder at Kode Java Org

I am a programmer, a runner, a recreational diver, currently live in the island of Bali, Indonesia. Mostly programming in Java, Spring Framework, Hibernate / JPA. You can support my works by donating here. Thank you 🥳

#### Latest posts by Wayan Saryada (see all)

- How to Install Consolas Font in Mac OS X? - March 29, 2019
- How do I clear the current command line in terminal? - February 14, 2019
- How do I generate random alphanumeric strings? - February 7, 2019