.signum()
Anonymous contributor
Anonymous contributor2 total contributions
Anonymous contributor
Published Oct 31, 2022
Contribute to Docs
The Math.signum()
method determines whether a number is positive, negative, zero, or NaN
.
Syntax
Math.signum(num)
The .signum()
method takes a num
parameter and returns a double
value that indicates whether num
is positive, negative, zero, or NaN
.
Some cases to consider include the following:
- If
num
is positive, a positive non-zero value is returned. - If
num
is negative, a negative non-zero value is returned. - If
num
is zero, zero is returned. - If the value of
num
isNaN
,NaN
is returned.
Example
The following example demonstrates the .signum()
method and its many use cases:
// Test.javapublic class Test {public static void main(String[] args) {System.out.println(Math.signum(8.75));System.out.println(Math.signum(-3.5));System.out.println(Math.signum(0));System.out.println(Math.signum(Double.NaN));}}
This will produce the following output:
1.0-1.00NaN
All contributors
- Anonymous contributorAnonymous contributor2 total contributions
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.