Math functions
- Last UpdatedApr 24, 2025
- 1 minute read
The standard math functions are contained in the System.Math class.
The following commonly used operations are implemented as static methods of this class. For information on using this class and all of the functions it provides, refer to the documentation provided on the Microsoft Docs website.
System.Math.Abs
var value = Double.MaxValue;
Console.WriteLine($"Abs({value}) = {Math.Abs(value)}");
//This example displays the following output
//Abs(1.79769313486232E+308) = 1.79769313486232E+308
System.Math.Acos
var value = 0.5;
Console.WriteLine($"Acos({value}) = {Math.Acos(value)}");
//This examples displays the following output
//Acos(0.5) = 1.0471975511965979
System.Math.Asin
var value = 0.3584;
Console.WriteLine($"Asin({value}) = {Math.Asin(value)}");
//This example displays the following output
//Asin(0.3584) = 0.3665534738291246;
System.Math.Atan
var value = 1;
Console.WriteLine($"Atan({value}) = {Math.Atan(value)}");
//This example displays the following output
//Atan(1) = 0.7853981633974483;
System.Math.Atan2
double x = 10, y = 10;
double radians;
radians = Math.Atan2(x, y);
Console.WriteLine($"Math.Atan2({x},{y}) = {radians})");
//This example displays the following output
//Math.Atan2(10,10) = 0.7853981633974483)
System.Math.BigMult
int int1 = Int32.MaxValue;
int int2 = Int32.MaxValue;
long longResult;
longResult = Math.BigMul(int1, int2);
Console.WriteLine("Calculate the product of two Int32 values:");
Console.WriteLine("{0} * {1} = {2}", int1, int2, longResult);
/*
This example produces the following results:
Calculate the product of two Int32 values:
2147483647 * 2147483647 = 4611686014132420609
*/
System.Math.Ceiling
double value = 7.03;
Console.WriteLine($"Math.Ceiling({value}) = {Math.Ceiling(value)}");
/*This example displays the following output
Math.Ceiling(7.03) = 8
*/
System.Math.Cos
double degrees = 45.0;
double angle = Math.PI * degrees / 180.0;
Console.WriteLine($"Math.Cos({angle}) = {Math.Cos(angle)}");
/*
This example produces the following results:
Math.Cos(0.7853981633974483) = 0.7071067811865476
*/
System.Math.Cosh
double degrees = 45.0;
double angle = Math.PI * degrees / 180.0;
Console.WriteLine($"Math.Cosh({angle}) = {Math.Cosh(angle)}");
/*
This example produces the following results:
Math.Cosh(0.7853981633974483) = 1.324609089252006
*/