Java Math.copySign(double magnitude, double sign)
Syntax
Math.copySign(double magnitude, double sign) has the following syntax.
public static double copySign(double magnitude, double sign)
Example
In the following code shows how to use Math.copySign(double magnitude, double sign) method.
public class Main {
/* w w w . j av a 2s.co m*/
public static void main(String[] args) {
double x = 125.9;
double y = -0.4873;
System.out.println(Math.copySign(x, y));
System.out.println(Math.copySign(y, x));
}
}
The code above generates the following result.