#1,101 – Mathematical Constants
May 21, 2014 2 Comments
For your convenience, the System.Math class provides two useful mathematical constants, as fields.
- Math.E – base of the natural logarithm, or Euler’s Number e, with value of approximately 2.71828
- Math.PI – ratio of circle’s circumference to its diameter π, with value of approximately 3.14159
If you need to use either of these constants in your code, you can use the corresponding field in the Math class.
double radius = 5.0; double circumference = 2.0 * Math.PI * radius; Console.Write("Radius={0}, Circumference={1}", radius, circumference);
What’s the point of adding a seemingly superfluous “2.0” to the mix? Shouldn’t circumference be simply:
Math.PI * radius
?
Circumference is 2 * PI * radius