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 w w w. j ava2 s . co m*/
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.