Java.lang.Math.signum() Method


Description

The java.lang.Math.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.Math.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

The following example shows the usage of lang.Math.signum() method.

package com.tutorialspoint;

import java.lang.*;

public class MathDemo {

   public static void main(String[] args) {

      // get two float numbers
      float x = 50.14f;
      float y = -4f;

      // call signum for both floats and print the result
      System.out.println("Math.signum(" + x + ")=" + Math.signum(x));
      System.out.println("Math.signum(" + y + ")=" + Math.signum(y));
   }
}

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

Math.signum(50.14f)=1.0
Math.signum(-4f)=-1.0
java_lang_math.htm
Advertisements