Java Math copySign() Method

The copySign() method of Math class returns the first floating-point argument with the sign of the second argument.


public static float copySign(float magnitude, float sign)

public static double copySign(double magnitude, double sign)


The parameter ‘magnitude’ and ‘sign’ represents the magnitude and sign of the result.

Return Value:

The copySign() method returns a value with the magnitude of magnitude and the sign of sign.

Example 1:


Example 2:


Example 3:


Example 4: