C# has a built-in Math
class which provides useful mathematical functions and operations. The class has the CopySign()
function, which is used to return a number with the magnitude of the first parameter and the sign of the second parameter.
public static double CopySign (double param1, double param2);
param1
: This parameter is of the Double
type and represents the input value whose magnitude is to be used in CopySign()
.param2
: This parameter is of the Double
type and represents the input value whose sign is to be used in CopySign()
.Double
: This value returns a Double
type number with magnitude of param1
and sign of param2
.using System;class Educative{static void Main(){double result = Math.CopySign(2,3);System.Console.WriteLine("CopySign(2,3) = "+ result);double result1 = Math.CopySign(1, -4);System.Console.WriteLine("CopySign(1, -4) = "+ result1);double result2 = Math.CopySign(-2, 1);System.Console.WriteLine("CopySign(-2, 1) = "+ result2);}}