Java.lang.Math.signum() Method

Advertisements


Description

The java.lang.Math.signum(double d) returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, -1.0 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 double signum(double d)

Parameters

  • d -- 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 double numbers
      double x = 50.14;
      double y = -4;

      // call signum for both doubles 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.14)=1.0
Math.signum(-4)=-1.0



Advertisements
Advertisements