.signum()
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 contributor
Contribute to Docs
- 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.
Learn Java on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Free course
Learn Java
Learn to code in Java — a robust programming language used to create software, web and mobile apps, and more.Beginner Friendly17 hours