What is the StrictMath.signum(float) function in Java?
Overview
In Java, signum is a static function of the StrictMath class. It is used to get the signum function of the specified float value.
Note: The
StrictMathclass has some utility methods for performing basic numeric operations. It is present in thejava.langpackage. Read more about theStrictMathclass here.
Syntax
public static float signum(float d)
Parameter value
This method takes a float value as an argument.
Return value
This method returns a float value:
-
1.0: The argument is greater than zero. -
-1.0: The argument is less than zero. -
0.0: The argument is equal to zero.
Note: If the argument is
NaN,+0.0, or-0.0, the return value is the same as the argument.
Code
class SignumExample {public static void main(String[] args) {System.out.println("Signum for -10.10f is " + StrictMath.signum(-10.10f));System.out.println("Signum for 10.5f is " + StrictMath.signum(10.5f));System.out.println("Signum for 0.0f is " + StrictMath.signum(0.0f));}}
Explanation
-
Line 3:, We call the
StrictMath.signum(-10.10f)function. This returns-1.0because the argument is less than zero. -
Line 4: We call the
StrictMath.signum(10.5f)function. This returns1.0because the argument is greater than zero. -
Line 5: We call the
StrictMath.signum(0.0f)function. This returns0.0because the argument is equal to zero.