Click or drag to resize
mathcopysign Method (Double, Double)
Copies the sign of number2 to number1.

Namespace:  C
Assembly:  C.math (in C.math.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
public static double copysign(
	double number1,
	double number2
)

Parameters

number1
Type: SystemDouble
A floating-point number.
number2
Type: SystemDouble
A floating-point number.

Return Value

Type: Double
The floating-point number whose absolute value is that of number1 with the sign of number2.
Remarks

copysign(Double, Double) is the only portable way to manipulate the sign of a NaN value (to examine the sign of a NaN, signbit(Double) may also be used).

See copysign in the C standard documentation.

Examples
Assert.IsTrue(math.copysign(0D, -0D) == -0D);
Assert.IsTrue(math.copysign(0D, -4D) == -0D);
Assert.IsTrue(math.copysign(2D, -0D) == -2D);
Assert.IsTrue(math.copysign(-2D, 0D) == 2D);
Assert.IsTrue(math.copysign(System.Double.PositiveInfinity, -2D) == System.Double.NegativeInfinity);
Assert.IsTrue(math.copysign(2D, System.Double.NegativeInfinity) == -2D);
See Also