C# Math Class and Math Class Methods

 

In C#, Math class used to perform many mathematical operations like absolute, Ceiling, Floor, logarithm.

In this article we discuss about what are the methods provided by Math class and it usage.

 

Abs method: It provides absolute of given value.

Exp: Math.Abs(34.4) = 34.4

        Math.Abs(-34.4) = 34.4

        Math.Abs(0) = 0

 

 

Ceiling Method: It rounds the given value to the nearest larger integer

Exp: Math.Ceiling(3.4) = 4

        Math.Ceiling(-3.4) = -3  

 

 

Cos Method: It provides Cosine value for given radians

Exp: Math.Cos(30) is 0.154251449887584

 

 

Exp Method: It gives the exponential of given value.

Exp: Math.Exp(3.4) is 29.964100047397

 

 

Floor Method: It rounds the given value to the nearer largest number not greater than its.

Exp: Math.Floor(34.6) is 34

 

 

Log Method: It gives logarithm of given value.

Exp: Math.Log(3.4) is 1.22377543162212

 

 

Max Method: It gives larger value of given numbers.

Exp: Math.Max(34.4,32.1) is 34.4

 

 

Min Method: It gives smaller value of given numbers

Exp: Math.Min(34.4,32.1) is 32.1

 

 

Pow(a,b) Method: It gives the a raised to power of b

Exp: Math.Pow(2,4) is 16

 

 

Sin Method: It gives the Sin value of given input.

Exp: Math.Sin(34) is 0.529082686120024

 

 

Sqrt Method: It gives the square root of given input.

Exp: Math.Sqrt(4) is 2

 

 

Tan Method: It gives the Tan of given input.

Exp: Math.Tan(34) is -0.623498962716226