MOCKSTACKS
EN  # C# Math Class

C# does support built in Math functions using Math class which comes under the System namespace. Math class has a built in static methods and constants for logarithmic, trigonometric, and other useful mathematical functions.

Below is a list of Math supported methods:

MethodDescription
Abs()Returns the absolute value of a specified number.
Acos()Returns the angle whose cosine is the specified number.
Acosh()Returns the Inverse hyperbolic cosine of the specified number.
Asin()Returns the angle whose sine is the specified number.
Asinh()Returns the Inverse hyperbolic sine of the specified number.
Atan()Returns the angle whose tangent is the specified number.
Atan2()Returns the angle whose tangent is the quotient of two specified numbers.
Atanh()Returns the Inverse hyperbolic tangent of the specified number.
BigMul()Produces the full product of two 32-bit numbers.
Cbrt()Returns the cube root of a specified value.
Ceiling()Returns the smallest integral value greater than or equal to the specified number.
Clamp()It is used to restrict a value to a given range.
Cos()Returns the cosine of the specified angle.
Cosh()Returns the hyperbolic cosine of the specified angle.
DivRem()Calculates the quotient of two numbers and also returns the remainder in an output parameter.
Exp()Returns e raised to the specified power.
Floor()Returns the largest integral value less than or equal to the specified number.
IEEERemainder()Returns the remainder resulting from the division of a specified number by another specified number.
Log()Returns the logarithm of a specified number.
Log10()Returns the base 10 logarithm of a specified number.
Max()Returns the larger of two specified numbers.
Min()Returns the smaller of two numbers.
Pow()Returns a specified number raised to the specified power.
Round()Rounds a value to the nearest integer or to the specified number of fractional digits.
Sign()Returns an integer that indicates the sign of a number.
Sin()Returns the sine of the specified angle.
Sinh()Returns the hyperbolic sine of the specified angle.
Sqrt()Returns the square root of a specified number.
Tan()Returns the tangent of the specified angle.
Tanh()Returns the hyperbolic tangent of the specified angle.
Truncate()Calculates the integral part of a number.

## C# Example of Math Functions

``````using System;

namespace MyApplication
{
class Program
{
static void Main(string[] args)
{
// Min number of 5 and 10 is 5
int minNumber = Math.Min(5, 10);

// Max number of 5 and 10 is 10
int maxNumber = Math.Max(5, 10);

// Sqrt number of 81 is 9
double sqrtNumber = Math.Sqrt(81);

// Abs number of -9.8 is 9.8
double abs = Math.Abs(-9.8);

// Round number of 0.99 is 1
double roundNumber = Math.Round(0.99);

Console.WriteLine(minNumber);
Console.WriteLine(maxNumber);
Console.WriteLine(sqrtNumber);
Console.WriteLine(abs);
Console.WriteLine(roundNumber);
}
}
}``````

5
10
9
9.8
1

## Conclusion

In this page (written and validated by ) you learned about C# Math Class . What's Next? If you are interested in completing CS tutorial, your next topic will be learning about: CS String Length.

Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.