signum(): This method is available in the Math class of Java.
Syntax:
float java.lang.Math.signum(float f)
This method takes one argument of type float as its parameter. It returns the signum function of the argument
1. Zero if the argument is zero.
2. 1.0f if the argument is greater than zero.
3. -1.0f if the argument is less than zero.
Special Cases:
1. If the argument is NaN, then the result is NaN.
2. If the argument is positive zero or negative zero, then the result is the same as the argument.
Parameters: One parameter is required for this method.
f: the floating-point value whose signum is to be returned.
Returns: the signum function of the argument.
For Example:
Math.signum(-19.9) = > It returns -1.0
Approach
Java
public class SignumFloat {public static void main(String[] args) {float f = (float) -19.9;System.out.println(Math.signum(f));}}
Output:
-1.0
No comments:
Post a Comment