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 ( ...
Get C# 5.0 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.