Java Data Type Tutorial - Java Math.copySign(float magnitude, float sign)








Syntax

Math.copySign(float magnitude, float sign) has the following syntax.

public static float copySign(float magnitude,  float sign)

Example

In the following code shows how to use Math.copySign(float magnitude, float sign) method.

//from  ww  w . j  a va 2s.c  om

public class Main {

   public static void main(String[] args) {

      float x = 123.4f;
      float y = -0.1234F;

      System.out.println(Math.copySign(x, y));
      System.out.println(Math.copySign(y, x));

   }
}

The code above generates the following result.