Java StrictMath - signum() Method
The java.lang.StrictMath.signum() method returns the sign of a given value. It returns zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero. In special cases it returns the following:
- If the argument is NaN, then the result is NaN.
- If the argument is positive zero or negative zero, then the result is the same as the argument.
Syntax
public static float signum(float f)
Parameters
f |
Specify a floating point value whose signum is to be returned. |
Return Value
Returns zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 if the argument is less than zero.
Exception
NA.
Example:
In the example below, signum() method returns the sign of a given value.
import java.lang.*; public class MyClass { public static void main(String[] args) { System.out.println(StrictMath.signum(10f)); System.out.println(StrictMath.signum(-10f)); System.out.println(StrictMath.signum(0f)); } }
The output of the above code will be:
1.0 -1.0 0.0
❮ Java.lang - StrictMath