Click or drag to resize
mathcopysign Method (Single, Single)
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 float copysign(
	float number1,
	float number2
)

Parameters

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

Return Value

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

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

See copysign in the C standard documentation.

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