O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The Math Class

Every self-respecting foundational API has facilities to deal with math. The BCL is no different in this respect with the System.Math static class that provides a plethora of handy mathematical operations on various numeric types. We don’t cover all of them in detail, so let’s highlight the most important aspects.

Constants

Anyone with any background in math knows two of the most important constants used in various applications. Those are e (2.71828...) and pi (3.14269...). Both of them are available as constants on the Math class, with double precision:

Console.WriteLine(Math.Pow(Math.E, Math.Log(5)));Console.WriteLine(Math.PI * r * r);

In the first example, we’re taking the natural logarithm ( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required