System.Math

This provides a core set of mathematical functions along with two constants: the ratio of the circumference of a circle to its diameter (pi) and the natural logarithm base (e). Listing B.14 provides an example of using parts of the Math class (math.cs).

Listing B.14. Math Example
static void Main(string [] args)
{
    Console.WriteLine("Pi: {0} ", Math.PI);
    Console.WriteLine("E: {0} ", Math.E);
    Console.WriteLine("sqrt(2): {0} ", Math.Sqrt(2.0));
    Console.WriteLine("log(e): {0} ", Math.Log(Math.E));
    Console.WriteLine("cos(pi): {0} ", Math.Cos(Math.PI));
    Console.WriteLine("sin(pi): {0} ", Math.Sin(Math.PI));
    Console.WriteLine("2^5: {0} ", Math.Pow(2,5));
}

Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.