C# find the greatest common divisor

Here’s an implementation of the Euclidean algorithm that returns the greatest common divisor without performing any heap allocation. You can substitute ulong for uint if needed. An unsigned type is used, as the technique does not work for signed values. If you know your a and b values are not negative, you can use long …

Read more

How is pi (π) calculated?

In calculus there is a thing called Taylor Series which provides an easy way to calculate many irrational values to arbitrary precision. Pi/4 = 1 – 1/3 + 1/5 – 1/7 + … (from http://www.math.hmc.edu/funfacts/ffiles/30001.1-3.shtml ) Keep adding those terms until the number of digits of precision you want stabilize. Taylor’s theorem is a powerful …

Read more