Java - StrictMath signum(float x) method



Description

The Java StrictMath signum(float f) returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, -1.0f if the argument is less than zero.Special Cases −

  • 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.

Declaration

Following is the declaration for java.lang.StrictMath.signum() method

public static float signum(float f)

Parameters

f − the floating-point value whose signum is to be returned

Return Value

This method returns the signum function of the argument

Exception

NA

Example: Getting signnum for a Positive float Value

The following example shows the usage of StrictMath signum() method to get a long value for a positive float value.

package com.tutorialspoint;
public class StrictMathDemo {
   public static void main(String[] args) {

      // get a float number
      float x = 1654.9874f;

      // find the signum of the value
      System.out.println("StrictMath.signum(" + x + ")=" + StrictMath.signum(x));
   }
}

Output

Let us compile and run the above program, this will produce the following result −

StrictMath.signum(1654.9874)=1.0

Example: Getting signnum for a Negative float Value

The following example shows the usage of StrictMath signum() method to get a signum of a negative float value.

package com.tutorialspoint;
public class StrictMathDemo {
   public static void main(String[] args) {

      // get a float number
      float x = -9765.134f;

      // find the signum of the value
      System.out.println("StrictMath.signum(" + x + ")=" + StrictMath.signum(x));
   }
}

Output

Let us compile and run the above program, this will produce the following result −

StrictMath.signum(-9765.134)=-1.0

Example: Getting signnum for a Zero float Value

The following example shows the usage of StrictMath signum() method to get a value of a zero float values.

package com.tutorialspoint;
public class StrictMathDemo {
   public static void main(String[] args) {

      // get float numbers
      float x = 0.0f;	  

      // find the signum of the value
      System.out.println("StrictMath.signum(" + x + ")=" + StrictMath.signum(x));
   }
}

Output

Let us compile and run the above program, this will produce the following result −

StrictMath.signum(0.0)=0.0
java_lang_strictmath.htm
Advertisements